88 cache-name :
99 description : Name of scoped cache for this set up.
1010 default : ' cache'
11+ cache-from-previous-run :
12+ description : Use the cache from the previous run if available.
13+ default : ' false'
1114
1215runs :
1316 using : composite
@@ -19,15 +22,37 @@ runs:
1922 go-version : ${{ inputs.go-version }}
2023 cache : false
2124
25+ # There is more code downloaded and built than is covered by '**/go.sum',
26+ # so give each job its own cache to try and not end up sharing the wrong
27+ # cache between jobs, and hash the Herebyfile and golancgi-lint version.
28+
29+ # In cache-from-previous-run mode, we try to restore the cache from the
30+ # previous run, and force the next cache to be saved by keying it on the
31+ # run ID.
32+
33+ - name : Create Go cache keys
34+ id : go-cache-keys
35+ shell : bash
36+ run : |
37+ if [[ "$CACHE_FROM_PREVIOUS_RUN" == "true" ]]; then
38+ echo "key=$PREFIX-$CACHE_NAME-$RUN_ID" >> $GITHUB_OUTPUT
39+ echo "restore-keys=$PREFIX-$CACHE_NAME" >> $GITHUB_OUTPUT
40+ else
41+ echo "key=$PREFIX-$CACHE_NAME" >> $GITHUB_OUTPUT
42+ echo "restore-keys=$PREFIX" >> $GITHUB_OUTPUT
43+ fi
44+
45+ env :
46+ PREFIX : ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}-${{ github.workflow }}
47+ CACHE_NAME : ${{ inputs.cache-name }}
48+ RUN_ID : ${{ github.run_id }}
49+ CACHE_FROM_PREVIOUS_RUN : ${{ inputs.cache-from-previous-run }}
50+
2251 - name : Go cache
2352 uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
2453 with :
25- # There is more code downloaded and built than is covered by '**/go.sum',
26- # so give each job its own cache to try and not end up sharing the wrong
27- # cache between jobs.
28- key : ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}-${{ github.workflow }}-${{ inputs.cache-name }}
29- restore-keys : |
30- ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}
54+ key : ${{ steps.go-cache-keys.outputs.key }}
55+ restore-keys : ${{ steps.go-cache-keys.outputs.restore-keys }}
3156 path : |
3257 ~/go/pkg/mod
3358 ~/.cache/go-build
0 commit comments