Skip to content

Commit dc77f2e

Browse files
committed
workflows: report benchmark regressions back to pull request
Let's see if this works, it's a bit experimental at this point. The twist comparred to how it's been done in EOPA (for example) is that we're running the benchmarks post-merge, and report back if at the end we find a failing check. This way, the PR goes green without having to wait for the benchmarks, but there's still a connection between PR and benchmark. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
1 parent bd26ba6 commit dc77f2e

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/benchmarks.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,87 @@ jobs:
7474
publish: true
7575
publish_branch: benchmarks
7676

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+
77158
notebook:
78159
permissions:
79160
contents: write # we'll push to the `benchmarks` branch

build/gobenchdata-checks.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
checks:
2+
- name: ns-per-op regression
3+
description: Flag if NsPerOp regresses by more than 10%
4+
package: ""
5+
benchmarks: []
6+
diff: (current.NsPerOp - base.NsPerOp) / base.NsPerOp * 100
7+
thresholds:
8+
max: 10

0 commit comments

Comments
 (0)