diff --git a/.github/actions/setup-go/actions.yaml b/.github/actions/setup-go/actions.yaml new file mode 100644 index 000000000000..c9efe6be8a78 --- /dev/null +++ b/.github/actions/setup-go/actions.yaml @@ -0,0 +1,27 @@ +name: 'Setup golang with master only caching' +description: 'A composite action that installs golang, but with a caching strategy that only updates the cache on master branch.' +runs: + using: 'composite' + steps: + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' # Just use whatever version is in the go.mod file + cache: ${{ github.ref == 'refs/heads/master' }} + + - name: Prepare for go cache + if: ${{ github.ref != 'refs/heads/master' }} + run: | + echo "GO_CACHE=$(go env GOCACHE)" | tee -a "$GITHUB_ENV" + echo "GO_MODCACHE=$(go env GOMODCACHE)" | tee -a "$GITHUB_ENV" + echo "GO_VERSION=$(go env GOVERSION | tr -d 'go')" | tee -a "$GITHUB_ENV" + + - name: Setup read-only cache + if: ${{ github.ref != 'refs/heads/master' }} + uses: actions/cache/restore@v4 + with: + path: | + ${{ env.GO_MODCACHE }} + ${{ env.GO_CACHE }} + key: setup-go-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('go.sum') }} + restore-keys: | + setup-go-${{ runner.os }}- \ No newline at end of file diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 383c53d6f819..db7a2ee10bdb 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -46,14 +46,7 @@ jobs: with: fetch-depth: 1 - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: '1.21.7' - check-latest: true - cache: true - cache-dependency-path: | - **/go.sum - **/go.mod + uses: .github/actions/setup-go - name: "Download k3s binary" uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/unitcoverage.yaml b/.github/workflows/unitcoverage.yaml index c4aaab6d70a8..3b085a79e0d0 100644 --- a/.github/workflows/unitcoverage.yaml +++ b/.github/workflows/unitcoverage.yaml @@ -36,10 +36,7 @@ jobs: with: fetch-depth: 1 - name: Install Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod # Just use whatever version is in the go.mod file - check-latest: true + uses: .github/actions/setup-go - name: Run Unit Tests run: | go test -coverpkg=./... -coverprofile=coverage.out ./pkg/... -run Unit diff --git a/.github/workflows/updatecli.yaml b/.github/workflows/updatecli.yaml index e3eee2675324..77c1b021fcf5 100644 --- a/.github/workflows/updatecli.yaml +++ b/.github/workflows/updatecli.yaml @@ -26,7 +26,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: 'stable' - + cache: false - 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