New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better GitHub CI caching strategy for golang #9495
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably stupid question: what is the benefit of doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at our Actions caches https://github.com/k3s-io/k3s/actions/caches, we keep going over our 10GB limit with a bunch of
setup-go-Linux-ubuntu22-go-1.21.7-bda3a8cce4ad2d34dfb706b901c4ce11eab6d77c2d08dd8f0eae8694a7a27733
caches. Alot of these are from PRs, whose caches are ONLY valid for the PR that opened them for security reasons (cache poisoning prevention).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to only allow
master
branch to Save a valid cache entry, because that cache is usable by all PRs, as along as the checksum is the same (ie no changes to go.mod).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Derek