Reuse cached Go modules across CI jobs

The kind e2e jobs download every module on every run. setup-go restores
its cache from main, but push.yml runs `go clean -modcache` before
setup-go's post step saves, so main holds an empty entry (1568 bytes)
under the key PR jobs ask for. They count it as a hit, so nothing is
ever saved over it.

- push.yml: turn off setup-go's cache, since the job empties it.
- e2e-test-kind.yaml: the build job restores one module cache, downloads
  what the e2e jobs need on a miss (`go mod download` plus the ginkgo
  CLI), and saves it before the job ends. The e2e jobs restore the same
  key. It is keyed on go.mod and go.sum rather than the Go patch version,
  which differed between runner images within one run.
- pr-ci-check.yml: point GOMODCACHE at .go/pkg/mod, which the build
  container mounts, so `go mod tidy` on the host and the containerised
  steps share one download that setup-go caches.

Fixes #10653

Signed-off-by: Parman Mohammadalizadeh <prmma23@gmail.com>
This commit is contained in:
Parman Mohammadalizadeh
2026-10-14 20:46:42 +02:00
parent 931a805207
commit c0d13fc51f
3 changed files with 45 additions and 0 deletions
+38
View File
@@ -37,6 +37,24 @@ jobs:
uses: actions/setup-go@v7
with:
go-version: ${{ needs.get-go-version.outputs.version }}
cache: false
# One Go module cache for this job and the e2e jobs. The key leaves out the
# Go patch version, which differs between runner images in the same run.
- name: Restore Go module cache
id: go-mod-cache
uses: actions/cache/restore@v6
with:
path: ~/go/pkg/mod
key: go-mod-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
restore-keys: go-mod-${{ runner.os }}-${{ runner.arch }}-
# Download everything the e2e jobs need, including the ginkgo CLI's own
# dependencies, so they can run from the cache.
- name: Download Go modules
if: steps.go-mod-cache.outputs.cache-hit != 'true'
run: |
go mod download
make -C test/ ginkgo
# Look for a CLI that's made for this PR
- name: Fetch built CLI
@@ -106,6 +124,12 @@ jobs:
with:
path: ./minio-image.tar
key: minio-bitnami-${{ env.BITNAMI_CONTAINERS_COMMIT }}
- name: Save Go module cache
if: steps.go-mod-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: ~/go/pkg/mod
key: ${{ steps.go-mod-cache.outputs.cache-primary-key }}
# Create json of k8s versions to test
# from guide: https://stackoverflow.com/a/65094398/4590470
setup-test-matrix:
@@ -203,6 +227,13 @@ jobs:
uses: actions/setup-go@v7
with:
go-version: ${{ needs.get-go-version.outputs.version }}
cache: false
- name: Restore Go module cache
uses: actions/cache/restore@v6
with:
path: ~/go/pkg/mod
key: go-mod-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
restore-keys: go-mod-${{ runner.os }}-${{ runner.arch }}-
# Fetch the pre-built MinIO image from the build job
- name: Fetch built MinIO Image
@@ -298,6 +329,13 @@ jobs:
uses: actions/setup-go@v7
with:
go-version: ${{ needs.get-go-version.outputs.version }}
cache: false
- name: Restore Go module cache
uses: actions/cache/restore@v6
with:
path: ~/go/pkg/mod
key: go-mod-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
restore-keys: go-mod-${{ runner.os }}-${{ runner.arch }}-
# Fetch the pre-built MinIO image from the build job
- name: Fetch built MinIO Image
+4
View File
@@ -14,6 +14,10 @@ jobs:
name: Run CI
needs: get-go-version
runs-on: ubuntu-latest
# The build container mounts .go/pkg as its GOPATH/pkg, so pointing the host
# here lets go mod tidy and the container share one cached module download.
env:
GOMODCACHE: ${{ github.workspace }}/.go/pkg/mod
strategy:
fail-fast: false
steps:
+3
View File
@@ -29,6 +29,9 @@ jobs:
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: ${{ needs.get-go-version.outputs.version }}
# The Build step cleans the module cache, so saving it would store an
# empty entry under the key that PR jobs restore.
cache: false
- name: Set up QEMU
id: qemu