|
74 | 74 | publish: true |
75 | 75 | publish_branch: benchmarks |
76 | 76 |
|
| 77 | + regression-check: |
| 78 | + permissions: |
| 79 | + contents: read |
| 80 | + pull-requests: write |
| 81 | + name: Check for regressions |
| 82 | + runs-on: ubuntu-24.04 |
| 83 | + needs: [check-changes, benchmarks] |
| 84 | + if: ${{ needs.check-changes.outputs.go == 'true' }} |
| 85 | + steps: |
| 86 | + - name: Check out code |
| 87 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 88 | + with: |
| 89 | + persist-credentials: false |
| 90 | + - id: go_version |
| 91 | + name: Read go version |
| 92 | + run: echo "go_version=$(cat .go-version)" >> $GITHUB_OUTPUT |
| 93 | + - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 94 | + with: |
| 95 | + go-version: ${{ steps.go_version.outputs.go_version }} |
| 96 | + - name: Fetch benchmark data |
| 97 | + run: | |
| 98 | + git fetch origin benchmarks |
| 99 | + git show origin/benchmarks:benchmarks.json > benchmarks.json |
| 100 | + - name: Split latest two runs |
| 101 | + run: | |
| 102 | + # Extract the two most recent runs into separate files |
| 103 | + jq '.[0]' benchmarks.json | jq '[.]' > current.json |
| 104 | + jq '.[1]' benchmarks.json | jq '[.]' > base.json |
| 105 | + - name: Run regression checks |
| 106 | + id: checks |
| 107 | + continue-on-error: true |
| 108 | + run: | |
| 109 | + go run go.bobheadxi.dev/gobenchdata@v1 checks eval base.json current.json \ |
| 110 | + --checks.config build/gobenchdata-checks.yml \ |
| 111 | + --json report.json |
| 112 | + go run go.bobheadxi.dev/gobenchdata@v1 checks report report.json |
| 113 | + - name: Comment on PR if regression detected |
| 114 | + if: ${{ steps.checks.outcome == 'failure' }} |
| 115 | + env: |
| 116 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 117 | + COMMIT_SHA: ${{ github.sha }} |
| 118 | + run: | |
| 119 | + PR_NUMBER=$(gh pr list --search "${COMMIT_SHA}" --state merged --json number --jq '.[0].number') |
| 120 | +
|
| 121 | + if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" = "null" ]; then |
| 122 | + echo "Could not find originating PR for commit ${COMMIT_SHA}" |
| 123 | + exit 0 |
| 124 | + fi |
| 125 | +
|
| 126 | + REPORT=$(jq -r ' |
| 127 | + .checks[] |
| 128 | + | select(.status != "pass") |
| 129 | + | "| \(.name) | \(.status) | \(.diffs | length) benchmarks |" |
| 130 | + ' report.json) |
| 131 | +
|
| 132 | + BODY=$(cat <<EOF |
| 133 | + ## Benchmark Regression Detected |
| 134 | +
|
| 135 | + Commit \`${COMMIT_SHA}\` introduced a benchmark regression. |
| 136 | +
|
| 137 | + | Check | Status | Affected | |
| 138 | + |-------|--------|----------| |
| 139 | + ${REPORT} |
| 140 | +
|
| 141 | + <details> |
| 142 | + <summary>Full report</summary> |
| 143 | +
|
| 144 | + \`\`\`json |
| 145 | + $(jq . report.json) |
| 146 | + \`\`\` |
| 147 | +
|
| 148 | + </details> |
| 149 | +
|
| 150 | + [Benchmarks Dashboard](https://open-policy-agent.github.io/opa/index.html) |
| 151 | +
|
| 152 | + _This comment was automatically generated by the benchmarks workflow._ |
| 153 | + EOF |
| 154 | + ) |
| 155 | +
|
| 156 | + gh pr comment "${PR_NUMBER}" --body "${BODY}" |
| 157 | +
|
77 | 158 | notebook: |
78 | 159 | permissions: |
79 | 160 | contents: write # we'll push to the `benchmarks` branch |
|
0 commit comments