@@ -5,12 +5,16 @@ inputs:
5
5
go-version :
6
6
description : Go version range to set up.
7
7
default : ' >=1.24.0'
8
- cache-name :
9
- description : Name of scoped cache for this set up.
10
- default : ' cache'
8
+ create :
9
+ description : Create the cache
10
+ default : ' false'
11
+ lint-cache :
12
+ description : Restore the golangci-lint cache
13
+ default : ' false'
11
14
12
15
runs :
13
16
using : composite
17
+
14
18
steps :
15
19
- name : Install Go
16
20
id : install-go
@@ -19,18 +23,101 @@ runs:
19
23
go-version : ${{ inputs.go-version }}
20
24
cache : false
21
25
22
- # There is more code downloaded and built than is covered by '**/go.sum',
23
- # so give each job its own cache to try and not end up sharing the wrong
24
- # cache between jobs, and hash the Herebyfile and golancgi-lint version.
26
+ # Avoid hardcoding the cache keys more than once.
27
+ - name : Get cache info
28
+ shell : bash
29
+ id : cache-info
30
+ env :
31
+ MODULES_KEY : go-modules-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml', '**/.dprint.jsonc') }}
32
+ LINT_KEY : golangci-lint-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml', '**/.dprint.jsonc') }}
33
+ BUILD_KEY : go-build-cache-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}
34
+ run : |
35
+ echo "modules-key=$MODULES_KEY" >> $GITHUB_OUTPUT
36
+ echo "lint-key=$LINT_KEY" >> $GITHUB_OUTPUT
37
+ echo "build-key=$BUILD_KEY" >> $GITHUB_OUTPUT
38
+ echo "GOLANGCI_LINT_CACHE=$RUNNER_TEMP/golangci-lint-cache" >> $GITHUB_ENV
39
+
40
+ - if : ${{ inputs.create != 'true' }}
41
+ name : Restore Go modules
42
+ uses : actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
43
+ with :
44
+ key : unused-key-${{ github.run_id }}
45
+ restore-keys : ${{ steps.cache-info.outputs.modules-key }}-
46
+ path : |
47
+ ~/go/pkg/mod
48
+
49
+ - if : ${{ inputs.create != 'true' }}
50
+ name : Restore Go build cache
51
+ uses : actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
52
+ with :
53
+ key : unused-key-${{ github.run_id }}
54
+ restore-keys : ${{ steps.cache-info.outputs.build-key }}-
55
+ path : |
56
+ ~/.cache/go-build
57
+ ~/Library/Caches/go-build
58
+ ~/AppData/Local/go-build
59
+
60
+ - if : ${{ inputs.create != 'true' && inputs.lint-cache == 'true' }}
61
+ name : Restore golangci-lint cache
62
+ uses : actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
63
+ with :
64
+ key : unused-key-${{ github.run_id }}
65
+ restore-keys : ${{ steps.cache-info.outputs.lint-key }}-
66
+ path : ${{ env.GOLANGCI_LINT_CACHE }}
67
+
68
+ - name : Set mtimes
69
+ shell : bash
70
+ run : |
71
+ find . -type f ! -path ./.git/\*\* | go run github.com/slsyy/mtimehash/cmd/[email protected] || true
72
+ find . -type d ! -path ./.git/\*\* -exec touch -d '1970-01-01T00:00:01Z' {} + || true
73
+
74
+ # All steps below are only run if the cache is being created.
75
+
76
+ - if : ${{ inputs.create == 'true' }}
77
+ shell : bash
78
+ run : npm ci
79
+
80
+ - if : ${{ inputs.create == 'true' }}
81
+ shell : bash
82
+ run : npx hereby build
83
+
84
+ - if : ${{ inputs.create == 'true' }}
85
+ shell : bash
86
+ run : npx hereby test
87
+
88
+ - if : ${{ inputs.create == 'true' }}
89
+ shell : bash
90
+ run : npx hereby lint
91
+
92
+ - if : ${{ inputs.create == 'true' }}
93
+ shell : bash
94
+ run : npx hereby lint --noembed
25
95
26
- - name : Go cache
27
- uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
96
+ - if : ${{ inputs.create == 'true' }}
97
+ shell : bash
98
+ run : npx dprint check
99
+
100
+ - if : ${{ inputs.create == 'true' }}
101
+ name : Save Go modules
102
+ uses : actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
28
103
with :
29
- 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 }}
30
- restore-keys : |
31
- ts-setup-go-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/Herebyfile.mjs', '**/.custom-gcl.yml') }}-${{ github.workflow }}-
104
+ key : ${{ steps.cache-info.outputs.modules-key }}
32
105
path : |
33
106
~/go/pkg/mod
107
+
108
+ - if : ${{ inputs.create == 'true' }}
109
+ name : Save Go build cache
110
+ uses : actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
111
+ with :
112
+ key : ${{ steps.cache-info.outputs.build-key }}-${{ github.run_id }}
113
+ path : |
34
114
~/.cache/go-build
35
115
~/Library/Caches/go-build
36
116
~/AppData/Local/go-build
117
+
118
+ - if : ${{ inputs.create == 'true' }}
119
+ name : Save golangci-lint cache
120
+ uses : actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
121
+ with :
122
+ key : ${{ steps.cache-info.outputs.lint-key }}-${{ github.run_id }}
123
+ path : ${{ env.GOLANGCI_LINT_CACHE }}
0 commit comments