Skip to content

Commit 5bc0c91

Browse files
committed
Optimize Go's mod cache usage across GH Actions
In order to be able to share caches between operating systems, you have to set enableCrossOsArchive to true, and the cache paths have to be identical (which was already the case). Also make sure that go.mod/go.sum files always use LF line endings, even on Windows. Otherwise the cache keys would be different. See: https://github.com/actions/cache/blob/v4.2.0/tips-and-workarounds.md#cross-os-cache Signed-off-by: Tom Wieczorek <[email protected]>
1 parent bf8a3fd commit 5bc0c91

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go.mod text eol=lf
2+
go.sum text eol=lf

.github/workflows/build-k0s.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ jobs:
8080
- name: "Cache :: GOMODCACHE"
8181
uses: actions/cache@v4
8282
with:
83-
key: build-k0s-${{ inputs.target-os }}-${{ inputs.target-arch }}-gomodcache-${{ hashFiles('go.sum') }}
84-
path: |
85-
build/cache/go/mod
83+
key: build-k0s-gomodcache-${{ hashFiles('go.sum') }}
84+
path: build/cache/go/mod
85+
enableCrossOsArchive: true
8686

8787
- name: "Build :: k0s"
8888
run: |

.github/workflows/check-network.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ jobs:
8989
path: |
9090
build/cache/go/build
9191
- name: Cache GOMODCACHE
92-
uses: actions/cache@v4
92+
uses: actions/cache/restore@v4
9393
with:
94-
key: ${{ runner.os }}-build-gomodcache-linux-${{ hashFiles('go.sum') }}
95-
path: |
96-
build/cache/go/mod
94+
key: build-k0s-gomodcache-${{ hashFiles('go.sum') }}
95+
path: build/cache/go/mod
96+
enableCrossOsArchive: true
9797

9898
- name: Build k0s Binary
9999
id: k0s_build

.github/workflows/go.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ jobs:
182182
uses: actions/cache@v4
183183
with:
184184
key: unittests-k0s-gomodcache-${{ hashFiles('go.sum') }}
185-
path: |
186-
build/cache/go/mod
185+
path: build/cache/go/mod
186+
enableCrossOsArchive: true
187187

188188
- name: Run unit tests
189189
run: make check-unit $UNITTEST_EXTRA_ARGS

0 commit comments

Comments
 (0)