@@ -178,6 +178,8 @@ jobs:
178178
179179 env :
180180 EMBEDDED_BINS_BUILDMODE : none
181+ # Set SOURCE_DATE_EPOCH to optimize cache usage
182+ MAKEFLAGS : -j SOURCE_DATE_EPOCH=315532800
181183
182184 steps :
183185 - name : Check out code into the Go module directory
@@ -208,24 +210,30 @@ jobs:
208210 go-version : ${{ env.GO_VERSION }}
209211 cache : false
210212
211- - name : Cache GOCACHE
213+ - name : Cache Go cache
214+ id : cache-gocache
212215 uses : actions/cache@v4
213216 with :
214- key : unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}-${{ github.sha }}
215- restore-keys : |
216- unittests-k0s-${{ matrix.name }}-gocache-${{ github.ref_name }}-
217- path : |
218- build/cache/go/build
219-
220- - name : Cache GOMODCACHE
221- uses : actions/cache@v4
222- with :
223- key : unittests-k0s-gomodcache-${{ hashFiles('go.sum') }}
224- path : build/cache/go/mod
225- enableCrossOsArchive : true
217+ key : " unittests-k0s-${{ matrix.name }}-gocache-go${{ env.GO_VERSION }}-${{ github.sha }}"
218+ restore-keys : " unittests-k0s-${{ matrix.name }}-gocache-go${{ env.GO_VERSION }}-"
219+ path : build/cache/go/build
226220
227221 - name : Run unit tests
228- run : make check-unit $UNITTEST_EXTRA_ARGS
222+ env :
223+ CACHE_HIT_GOCACHE : " ${{ steps.cache-gocache.outputs.cache-hit }}"
224+ run : |
225+ if [ -n "$CACHE_HIT_GOCACHE" ]; then
226+ echo Preparing Go cache
227+ touch -t "$(TZ=UTC+24 date +%Y%m%d%H%M.%S)" build/cache/_cache_sentinel
228+ find build/cache/go/build -type f \( -name '*-a' -o -name '*-d' \) -exec touch -r build/cache/_cache_sentinel {} +
229+ fi
230+
231+ make check-unit $UNITTEST_EXTRA_ARGS
232+
233+ if [ -n "$CACHE_HIT_GOCACHE" ]; then
234+ echo Trimming Go cache
235+ find build/cache/go/build -type f \( -name '*-a' -o -name '*-d' \) -not -newer build/cache/_cache_sentinel -delete
236+ fi
229237
230238 smoketests :
231239 strategy :
@@ -308,35 +316,40 @@ jobs:
308316 go-version : ${{ env.GO_VERSION }}
309317
310318 - name : Cache embedded binaries
319+ id : cache-embedded-bins
311320 uses : actions/cache@v4
312321 with :
313- key : ${{ runner.os }}-embedded-bins-arm-${{ hashFiles('**/embedded-bins/**/*') }}
314- path : |
315- .bins.linux.stamp
316- embedded-bins/staging/linux/bin/
317- embedded-bins/Makefile.variables
322+ key : " build-k0s-linux-arm-embedded-bins-${{ hashFiles('embedded-bins/**/*') }}"
323+ path : embedded-bins/staging/linux/bin/
318324
319- - name : Cache GOCACHE
325+ - name : Cache Go cache
326+ id : cache-gocache
320327 uses : actions/cache@v4
321328 with :
322- key : ${{ runner.os }}-smoketest-arm-gocache-arm-${{ github.ref_name }}-${{ github.sha }}
323- restore-keys : |
324- ${{ runner.os }}-smoketest-arm-gocache-arm-${{ github.ref_name }}-
325- path : |
326- build/cache/go/build
329+ key : " build-k0s-linux-arm-gocache-go${{ env.GO_VERSION }}-${{ github.sha }}"
330+ restore-keys : " build-k0s-linux-arm-gocache-go${{ env.GO_VERSION }}-"
331+ path : build/cache/go/build
327332
328- - name : Cache GOMODCACHE
329- uses : actions/cache@v4
330- with :
331- key : ${{ runner.os }}-smoketest-arm-gomodcache-arm-${{ hashFiles('go.sum') }}
332- path : |
333- build/cache/go/mod
333+ - name : Prepare Go cache
334+ if : steps.cache-gocache.outputs.cache-hit
335+ run : |
336+ touch -t "$(TZ=UTC+24 date +%Y%m%d%H%M.%S)" build/cache/_cache_sentinel
337+ find build/cache/go/build -type f \( -name '*-a' -o -name '*-d' \) -exec touch -r build/cache/_cache_sentinel {} +
334338
335339 - name : Build
340+ env :
341+ EMBEDDED_BINS_CACHED : " ${{ steps.cache-embedded-bins.outputs.cache-hit }}"
336342 run : |
343+ gh --version || echo No gh installed
344+ make .k0sbuild.docker-image.k0s
345+ touch go.sum
346+ if [ "$EMBEDDED_BINS_CACHED" == true ]; then
347+ make --touch .bins.linux.stamp
348+ fi
337349 make bindata
338350 make --touch codegen
339351 make build
352+ echo "k0s binary size: **$(du -sh k0s | cut -f1)**" >>$GITHUB_STEP_SUMMARY
340353
341354 - name : Upload compiled executable
342355 uses : actions/upload-artifact@v4
@@ -369,6 +382,11 @@ jobs:
369382 name : airgap-image-bundle-linux-arm.tar
370383 path : airgap-image-bundle-linux-arm.tar
371384
385+ - name : Trim Go cache
386+ if : steps.cache-gocache.outputs.cache-hit
387+ run : |
388+ find build/cache/go/build -type f \( -name '*-a' -o -name '*-d' \) -not -newer build/cache/_cache_sentinel -delete
389+
372390 # TODO We probably want to separate the smoketest into a separate callable workflow which we can call from the build step
373391 # This way we could actually fully parallelize the build and smoketest steps. Currently we are limited by the fact that
374392 # smoke-test step only start after both arm and armv7 builds have finished.
0 commit comments