31
31
- commit : ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
32
32
name : previous
33
33
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
36
38
steps :
37
39
- name : Checkout ${{ matrix.name }}
38
40
uses : actions/checkout@v4
@@ -43,29 +45,38 @@ jobs:
43
45
id : cache
44
46
with :
45
47
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 }}
47
49
- name : Is previous cached?
48
50
if : matrix.name == 'previous'
49
51
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"
51
53
- name : Is current cached?
52
54
if : matrix.name == 'current'
53
55
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
55
66
- 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'
57
68
- 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'
59
70
- name : Upload build artifact
60
71
uses : actions/upload-artifact@v4
61
72
with :
62
73
name : ${{ matrix.name }}
63
- path : target/release/cpp-linter
74
+ path : ${{ env.BIN }}
64
75
65
76
benchmark :
66
77
name : Measure Performance Difference
67
78
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 }}
69
80
runs-on : ubuntu-latest
70
81
steps :
71
82
- uses : actions/checkout@v4
@@ -118,7 +129,7 @@ jobs:
118
129
--command-name=pure-python
119
130
"cpp-linter -l false -j 0 -p build -i='|!src/libgit2' -e c"
120
131
- 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"
122
133
- name : Upload JSON results
123
134
uses : actions/upload-artifact@v4
124
135
with :
@@ -130,6 +141,6 @@ jobs:
130
141
report-no-src-changes :
131
142
runs-on : ubuntu-latest
132
143
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
134
145
steps :
135
146
- run : echo "::notice title=No benchmark performed::No changes to cpp-linter source code detected."
0 commit comments