Skip to content

Commit b2151ca

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 05df36d commit b2151ca

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
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/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)