Fix setup-go cache issues

* Move cleanup earlier, to prevent running out of space when restoring caches
* Consistently use local setup-go action to avoid saving cache on PR runs
* Update local setup-go action

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit 358c8cc00f)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
Brad Davidson 2026-01-09 18:41:27 +00:00 committed by Brad Davidson
parent ceeff68a11
commit 525a648731
7 changed files with 128 additions and 90 deletions

View file

@ -1,15 +1,30 @@
name: 'Setup golang with main only caching'
name: 'Setup Go with Limited Cache'
description: 'A composite action that installs golang, but with a caching strategy that only updates the cache on main branch.'
inputs:
go-version:
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges. Be sure to enclose this option in single quotation marks.'
default: ''
runs:
using: 'composite'
steps:
- uses: actions/setup-go@v5
- name: Find Latest Release Branch
shell: bash
run: |
LATEST_RELEASE_BRANCH=$(gh api repos/k3s-io/k3s/branches?per_page=100 --jq '[.[].name | select(startswith("release-"))] | sort_by(ltrimstr("release-") | tonumber) | last')
echo "LATEST_RELEASE_REF=refs/heads/$LATEST_RELEASE_BRANCH" | tee -a "$GITHUB_ENV"
env:
GH_TOKEN: ${{ github.token }}
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod' # Just use whatever version is in the go.mod file
cache: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release-1.32' }}
go-version: ${{ env.INPUT_GO_VERSION }}
go-version-file: 'go.mod' # if go-version is not set, just use whatever version is in the go.mod file
cache: ${{ github.ref == 'refs/heads/main' || github.ref == env.LATEST_RELEASE_REF }} # use default cache for main and most recent minor
- name: Prepare for go cache
if: github.ref != 'refs/heads/main' && github.ref != 'refs/heads/release-1.32'
if: github.ref != 'refs/heads/main' && github.ref != env.LATEST_RELEASE_REF # use custom cache for older minors
shell: bash
run: |
echo "GO_CACHE=$(go env GOCACHE)" | tee -a "$GITHUB_ENV"
@ -17,8 +32,8 @@ runs:
echo "GO_VERSION=$(go env GOVERSION | tr -d 'go')" | tee -a "$GITHUB_ENV"
- name: Setup read-only cache
if: github.ref != 'refs/heads/main' && github.ref != 'refs/heads/release-1.32'
uses: actions/cache/restore@v4
if: github.ref != 'refs/heads/main' && github.ref != env.LATEST_RELEASE_REF # use custom cache for older minors
uses: actions/cache/restore@v5
with:
path: |
${{ env.GO_MODCACHE }}
@ -26,4 +41,4 @@ runs:
# Match the cache key to the setup-go action https://github.com/actions/setup-go/blob/main/src/cache-restore.ts#L34
key: setup-go-${{ runner.os }}-${{ env.ImageOS }}-go-${{ env.GO_VERSION }}-${{ hashFiles('go.sum') }}
restore-keys: |
setup-go-${{ runner.os }}-
setup-go-${{ runner.os }}-

View file

@ -54,6 +54,25 @@ jobs:
etest: [btrfs, embeddedmirror, externalip, privateregistry, rootless, s3, startup, wasm, multus]
max-parallel: 5
steps:
- name: Remove Unnecessary Tools
working-directory: /
run: |
sudo rm -rf \
/home/linuxbrew \
/home/packer \
/opt/az \
/opt/microsoft \
/usr/lib/firefox \
/usr/lib/google-cloud-sdk \
/usr/local/julia* \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: "Checkout"
uses: actions/checkout@v6
with: {fetch-depth: 1}
@ -92,24 +111,6 @@ jobs:
with:
name: k3s-amd64
path: ./dist/artifacts
- name: Remove Unnecessary Tools
run: |
sudo rm -rf \
/home/linuxbrew \
/home/packer \
/opt/az \
/opt/microsoft \
/usr/lib/firefox \
/usr/lib/google-cloud-sdk \
/usr/local/julia* \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: Run ${{ matrix.etest }} Test
env:
E2E_GOCOVER: "true"
@ -202,6 +203,25 @@ jobs:
env:
CHANNEL: ${{ needs.build-go-tests.outputs.channel }}
steps:
- name: Remove Unnecessary Tools
working-directory: /
run: |
sudo rm -rf \
/home/linuxbrew \
/home/packer \
/opt/az \
/opt/microsoft \
/usr/lib/firefox \
/usr/lib/google-cloud-sdk \
/usr/local/julia* \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: Checkout
uses: actions/checkout@v6
- name: "Download K3s image"
@ -229,24 +249,6 @@ jobs:
with:
name: docker-go-tests-${{ matrix.arch }}
path: ./dist/artifacts
- name: Remove Unnecessary Tools
run: |
sudo rm -rf \
/home/linuxbrew \
/home/packer \
/opt/az \
/opt/microsoft \
/usr/lib/firefox \
/usr/lib/google-cloud-sdk \
/usr/local/julia* \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: Run ${{ matrix.dtest }} Test
# Put the compiled test binary back in the same place as the test source
run: |

