@@ -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,111 @@ 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', '**/.custom-gcl.yml') }}
32
+ LINT_KEY : golangci-lint-${{ runner.os }}-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/.custom-gcl.yml') }}
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 : ${{ steps.cache-info.outputs.modules-key }}
45
+ path : |
46
+ ~/go/pkg/mod
47
+
48
+ - if : ${{ inputs.create != 'true' }}
49
+ name : Restore Go build cache
50
+ uses : actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
51
+ with :
52
+ key : unused-key-${{ github.run_id }}
53
+ restore-keys : ${{ steps.cache-info.outputs.build-key }}-
54
+ path : |
55
+ ~/.cache/go-build
56
+ ~/Library/Caches/go-build
57
+ ~/AppData/Local/go-build
58
+
59
+ - if : ${{ inputs.create != 'true' && inputs.lint-cache == 'true' }}
60
+ name : Restore golangci-lint cache
61
+ uses : actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
62
+ with :
63
+ key : unused-key-${{ github.run_id }}
64
+ restore-keys : ${{ steps.cache-info.outputs.lint-key }}-
65
+ path : ${{ env.GOLANGCI_LINT_CACHE }}
66
+
67
+ - name : Set mtimes
68
+ shell : bash
69
+ run : |
70
+ find . -type f ! -path ./.git/\*\* | go run github.com/slsyy/mtimehash/cmd/[email protected] || true
71
+ find . -type d ! -path ./.git/\*\* -exec touch -d '1970-01-01T00:00:01Z' {} + || true
25
72
26
- - name : Go cache
27
- uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
73
+ # All steps below are only run if the cache is being created.
74
+
75
+ - if : ${{ inputs.create == 'true' }}
76
+ shell : bash
77
+ run : npm ci
78
+
79
+ - if : ${{ inputs.create == 'true' }}
80
+ shell : bash
81
+ run : |
82
+ go mod download
83
+ cd _tools
84
+ go mod download
85
+
86
+ - if : ${{ inputs.create == 'true' }}
87
+ shell : bash
88
+ run : npx hereby build
89
+
90
+ - if : ${{ inputs.create == 'true' }}
91
+ shell : bash
92
+ run : npx hereby test
93
+
94
+ - if : ${{ inputs.create == 'true' }}
95
+ shell : bash
96
+ run : npx hereby test --coverage
97
+
98
+ - if : ${{ inputs.create == 'true' }}
99
+ shell : bash
100
+ run : npx hereby lint
101
+
102
+ - if : ${{ inputs.create == 'true' }}
103
+ shell : bash
104
+ run : npx hereby lint --noembed
105
+
106
+ - if : ${{ inputs.create == 'true' }}
107
+ shell : bash
108
+ run : npx dprint check
109
+
110
+ - if : ${{ inputs.create == 'true' }}
111
+ name : Save Go modules
112
+ uses : actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
28
113
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 }}-
114
+ key : ${{ steps.cache-info.outputs.modules-key }}
32
115
path : |
33
116
~/go/pkg/mod
117
+
118
+ - if : ${{ inputs.create == 'true' }}
119
+ name : Save Go build cache
120
+ uses : actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
121
+ with :
122
+ key : ${{ steps.cache-info.outputs.build-key }}-${{ github.run_id }}
123
+ path : |
34
124
~/.cache/go-build
35
125
~/Library/Caches/go-build
36
126
~/AppData/Local/go-build
127
+
128
+ - if : ${{ inputs.create == 'true' }}
129
+ name : Save golangci-lint cache
130
+ uses : actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
131
+ with :
132
+ key : ${{ steps.cache-info.outputs.lint-key }}-${{ github.run_id }}
133
+ path : ${{ env.GOLANGCI_LINT_CACHE }}
0 commit comments