Skip to content

Commit 7cfcddd

Browse files
committed
ci: avoid using default caching feature of actions/setup-go
`actions/setup-go` configures the cache under the assumption that a single module will be built with one setup. Signed-off-by: Norio Nomura <[email protected]>
1 parent dc36df8 commit 7cfcddd

File tree

3 files changed

+92
-10
lines changed

3 files changed

+92
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: setup cache for go
2+
description: setup cache for go. export GOMODCACHE environment variable
3+
inputs:
4+
go-version:
5+
description: go version
6+
required: true
7+
runs-on:
8+
description: runs on
9+
required: true
10+
working-directory:
11+
description: working directory
12+
default: '.'
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Set GOMODCACHE environment variable
17+
run: echo "GOMODCACHE=$(pwd)/.gomodcache" >> $GITHUB_ENV
18+
shell: bash
19+
- id: go-env
20+
run: |
21+
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
22+
echo "GOMOD=$(go env GOMOD)" >> $GITHUB_OUTPUT
23+
echo "GOSUM=$(realpath go.sum)" >> $GITHUB_OUTPUT
24+
shell: bash
25+
working-directory: ${{ inputs.working-directory }}
26+
- name: Cache go modules
27+
uses: actions/cache@v4
28+
with:
29+
path: .gomodcache
30+
key: go-modcache-${{ inputs.working-directory }}-${{ inputs.go-version }}-${{ hashFiles(steps.go-env.outputs.GOMOD) }}
31+
restore-keys: |
32+
go-modcache-${{ inputs.working-directory }}-${{ inputs.go-version }}-
33+
go-modcache-${{ inputs.working-directory }}-
34+
enableCrossOsArchive: true
35+
- name: Cache go build cache
36+
uses: actions/cache@v4
37+
with:
38+
path: ${{ steps.go-env.outputs.GOCACHE }}
39+
key: go-cache-${{ inputs.working-directory }}-${{ inputs.runs-on }}-${{ inputs.go-version }}-${{ hashFiles(steps.go-env.outputs.GOSUM) }}
40+
restore-keys: |
41+
go-cache-${{ inputs.working-directory }}-${{ inputs.runs-on }}-${{ inputs.go-version }}-
42+
go-cache-${{ inputs.working-directory }}-${{ inputs.runs-on }}-
43+
go-cache-${{ inputs.working-directory }}-
44+
- name: Download dependencies
45+
run: go mod download -x
46+
shell: bash
47+
working-directory: ${{ inputs.working-directory }}

.github/workflows/build.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,15 @@ jobs:
2929
- uses: actions/checkout@v4
3030
with:
3131
fetch-depth: 0
32-
- uses: actions/setup-go@v5
32+
- id: setup-go
33+
uses: actions/setup-go@v5
3334
with:
35+
cache: false
3436
go-version: ${{ inputs.go-version }}
37+
- uses: ./.github/actions/setup_cache_for_go
38+
with:
39+
go-version: ${{ steps.setup-go.outputs.go-version }}
40+
runs-on: ${{ inputs.runs-on }}
3541
- name: Make
3642
run: make
3743
- name: Make install on Linux

.github/workflows/test.yml

+38-9
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ jobs:
8181
- uses: actions/checkout@v4
8282
with:
8383
fetch-depth: 1
84-
- uses: actions/setup-go@v5
84+
- id: setup-go
85+
uses: actions/setup-go@v5
8586
with:
87+
cache: false
8688
go-version: ${{ matrix.go-version }}
89+
- uses: ./.github/actions/setup_cache_for_go
90+
with:
91+
go-version: ${{ steps.setup-go.outputs.go-version }}
92+
runs-on: ubuntu-24.04
8793
- name: Unit tests
8894
run: go test -v ./...
8995
- name: Make
@@ -161,9 +167,15 @@ jobs:
161167
- uses: actions/checkout@v4
162168
with:
163169
fetch-depth: 1
164-
- uses: actions/setup-go@v5
170+
- id: setup-go
171+
uses: actions/setup-go@v5
165172
with:
173+
cache: false
166174
go-version: 1.23.x
175+
- uses: ./.github/actions/setup_cache_for_go
176+
with:
177+
go-version: ${{ steps.setup-go.outputs.go-version }}
178+
runs-on: macos-12
167179
- name: Unit tests
168180
run: go test -v ./...
169181
- name: Make
@@ -287,23 +299,34 @@ jobs:
287299
# fetch-depth is set to 0 to let `limactl --version` print semver-ish version
288300
fetch-depth: 0
289301
ref: ${{ github.event.pull_request.head.sha }}
290-
- uses: actions/setup-go@v5
291-
with:
292-
go-version: 1.23.x
293302
- uses: actions/cache@v4
294303
with:
295304
path: ~/.cache/lima/download
296305
key: ${{ runner.os }}-colima-${{ matrix.colima-version }}
297306
- uses: ./.github/actions/install_lima_from_artifact
298307
with:
299308
artifact: ${{ needs.build-on-ubuntu.outputs.artifact }}
309+
- name: Checkout colima
310+
uses: actions/checkout@v4
311+
with:
312+
repository: abiosoft/colima
313+
ref: ${{ matrix.colima-version }}
314+
path: colima
315+
- id: setup-go
316+
uses: actions/setup-go@v5
317+
with:
318+
cache: false
319+
go-version: 1.23.x
320+
- uses: ./.github/actions/setup_cache_for_go
321+
with:
322+
go-version: ${{ steps.setup-go.outputs.go-version }}
323+
runs-on: macos-12
324+
working-directory: ./colima
300325
- name: Install colima
301326
run: |
302-
git clone https://github.com/abiosoft/colima
303-
cd colima
304-
git checkout ${{ matrix.colima-version }}
305327
make
306328
sudo make install
329+
working-directory: ./colima
307330
- name: Install test dependencies
308331
run: |
309332
sudo apt-get update
@@ -382,9 +405,15 @@ jobs:
382405
- uses: actions/checkout@v4
383406
with:
384407
fetch-depth: 0
385-
- uses: actions/setup-go@v5
408+
- id: setup-go
409+
uses: actions/setup-go@v5
386410
with:
411+
cache: false
387412
go-version: 1.23.x
413+
- uses: ./.github/actions/setup_cache_for_go
414+
with:
415+
go-version: ${{ steps.setup-go.outputs.go-version }}
416+
runs-on: macos-12
388417
- name: Cache image used by ${{ matrix.oldver }}/examples/ubuntu-lts.yaml
389418
uses: ./.github/actions/setup_cache_for_template
390419
with:

0 commit comments

Comments
 (0)