Skip to content

Commit 41d4237

Browse files
hjmjohnsonclaude
andcommitted
ENH: Optimize GitHub Actions ccache strategy with config-based keys
Improve the ccache caching strategy in pixi.yml and arm.yml: - Key cache on OS + build config + build-system file hashes rather than github.sha. This gives reuse when source files change but the toolchain/build-config is still compatible, which is exactly where ccache pays off. ccache itself handles source-level reuse. - Add tiered restore-keys fallback (OS+config → OS-only) so PR branches inherit the best available cache via GitHub's built-in branch scoping (PRs can read default branch caches) - Save cache on all branches (if: always()), not just main, so PR branches benefit from incremental caches across pushes - Bump cache key version to v3 to avoid restoring old caches - Remove CCACHE_NODIRECT=1 to enable direct mode for better hit rates (CCACHE_COMPILERCHECK=content already ensures correctness) - Increase CCACHE_MAXSIZE from 2.4G to 5G to leverage larger storage limits - Use separate restore/save actions to support saving even on build failure (if: always()) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d338c1f commit 41d4237

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

.github/workflows/arm.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ jobs:
9494
echo "CCACHE_BASEDIR=${GITHUB_WORKSPACE}" >> "$GITHUB_ENV"
9595
echo "CCACHE_COMPILERCHECK=content" >> "$GITHUB_ENV"
9696
echo "CCACHE_NOHASHDIR=true" >> "$GITHUB_ENV"
97-
echo "CCACHE_NODIRECT=1" >> "$GITHUB_ENV"
9897
echo "CCACHE_DIR=${{ runner.temp }}/ccache" >> "$GITHUB_ENV"
99-
echo "CCACHE_MAXSIZE=2.4G" >> "$GITHUB_ENV"
98+
echo "CCACHE_MAXSIZE=5G" >> "$GITHUB_ENV"
10099
if [ "$RUNNER_OS" == "Linux" ]; then
101100
sudo apt-get update -qq && sudo apt-get install -y ccache locales
102101
sudo locale-gen de_DE.UTF-8
@@ -109,7 +108,11 @@ jobs:
109108
uses: actions/cache/restore@v5
110109
with:
111110
path: ${{ runner.temp }}/ccache
112-
key: ccache-v1-${{ matrix.os }}-${{ matrix.name }}
111+
key: >-
112+
ccache-v3-${{ runner.os }}-${{ matrix.name }}-${{ hashFiles('CMakeLists.txt', 'cmake/**', '**/*.cmake', '**/pyproject.toml', '**/pixi.lock') }}
113+
restore-keys: |
114+
ccache-v3-${{ runner.os }}-${{ matrix.name }}-
115+
ccache-v3-${{ runner.os }}-
113116
114117
- name: Show ccache configuration, stats and maintenance
115118
shell: bash
@@ -170,11 +173,12 @@ jobs:
170173
env:
171174
CTEST_OUTPUT_ON_FAILURE: 1
172175
- name: Save compiler cache
173-
if: github.ref == 'refs/heads/main'
176+
if: always()
174177
uses: actions/cache/save@v5
175178
with:
176179
path: ${{ runner.temp }}/ccache
177-
key: ccache-v1-${{ matrix.os }}-${{ matrix.name }}
180+
key: >-
181+
ccache-v3-${{ runner.os }}-${{ matrix.name }}-${{ hashFiles('CMakeLists.txt', 'cmake/**', '**/*.cmake', '**/pyproject.toml', '**/pixi.lock') }}
178182
179183
- name: ccache stats
180184
if: always()

.github/workflows/pixi.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ jobs:
5353
echo "CCACHE_BASEDIR=${GITHUB_WORKSPACE}" >> "$GITHUB_ENV"
5454
echo "CCACHE_COMPILERCHECK=content" >> "$GITHUB_ENV"
5555
echo "CCACHE_NOHASHDIR=true" >> "$GITHUB_ENV"
56-
echo "CCACHE_NODIRECT=1" >> "$GITHUB_ENV"
5756
echo "CCACHE_DIR=${{ runner.temp }}/ccache" >> "$GITHUB_ENV"
58-
echo "CCACHE_MAXSIZE=2.4G" >> "$GITHUB_ENV"
57+
echo "CCACHE_MAXSIZE=5G" >> "$GITHUB_ENV"
5958
if [ "$RUNNER_OS" == "Linux" ]; then
6059
sudo apt-get update -qq && sudo apt-get install -y ccache locales
6160
sudo locale-gen de_DE.UTF-8
@@ -70,7 +69,11 @@ jobs:
7069
uses: actions/cache/restore@v5
7170
with:
7271
path: ${{ runner.temp }}/ccache
73-
key: ccache-v1-${{ matrix.os }}-pixi-cxx
72+
key: >-
73+
ccache-v3-${{ runner.os }}-pixi-cxx-${{ hashFiles('CMakeLists.txt', 'cmake/**', '**/*.cmake', '**/pyproject.toml', '**/pixi.lock') }}
74+
restore-keys: |
75+
ccache-v3-${{ runner.os }}-pixi-cxx-
76+
ccache-v3-${{ runner.os }}-
7477
7578
- name: Show ccache configuration, stats and maintenance
7679
shell: bash
@@ -150,11 +153,12 @@ jobs:
150153
echo "****** df -h /"
151154
df -h /
152155
- name: Save compiler cache
153-
if: github.ref == 'refs/heads/main'
156+
if: always()
154157
uses: actions/cache/save@v5
155158
with:
156159
path: ${{ runner.temp }}/ccache
157-
key: ccache-v1-${{ matrix.os }}-pixi-cxx
160+
key: >-
161+
ccache-v3-${{ runner.os }}-pixi-cxx-${{ hashFiles('CMakeLists.txt', 'cmake/**', '**/*.cmake', '**/pyproject.toml', '**/pixi.lock') }}
158162
159163
- name: ccache stats
160164
if: always()

0 commit comments

Comments
 (0)