Skip to content
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

fix: PR cache fallback to master/main branch's cache #573

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ runs:
with:
go-version: ${{ inputs.go-version }}
check-latest: ${{ inputs.check-latest }}
cache: false # cache is handled by separate actions/cache step.
cache: false # cache is handled by separate actions/cache step, see https://github.com/actions/setup-go/issues/358

# NOTE: cache key and restore key is not the same;
# We want to always re-use the cache created by master in all our PRs. We also want any PR which modifies go.sum to create a new cache for itself.
# Therefore the cache key is set to use GITHUB_REF_NAME and the restore key is set to use GITHUB_BASE_REF.
# For more details, see https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
# NOTE: you need to build on push to master and on pull request in the repos which uses this reusable workflow.
- name: Set up cache
if: ${{ inputs.disableCache != 'true' }}
uses: actions/cache@v4
Expand All @@ -53,10 +58,6 @@ runs:
/home/runner/.cache/go-build
/home/runner/go/pkg/mod
/home/runner/go/bin
key: ${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-${{ github.ref_name }}-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-
${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-
${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-
${{ runner.os }}-sage-${{ github.workflow }}-
${{ runner.os }}-sage-
${{ runner.os }}-${{ github.base_ref }}-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}