View file

@ -38,6 +38,25 @@ jobs:
env:
INSTALL_K3S_SKIP_DOWNLOAD: binary
steps:
- name: Remove Unnecessary Tools
working-directory: /
run: |
sudo rm -rf \
/home/linuxbrew \
/home/packer \
/opt/az \
/opt/microsoft \
/usr/lib/firefox \
/usr/lib/google-cloud-sdk \
/usr/local/julia* \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: "Checkout"
uses: actions/checkout@v6
with: {fetch-depth: 1}
@ -56,24 +75,6 @@ jobs:
with:
name: k3s-amd64
path: tests/install/${{ matrix.vm }}
- name: Remove Unnecessary Tools
run: |
sudo rm -rf \
/home/linuxbrew \
/home/packer \
/opt/az \
/opt/microsoft \
/usr/lib/firefox \
/usr/lib/google-cloud-sdk \
/usr/local/julia* \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: "Vagrant Up"
run: vagrant up --no-tty --no-provision
- name: "Upload k3s binary to VM"

View file

@ -47,18 +47,8 @@ jobs:
itest: [certrotation, cacertrotation, etcdrestore, localstorage, startup, custometcdargs, etcdsnapshot, kubeflags, longhorn, secretsencryption, flannelnone]
max-parallel: 3
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Install Go
uses: ./.github/actions/setup-go
- name: "Download k3s binary"
uses: actions/download-artifact@v7
with:
name: k3s-amd64
path: ./dist/artifacts
- name: Remove Unnecessary Tools
working-directory: /
run: |
sudo rm -rf \
/home/linuxbrew \
@ -76,6 +66,17 @@ jobs:
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Install Go
uses: ./.github/actions/setup-go
- name: "Download k3s binary"
uses: actions/download-artifact@v7
with:
name: k3s-amd64
path: ./dist/artifacts
- name: Run Integration Tests
run: |
chmod +x ./dist/artifacts/k3s

View file

@ -24,19 +24,8 @@ jobs:
env:
INSTALL_K3S_CHANNEL: ${{ matrix.channel }}
steps:
- name: "Checkout"
uses: actions/checkout@v6
with: {fetch-depth: 1}
- name: Set up vagrant and libvirt
uses: ./.github/actions/vagrant-setup
- name: "Vagrant Cache"
uses: actions/cache@v5
with:
path: |
~/.vagrant.d/boxes
key: vagrant-box-${{ matrix.vm }}
id: vagrant-cache
- name: Remove Unnecessary Tools
working-directory: /
run: |
sudo rm -rf \
/home/linuxbrew \
@ -54,6 +43,18 @@ jobs:
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: "Checkout"
uses: actions/checkout@v6
with: {fetch-depth: 1}
- name: Set up vagrant and libvirt
uses: ./.github/actions/vagrant-setup
- name: "Vagrant Cache"
uses: actions/cache@v5
with:
path: |
~/.vagrant.d/boxes
key: vagrant-box-${{ matrix.vm }}
id: vagrant-cache
- name: "Vagrant Plugin(s)"
run: vagrant plugin install vagrant-k3s vagrant-reload
- name: "Vagrant Up ⏩ Install K3s"

View file

@ -23,10 +23,8 @@ jobs:
uses: actions/checkout@v6
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: 'stable'
cache: false
uses: ./.github/actions/setup-go
- name: Delete leftover UpdateCLI branches
run: |
gh pr list --search "is:closed is:pr head:updatecli_" --json headRefName --jq ".[].headRefName" | sort -u > closed_prs_branches.txt

View file

@ -20,6 +20,26 @@ jobs:
name: Validate
runs-on: ubuntu-latest
steps:
- name: Remove Unnecessary Tools
working-directory: /
run: |
sudo rm -rf \
/home/linuxbrew \
/home/packer \
/opt/az \
/opt/microsoft \
/usr/lib/firefox \
/usr/lib/google-cloud-sdk \
/usr/local/julia* \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
df -khl
- name: Set Commit Count
run: |
echo "GITHUB_CHECKOUT_FETCH_DEPTH=$( expr 1 + ${{ github.event.pull_request.commits }} )" >> "$GITHUB_ENV"
@ -35,7 +55,7 @@ jobs:
echo "GOTOOLCHAIN=${VERSION_GOLANG/go}" >> "$GITHUB_ENV"
- name: Setup Go
uses: actions/setup-go@v6
uses: ./.github/actions/setup-go
with:
go-version: "${{ env.GOTOOLCHAIN }}"