Skip to content

Commit 06be9b8

Browse files
committed
Enhance GitHub Actions workflow for benchmark results
- Updated permissions to allow opening pull requests in addition to pushing benchmark result branches. - Modified the workflow to create a new branch for benchmark results and automatically open a pull request with a detailed summary of changes. - Improved commit message generation based on the type of GitHub reference (tag or branch) to ensure clarity in versioning. - Added checks to skip PR creation if there are no changes to commit, enhancing workflow efficiency.
1 parent 338640c commit 06be9b8

1 file changed

Lines changed: 46 additions & 13 deletions

File tree

.github/workflows/benchmarks.yml

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ env:
2323
RUST_BACKTRACE: 1
2424

2525
permissions:
26-
contents: write # Needed to commit benchmark results
26+
contents: write # Needed to push benchmark result branches
27+
pull-requests: write # Needed to open PRs
2728

2829
jobs:
2930
benchmark:
@@ -118,8 +119,25 @@ jobs:
118119
git config user.name "github-actions[bot]"
119120
git config user.email "github-actions[bot]@users.noreply.github.com"
120121
121-
- name: Commit and push results
122+
- name: Commit results to a new branch and open PR
123+
env:
124+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122125
run: |
126+
# Determine branch name and PR title
127+
if [ "${{ github.ref_type }}" = "tag" ]; then
128+
VERSION="${GITHUB_REF#refs/tags/}"
129+
BRANCH="benchmark-results/${VERSION}"
130+
PR_TITLE="benchmark: update results for ${VERSION}"
131+
COMMIT_MSG="benchmark: update results for ${VERSION} [skip ci]"
132+
else
133+
BRANCH="benchmark-results/$(date -u +%Y-%m-%d)-${{ github.run_id }}"
134+
PR_TITLE="benchmark: update results ($(date -u +%Y-%m-%d))"
135+
COMMIT_MSG="benchmark: update results [skip ci]"
136+
fi
137+
138+
# Create and switch to the new branch from the current HEAD
139+
git checkout -b "$BRANCH"
140+
123141
# Add generated files (force add since they're in .gitignore)
124142
git add -f docs/benchmarks/latest/
125143
@@ -130,21 +148,36 @@ jobs:
130148
131149
# Check if there are changes to commit
132150
if git diff --staged --quiet; then
133-
echo "ℹ️ No changes to commit"
151+
echo "ℹ️ No changes to commit — skipping PR creation"
134152
exit 0
135153
fi
136154
137-
# Create commit message
138-
if [ "${{ github.ref_type }}" = "tag" ]; then
139-
COMMIT_MSG="benchmark: update results for ${GITHUB_REF#refs/tags/} [skip ci]"
140-
else
141-
COMMIT_MSG="benchmark: update results [skip ci]"
142-
fi
143-
144155
git commit -m "$COMMIT_MSG"
145-
git push
146-
147-
echo "✅ Pushed benchmark results"
156+
git push origin "$BRANCH"
157+
echo "✅ Pushed branch: $BRANCH"
158+
159+
# Determine base branch (main by default, or the tag's base branch)
160+
BASE_BRANCH="${{ github.event.repository.default_branch }}"
161+
162+
# Open a PR
163+
gh pr create \
164+
--base "$BASE_BRANCH" \
165+
--head "$BRANCH" \
166+
--title "$PR_TITLE" \
167+
--body "$(cat <<'EOF'
168+
## 📊 Benchmark Results
169+
170+
This PR was automatically generated by the [Benchmarks workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
171+
172+
**Files updated:**
173+
- `docs/benchmarks/latest/index.md`
174+
- `docs/benchmarks/latest/charts.html`
175+
- `docs/benchmarks/latest/results.json`
176+
177+
> ⚠️ **Note:** Benchmark results may vary on CI runners. For consistent measurements, use a dedicated benchmark machine.
178+
EOF
179+
)"
180+
echo "✅ PR opened"
148181
149182
- name: Create benchmark summary
150183
if: always()

0 commit comments

Comments
 (0)