Skip to content

Commit

Permalink
fix: cache from branch, fallback to target branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Aug 20, 2024
1 parent f12499f commit 2971c8b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ runs:
check-latest: ${{ inputs.check-latest }}
cache: false # cache is handled by separate actions/cache step, see https://github.com/actions/setup-go/issues/358

- name: Generate cache key
id: cache-key
shell: bash
run: |
echo "restore_key=${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}-default" >> $GITHUB_OUTPUT
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
echo "cache_key=${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}-default" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "cache_key=${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}-PR" >> $GITHUB_OUTPUT
else
echo "cache_key=${{ runner.os }}-sage-${{ github.workflow }}-${{ github.job }}-${{ inputs.cacheKey }}-${{ inputs.go-version }}-${{ hashFiles('**/go.sum') }}" >> $GITHUB_OUTPUT
fi
- name: Set up cache
if: ${{ inputs.disableCache != 'true' }}
uses: actions/cache@v4
Expand All @@ -53,10 +68,7 @@ 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: ${{ steps.cache-key.outputs.cache_key }}
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-
${{ steps.cache-key.outputs.restore_key }}

0 comments on commit 2971c8b

Please sign in to comment.