|
| 1 | +name: Upload and compare benchmark results |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + types: [completed] |
| 6 | + workflows: ['Running benchmark'] |
| 7 | + |
| 8 | +jobs: |
| 9 | + upload-benchmark-results: |
| 10 | + if: (github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'pull_request') && github.repository == 'OptimumCode/json-schema-validator' |
| 11 | + runs-on: ubuntu-latest |
| 12 | + environment: contribution |
| 13 | + env: |
| 14 | + RESULTS_DIR: bench-results |
| 15 | + permissions: |
| 16 | + # deployments permission to deploy GitHub pages website |
| 17 | + deployments: write |
| 18 | + # contents permission to update benchmark contents in gh-pages branch |
| 19 | + contents: write |
| 20 | + # pull-requests permission to create comments on PR in case of alert |
| 21 | + pull-requests: write |
| 22 | + strategy: |
| 23 | + # to make sure results are submitted one by one |
| 24 | + max-parallel: 1 |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - artifact-pattern: 'bench-result-*' |
| 28 | + results-name: KMP JSON schema validator |
| 29 | + alert: true |
| 30 | + - artifact-pattern: 'bench-comparison-result-*' |
| 31 | + results-name: Compare KMP JSON schema validator |
| 32 | + alert: false |
| 33 | + name: 'Process benchmark results for ${{ matrix.results-name }}' |
| 34 | + steps: |
| 35 | + - name: 'Checkout Repository' |
| 36 | + uses: actions/checkout@v4 |
| 37 | + - name: Download benchmark results |
| 38 | + uses: actions/download-artifact@v4 |
| 39 | + with: |
| 40 | + pattern: ${{ matrix.artifact-pattern }} |
| 41 | + path: ${{ env.RESULTS_DIR }} |
| 42 | + merge-multiple: true |
| 43 | + run-id: ${{ github.event.workflow_run.id }} |
| 44 | + - name: Show downloaded artifacts |
| 45 | + run: tree ${{ env.RESULTS_DIR }} |
| 46 | + - name: Prepare and join benchmark reports |
| 47 | + id: prep |
| 48 | + run: | |
| 49 | + for report in $(find ./${{ env.RESULTS_DIR }} -type f -name "*.json") |
| 50 | + do |
| 51 | + file_name=$(basename "$report") |
| 52 | + platform="${file_name%.*}" |
| 53 | + jq "[ .[] | .benchmark |= \"${platform}.\" + ltrimstr(\"io.github.optimumcode.json.schema.benchmark.\") | .params |= map_values(. |= split(\"/\")[-1]) ]" $report > ${{ env.RESULTS_DIR }}/$platform.json |
| 54 | + done |
| 55 | + AGGREGATED_REPORT=aggregated.json |
| 56 | + # Joined reports looks like this: [[{},{}], [{},{}]] |
| 57 | + # We need to transform them into this: [{},{}] |
| 58 | + ls ${{ env.RESULTS_DIR }}/*.json |
| 59 | + jq -s '[ .[] | .[] ]' ${{ env.RESULTS_DIR }}/*.json > $AGGREGATED_REPORT |
| 60 | + echo "report=$AGGREGATED_REPORT" >> $GITHUB_OUTPUT |
| 61 | + - name: Store benchmark result |
| 62 | + uses: benchmark-action/github-action-benchmark@v1 |
| 63 | + with: |
| 64 | + name: ${{ matrix.results-name }} |
| 65 | + tool: 'jmh' |
| 66 | + output-file-path: ${{ steps.prep.outputs.report }} |
| 67 | + alert-comment-cc-users: "@OptimumCode" |
| 68 | + comment-on-alert: ${{ matrix.alert }} |
| 69 | + summary-always: true |
| 70 | + alert-threshold: '150%' |
| 71 | + fail-threshold: '200%' |
| 72 | + max-items-in-chart: 50 |
| 73 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + # Push and deploy GitHub pages branch automatically only if run in main repo and not in PR |
| 75 | + auto-push: ${{ github.event.workflow_run.event == 'push' }} |
| 76 | + |
| 77 | + |
0 commit comments