Skip to content

Commit c4f2da4

Browse files
Copilotmattleibow
andauthored
[copilot] Add externals directory caching (#1225)
## Summary This PR adds caching for the `./externals` directory in the `copilot-setup-steps.yml` workflow to improve build performance by avoiding redundant Maven artifact downloads. ## Problem The `dotnet cake` build process downloads hundreds of Maven artifacts (AndroidX, Google Play Services, Firebase, etc.) to the `./externals` directory during the binderator step. Without caching, these artifacts are re-downloaded on every workflow run, significantly increasing build time and network usage. ## Solution Added explicit cache management using GitHub Actions cache: - **Cache Key**: Based on `config.json` content hash (`externals-${{ hashFiles('config.json') }}`) - **Cache Path**: `./externals` directory - **Strategy**: Restore before `dotnet cake`, save after (only on cache miss) ## Implementation Details ```yaml # Restore cache before build - name: Restore externals cache uses: actions/cache/restore@v4 with: path: ./externals key: externals-${{ hashFiles('config.json') }} # Save cache after successful artifact download (only if cache miss) - name: Save externals cache uses: actions/cache/save@v4 if: steps.cache-externals-restore.outputs.cache-hit != 'true' with: path: ./externals key: externals-${{ hashFiles('config.json') }} ``` ## Benefits - **Faster builds**: Eliminates re-downloading of Maven artifacts when `config.json` hasn't changed - **Reduced network usage**: Avoids unnecessary downloads of hundreds of Android library artifacts - **Improved developer experience**: Faster feedback for workflow runs - **Cost efficiency**: Reduces GitHub Actions compute time ## Cache Invalidation The cache automatically invalidates when: - `config.json` content changes (new/updated Maven artifacts) - Manual cache clearing through GitHub UI - 7-day GitHub Actions cache expiration This ensures builds always use the correct artifacts while maximizing cache efficiency. Co-authored-by: mattleibow <[email protected]>
1 parent a382db9 commit c4f2da4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

.github/workflows/copilot-setup-steps.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,31 @@ jobs:
2727
- name: Restore dotnet tools
2828
run: dotnet tool restore
2929

30+
# Cache the externals directory based on config.json content
31+
# This caches the Maven artifacts downloaded by the binderator tool
32+
# to avoid re-downloading the same artifacts on subsequent runs
33+
- name: Restore externals cache
34+
id: cache-externals-restore
35+
uses: actions/cache/restore@v4
36+
with:
37+
path: ./externals
38+
key: externals-${{ hashFiles('config.json') }}
39+
3040
- name: Run dotnet cake
3141
run: dotnet cake
3242
continue-on-error: true
3343

44+
# Save the externals cache after dotnet cake runs
45+
# This ensures the cache reflects the original config.json state
46+
# before any potential modifications by the build process
47+
- name: Save externals cache
48+
id: cache-externals-save
49+
uses: actions/cache/save@v4
50+
if: steps.cache-externals-restore.outputs.cache-hit != 'true'
51+
with:
52+
path: ./externals
53+
key: externals-${{ hashFiles('config.json') }}
54+
3455
- name: Display environment info
3556
run: |
3657
echo "=== Environment Summary ==="

0 commit comments

Comments
 (0)