Skip to content

Commit 1fe4b3a

Browse files
committed
update minimal example
1 parent 69b61e7 commit 1fe4b3a

2 files changed

Lines changed: 32 additions & 34 deletions

File tree

.github/workflows/minimal.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ permissions:
1111

1212
jobs:
1313
benchmark:
14-
name: Performance regression check
14+
name: Run benchmark and save results
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v6
1818
- uses: actions/setup-go@v6
1919
with:
2020
go-version: "stable"
21-
# Run benchmark with `go test -bench` and stores the output to a file
22-
- name: Run benchmark
21+
- name: Run benchmark and stores the output to a file
2322
run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt
24-
# Download previous benchmark result from cache
25-
- name: Download previous benchmark data
26-
uses: actions/cache/restore@v5
27-
with:
28-
fail-on-cache-miss: true
29-
path: ./cache/benchmark-data.json
30-
key: ${{ runner.os }}-benchmark
31-
- name: Compare benchmark result
23+
- name: Get JSON for benchmark
3224
uses: benchmark-action/github-action-benchmark@v1
3325
with:
3426
# What benchmark tool the output.txt came from
3527
tool: 'go'
3628
# Where the output from the benchmark tool is stored
3729
output-file-path: output.txt
38-
# Where the previous benchmark results are (to compare)
30+
# Updates this file
3931
external-data-json-path: ./cache/benchmark-data.json
4032
# Workflow will fail when an alert happens
4133
fail-on-alert: true
34+
# Writes to gh-pages-branch
35+
auto-push: "true"
36+
- name: Save JSON in cache
37+
uses: actions/cache/save@v5
38+
with:
39+
path: ./cache/benchmark-data.json
40+
# Save with commit hash to avoid "cache already exists"
41+
key: "${{ github.sha }}-${{ runner.os }}-go-benchmark"

README.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,49 +71,47 @@ context) properties. Like this:
7171
### Minimal setup
7272

7373
```yaml
74-
name: Minimal setup
74+
nname: Example for minimal setup
7575
on:
76+
# NOTE! Do NOT add any other "on", because this workflow has permission to write to the repo!
7677
push:
7778
branches:
7879
- master
7980

81+
permissions:
82+
# permission to update benchmark contents in gh-pages branch
83+
contents: "write"
84+
8085
jobs:
8186
benchmark:
82-
name: Performance regression check
87+
name: Run benchmark and save results
8388
runs-on: ubuntu-latest
8489
steps:
8590
- uses: actions/checkout@v6
8691
- uses: actions/setup-go@v6
8792
with:
8893
go-version: "stable"
89-
# Run benchmark with `go test -bench` and stores the output to a file
90-
- name: Run benchmark
91-
run: go test -bench 'BenchmarkFib' | tee output.txt
92-
# Download previous benchmark result from cache
93-
- name: Download previous benchmark data
94-
uses: actions/cache/restore@v5
95-
with:
96-
fail-on-cache-miss: true
97-
path: ./cache/benchmark-data.json
98-
key: ${{ runner.os }}-benchmark
99-
- name: Compare results
94+
- name: Run benchmark and stores the output to a file
95+
run: cd examples/go && go test -bench 'BenchmarkFib' | tee output.txt
96+
- name: Get JSON for benchmark
10097
uses: benchmark-action/github-action-benchmark@v1
10198
with:
10299
# What benchmark tool the output.txt came from
103100
tool: 'go'
104-
# Extract benchmark result from here
101+
# Where the output from the benchmark tool is stored
105102
output-file-path: output.txt
106-
# Where the previous data file is stored
103+
# Updates this file
107104
external-data-json-path: ./cache/benchmark-data.json
108105
# Workflow will fail when an alert happens
109106
fail-on-alert: true
110-
# Upload the updated cache file for the next job by actions/cache
111-
- name: Save benchmark JSON
107+
# Writes to gh-pages-branch
108+
auto-push: "true"
109+
- name: Save JSON in cache
112110
uses: actions/cache/save@v5
113111
with:
114112
path: ./cache/benchmark-data.json
115-
# Include OS in key so that we don't compare benchmarks across different OSes
116-
key: ${{ runner.os }}-benchmark
113+
# Save with commit hash to avoid "cache already exists"
114+
key: "${{ github.sha }}-${{ runner.os }}-go-benchmark"
117115
```
118116
119117
By default, this action marks the result as performance regression when it is worse than the previous
@@ -140,8 +138,8 @@ be seen [here][minimal-workflow-example].
140138
github-token: ${{ secrets.GITHUB_TOKEN }}
141139
# Enable alert commit comment
142140
comment-on-alert: true
143-
# Mention @rhysd in the commit comment, not mandatory but highly recommended to ensure the comment is seen
144-
alert-comment-cc-users: '@rhysd'
141+
# Mention @ktrz in the commit comment, not mandatory but highly recommended to ensure the comment is seen
142+
alert-comment-cc-users: '@ktrz'
145143
```
146144

147145
`secrets.GITHUB_TOKEN` is [a GitHub API token automatically generated for each workflow run][help-github-token].
@@ -151,7 +149,7 @@ performance regression.
151149
Now, in addition to making workflow fail, the step leaves a commit comment when it detects performance
152150
regression [like this][alert-comment-example]. Though `alert-comment-cc-users` input is not mandatory for
153151
this, I recommend to set it to make sure you notice the comment via GitHub notification. Please note
154-
that this value must be quoted like `'@rhysd'` because [`@` is an indicator in YAML syntax](https://yaml.org/spec/1.2/spec.html#id2772075).
152+
that this value must be quoted like `'@ktrz'` because [`@` is an indicator in YAML syntax](https://yaml.org/spec/1.2/spec.html#id2772075).
155153

156154
A live workflow example is [here](.github/workflows/commit-comment.yml). And the results of the workflow
157155
can be seen [here][commit-comment-workflow-example].

0 commit comments

Comments
 (0)