Skip to content

Commit b5a9cfb

Browse files
authored
Save benchmark cache even the job is failed (#5694)
Part of #4537, replace #5671 I tried to use `save-always` to simplify it, but this flag never worked. actions/cache#1315. So, I split the cache action into two, one for restore and one for save. The save step would always run even if a step failed. Some actions I run to prove it could work: - On success: https://github.com/XSAM/opentelemetry-go/actions/runs/10292883964/job/28488154161 - On failure: https://github.com/XSAM/opentelemetry-go/actions/runs/10292907887/job/28488227777
1 parent 6c099c2 commit b5a9cfb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

.github/workflows/benchmark.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@ jobs:
2121
- name: Run benchmarks
2222
run: make benchmark | tee output.txt
2323
- name: Download previous benchmark data
24-
uses: actions/cache@v4
24+
uses: actions/cache/restore@v4
2525
with:
2626
path: ./benchmarks
27-
# Use the current commit SHA as the cache key.
28-
# This key won't exist on the first run, so the cache match falls back to restore-keys.
29-
# Though, it won't be matched, the cache created will use this key as the cache key.
30-
# So the next commit will be able to restore this cache (from the restore-keys).
31-
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#matching-a-cache-key
32-
key: ${{ runner.os }}-benchmark-${{ github.sha }}
3327
# `github.event.before` means the commit before the push (i.e. the previous commit).
3428
# So we can fetch the exact benchmark data from the previous commit.
35-
restore-keys: ${{ runner.os }}-benchmark-${{ github.event.before }}
29+
key: ${{ runner.os }}-benchmark-${{ github.event.before }}
3630
- name: Store benchmarks result
3731
uses: benchmark-action/[email protected]
3832
with:
@@ -46,3 +40,11 @@ jobs:
4640
alert-threshold: "400%"
4741
# Add benchmark summary to GitHub workflow run report
4842
summary-always: true
43+
- name: Save benchmark data
44+
uses: actions/cache/save@v4
45+
# The cache will be saved even if a step fails.
46+
if: always()
47+
with:
48+
path: ./benchmarks
49+
# Use the current commit SHA as the cache key.
50+
key: ${{ runner.os }}-benchmark-${{ github.sha }}

0 commit comments

Comments
 (0)