8
8
cache-name :
9
9
description : Name of scoped cache for this set up.
10
10
default : ' cache'
11
+ cache-from-previous-run :
12
+ description : Use the cache from the previous run if available.
13
+ default : ' false'
11
14
12
15
runs :
13
16
using : composite
@@ -19,15 +22,37 @@ runs:
19
22
go-version : ${{ inputs.go-version }}
20
23
cache : false
21
24
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
+
22
51
- name : Go cache
23
52
uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
24
53
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 }}
31
56
path : |
32
57
~/go/pkg/mod
33
58
~/.cache/go-build
0 commit comments