Skip to content

Commit

Permalink
Better GitHub CI caching strategy for golang (k3s-io#9495)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <derek.nola@suse.com>
  • Loading branch information
dereknola authored Mar 1, 2024
1 parent 736fb2b commit 8f777d0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
27 changes: 27 additions & 0 deletions .github/actions/setup-go/actions.yaml
Original file line number Diff line number Diff line change
@@ -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 }}-
9 changes: 1 addition & 8 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/unitcoverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/updatecli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8f777d0

Please sign in to comment.