Skip to content

ENH: Simplify ccache key in Build.yml GHA workflow - #2573

Merged
blowekamp merged 1 commit into
SimpleITK:mainfrom
blowekamp:GHA-simplify-ccache-key
Apr 29, 2026
Merged

blowekamp merged 1 commit into
SimpleITK:mainfrom
blowekamp:GHA-simplify-ccache-key

Conversation

@blowekamp

Copy link
Copy Markdown
Member

Summary

The ccache key and restore-keys were encoding branch names (github.head_ref, github.base_ref, github.ref_name) to try to create a branch-preference fallback order. This is unnecessary.

GHA cache scoping already handles this natively: restore-keys are searched on the current branch first, then the default branch (main), and for PRs also the base branch. A PR therefore naturally falls back to the latest main ccache via the simple prefix ccache-v1-{name}-, with no branch names needed in the key.

Change

# Before
key: ccache-v1-${{ matrix.name }}-${{ github.head_ref && format('{0}-{1}', github.base_ref, github.head_ref) || github.ref_name }}-${{ github.sha }}
restore-keys: |
  ccache-v1-${{ matrix.name }}-${{ github.head_ref && format('{0}-{1}', github.base_ref, github.head_ref) || github.ref_name }}-
  ccache-v1-${{ matrix.name }}-${{ github.head_ref && github.base_ref || github.ref_name }}-
  ccache-v1-${{ matrix.name }}-

# After
key: ccache-v1-${{ matrix.name }}-${{ github.sha }}
restore-keys: |
  ccache-v1-${{ matrix.name }}-

The branch-name embedding in the cache key was redundant.
GHA cache scoping already searches the current branch first,
then falls back to the default branch (main), so a PR naturally
restores the latest main ccache via the prefix restore-key
without needing branch names encoded in the key string.
@blowekamp
blowekamp marked this pull request as ready for review April 29, 2026 15:40
@blowekamp
blowekamp requested a review from zivy April 29, 2026 15:40
@blowekamp
blowekamp merged commit 5f9bd87 into SimpleITK:main Apr 29, 2026
9 of 10 checks passed
@blowekamp
blowekamp deleted the GHA-simplify-ccache-key branch September 9, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants