Skip to content

Commit 6f05c36

Browse files
committed
validate cache
1 parent 94af723 commit 6f05c36

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

.github/workflows/perf-test.yml

+22-11
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ jobs:
3131
- commit: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
3232
name: previous
3333
outputs:
34-
cached-previous: ${{ steps.is-cached-previous.outputs.is-cached }}
35-
cached-current: ${{ steps.is-cached-current.outputs.is-cached }}
34+
cached-previous: ${{ steps.is-cached-previous.outputs.is-cached == 'true' && steps.validate.outputs.cache-valid != 'false' }}
35+
cached-current: ${{ steps.is-cached-current.outputs.is-cached == 'true' && steps.validate.outputs.cache-valid != 'false' }}
36+
env:
37+
BIN: target/release/cpp-linter
3638
steps:
3739
- name: Checkout ${{ matrix.name }}
3840
uses: actions/checkout@v4
@@ -43,29 +45,38 @@ jobs:
4345
id: cache
4446
with:
4547
key: bin-cache-${{ hashFiles('cpp-linter/src/**', 'Cargo.toml', 'Cargo.lock', 'cpp-linter/Cargo.toml') }}
46-
path: target/release/cpp-linter
48+
path: ${{ env.BIN }}
4749
- name: Is previous cached?
4850
if: matrix.name == 'previous'
4951
id: is-cached-previous
50-
run: echo "is-cached=${{ steps.cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT
52+
run: echo "is-cached=${{ steps.cache.outputs.cache-hit }}" >> "$GITHUB_OUTPUT"
5153
- name: Is current cached?
5254
if: matrix.name == 'current'
5355
id: is-cached-current
54-
run: echo "is-cached=${{ steps.cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT
56+
run: echo "is-cached=${{ steps.cache.outputs.cache-hit }}" >> "$GITHUB_OUTPUT"
57+
- name: Validate cached binary
58+
if: steps.cache.outputs.cache-hit == 'true'
59+
id: validate
60+
run: |
61+
chmod +x ${{ env.BIN }}
62+
if ! ${{ env.BIN }} version; then
63+
echo "Cached binary is invalid, rebuilding..."
64+
echo "cache-valid=false" >> "$GITHUB_OUTPUT"
65+
fi
5566
- run: rustup update --no-self-update
56-
if: steps.cache.outputs.cache-hit != 'true'
67+
if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false'
5768
- run: cargo build --bin cpp-linter --release
58-
if: steps.cache.outputs.cache-hit != 'true'
69+
if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false'
5970
- name: Upload build artifact
6071
uses: actions/upload-artifact@v4
6172
with:
6273
name: ${{ matrix.name }}
63-
path: target/release/cpp-linter
74+
path: ${{ env.BIN }}
6475

6576
benchmark:
6677
name: Measure Performance Difference
6778
needs: [build]
68-
if: ${{ needs.build.outputs.cached-current != 'true' || needs.build.outputs.cached-previous != 'true' }}
79+
if: ${{ !needs.build.outputs.cached-current || !needs.build.outputs.cached-previous }}
6980
runs-on: ubuntu-latest
7081
steps:
7182
- uses: actions/checkout@v4
@@ -118,7 +129,7 @@ jobs:
118129
--command-name=pure-python
119130
"cpp-linter -l false -j 0 -p build -i='|!src/libgit2' -e c"
120131
- name: Append report to job summary
121-
run: cat ${{ runner.temp }}/benchmark.md >> $GITHUB_STEP_SUMMARY
132+
run: cat ${{ runner.temp }}/benchmark.md >> "$GITHUB_STEP_SUMMARY"
122133
- name: Upload JSON results
123134
uses: actions/upload-artifact@v4
124135
with:
@@ -130,6 +141,6 @@ jobs:
130141
report-no-src-changes:
131142
runs-on: ubuntu-latest
132143
needs: [build]
133-
if: needs.build.outputs.cached-current == 'true' && needs.build.outputs.cached-previous == 'true'
144+
if: needs.build.outputs.cached-current && needs.build.outputs.cached-previous
134145
steps:
135146
- run: echo "::notice title=No benchmark performed::No changes to cpp-linter source code detected."

0 commit comments

Comments
 (0)