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,24 +45,33 @@ 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
@@ -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 :
0 commit comments