Skip to content

Commit f8881cc

Browse files
committed
GitHub: add key-prefix and use-build-cache to setup-go action
This allows us to control the cache key and whether we want to cache the Go build cache (which can grow very large).
1 parent 474080f commit f8881cc

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

.github/actions/setup-go/action.yml

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ inputs:
44
go-version:
55
description: "The version of Golang to set up"
66
required: true
7+
key-prefix:
8+
description: "A prefix to use for the cache key, to separate cache entries from other workflows"
9+
required: false
10+
use-build-cache:
11+
description: "Whether to use the build cache"
12+
required: false
13+
# Boolean values aren't supported in the workflow syntax, so we use a
14+
# string. To not confuse the value with true/false, we use 'yes' and 'no'.
15+
default: 'yes'
716

817
runs:
918
using: "composite"
@@ -16,19 +25,42 @@ runs:
1625
git config --global core.autocrlf false
1726
1827
- name: setup go ${{ inputs.go-version }}
19-
uses: actions/setup-go@v3
28+
uses: actions/setup-go@v5
2029
with:
2130
go-version: '${{ inputs.go-version }}'
2231

23-
- name: go cache
24-
uses: actions/cache@v3
32+
- name: go module and build cache
33+
if: ${{ inputs.use-build-cache == 'yes' }}
34+
uses: actions/cache@v4
2535
with:
36+
# In order:
37+
# * Module download cache
38+
# * Build cache (Linux)
39+
# * Build cache (Mac)
40+
# * Build cache (Windows)
2641
path: |
27-
/home/runner/go/pkg/mod
28-
/home/runner/.cache/go-build
29-
key: litd-${{ runner.os }}-go-${{ inputs.go-version }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
42+
~/go/pkg/mod
43+
~/.cache/go-build
44+
~/Library/Caches/go-build
45+
~\AppData\Local\go-build
46+
key: ${{ runner.os }}-go-${{ inputs.go-version }}-${{ inputs.key-prefix }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
3047
restore-keys: |
31-
litd-${{ runner.os }}-go-${{ inputs.go-version }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
32-
litd-${{ runner.os }}-go-${{ inputs.go-version }}-${{ github.job }}-
33-
litd-${{ runner.os }}-go-${{ inputs.go-version }}-
34-
litd-${{ runner.os }}-go-
48+
${{ runner.os }}-go-${{ inputs.go-version }}-${{ inputs.key-prefix }}-${{ github.job }}-
49+
${{ runner.os }}-go-${{ inputs.go-version }}-${{ inputs.key-prefix }}-
50+
51+
- name: go module cache
52+
if: ${{ inputs.use-build-cache == 'no' }}
53+
uses: actions/cache@v4
54+
with:
55+
# Just the module download cache.
56+
path: |
57+
~/go/pkg/mod
58+
key: ${{ runner.os }}-go-${{ inputs.go-version }}-${{ inputs.key-prefix }}-no-build-cache-${{ github.job }}-${{ hashFiles('**/go.sum') }}
59+
restore-keys: |
60+
${{ runner.os }}-go-${{ inputs.go-version }}-${{ inputs.key-prefix }}-no-build-cache-${{ github.job }}-
61+
${{ runner.os }}-go-${{ inputs.go-version }}-${{ inputs.key-prefix }}-no-build-cache-
62+
63+
- name: set GOPATH
64+
shell: bash
65+
run: |
66+
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV

0 commit comments

Comments
 (0)