Skip to content
Open
34 changes: 21 additions & 13 deletions .github/workflows/minimal.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
name: Example for minimal setup
on:
# NOTE! Do NOT add any other "on", because this workflow has permission to write to the repo!
push:
branches:
- master

permissions:
contents: write
deployments: write
# permission to update benchmark contents in gh-pages branch
contents: "write"

jobs:
benchmark:
name: Run minimal steps to run github-action-benchmark
name: Run benchmark and save results

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like there is a companion minimal example missing: where a PR runs benchmarks and compares them against the benchmarks saved in here...

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: "stable"
- name: Run benchmark
- name: Run benchmark and stores the output to a file
run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt
- name: Download previous benchmark data
uses: actions/cache@v4
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- name: Store benchmark result
- name: Get JSON for benchmark
uses: benchmark-action/github-action-benchmark@v1
with:
# What benchmark tool the output.txt came from
tool: 'go'
output-file-path: examples/go/output.txt
# Where the output from the benchmark tool is stored
output-file-path: output.txt
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
# Updates this file
external-data-json-path: ./cache/benchmark-data.json
# Workflow will fail when an alert happens
fail-on-alert: true
Comment on lines +32 to 33

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if this line makes sense here. this step isn't comparing benchmark results, so how would it fail?

# Writes to gh-pages-branch
auto-push: "true"
- name: Save JSON in cache
uses: actions/cache/save@v5
with:
path: ./cache/benchmark-data.json
# Save with commit hash to avoid "cache already exists"
key: "${{ github.sha }}-${{ runner.os }}-go-benchmark"

Check failure on line 41 in .github/workflows/minimal.yml

View workflow job for this annotation

GitHub Actions / Run unit tests

41:65 [new-line-at-end-of-file] no new line character at the end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing cache restore step prevents comparison with previous benchmarks.

The workflow saves benchmark-data.json to cache but never restores it. Without a restore step before the benchmark action, each run starts with an empty/missing benchmark-data.json, so there's no historical data to compare against. The fail-on-alert setting becomes ineffective since there's nothing to compare.

For a functional minimal example, add a cache restore step:

Proposed fix
       - name: Run benchmark and stores the output to a file
         run: go test ./examples/go -bench 'BenchmarkFib' | tee output.txt
+      - name: Restore benchmark JSON from cache
+        uses: actions/cache/restore@v5
+        with:
+          path: ./cache/benchmark-data.json
+          key: "${{ runner.os }}-go-benchmark"
+          restore-keys: |
+            ${{ runner.os }}-go-benchmark
       - name: Get JSON for benchmark
         uses: benchmark-action/github-action-benchmark@v1
🧰 Tools
🪛 GitHub Check: Run unit tests

[failure] 41-41:
41:65 [new-line-at-end-of-file] no new line character at the end of file

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/minimal.yml around lines 36 - 41, The workflow saves
benchmark-data.json but never restores it before the benchmark run; add a cache
restore step (using actions/cache/restore@v5) before the benchmark action that
uses the same path "./cache/benchmark-data.json" and the same key expression
"${{ github.sha }}-${{ runner.os }}-go-benchmark" so the previous
benchmark-data.json is available for comparison by the step that performs the
benchmark and the "fail-on-alert" check; ensure the restore step is named (e.g.,
"Restore JSON from cache") and placed before the benchmark invocation so
missing-cache cases are handled gracefully.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Loading
Loading