diff --git a/.github/actions/setup-go/action.yaml b/.github/actions/setup-go/action.yaml index bc636b4bb83..1fd2551d6be 100644 --- a/.github/actions/setup-go/action.yaml +++ b/.github/actions/setup-go/action.yaml @@ -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 }}- \ No newline at end of file + setup-go-${{ runner.os }}- diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index a930f0c1ca5..8f933558000 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -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: | diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index 0e5e4251162..d93db9109a7 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -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" diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index b36f0c7baf1..0706f3db44a 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -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 diff --git a/.github/workflows/nightly-install.yaml b/.github/workflows/nightly-install.yaml index 11f79f370b6..8c778a1cf20 100644 --- a/.github/workflows/nightly-install.yaml +++ b/.github/workflows/nightly-install.yaml @@ -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" diff --git a/.github/workflows/updatecli.yaml b/.github/workflows/updatecli.yaml index bb8af4d84b3..5d878bf0731 100644 --- a/.github/workflows/updatecli.yaml +++ b/.github/workflows/updatecli.yaml @@ -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 diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 29c5ddb377f..1c199f7437d 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -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 }}"