Save/Restore seperately in MacOS/Windows caching workflows. - #11199
Conversation
Only *save* cache on the default branch (develop), restore it everywhere it fits
📝 WalkthroughWalkthroughUpdates macOS and Windows CI cache handling to separate restore and save operations, restricts cache writes to default-branch pushes, and pins the Emscripten setup action used by the PortDuino WASM build. ChangesCI workflow maintenance
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⚡ Try this PR in the Web FlasherNote Building this pull request… the flash button, badges and supported-board |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/build_windows_bin.yml:
- Around line 17-20: Gate the built-in caches of msys2/setup-msys2@v2 and
actions/setup-python@v6 using the existing SAVE_CACHE policy, preventing cache
saves on PR and merge_group runs. Configure both steps with caching disabled or
replace them with explicit restore and conditionally gated save steps, while
preserving dependency installation behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 63414347-1cb8-4517-8bc5-7a4bcfbfc6d3
📒 Files selected for processing (3)
.github/workflows/build_macos_bin.yml.github/workflows/build_portduino_wasm.yml.github/workflows/build_windows_bin.yml
| # Only pushes to the default branch (develop) populate the cache; PR / merge_group runs | ||
| # restore it but never save, so they stop filling up the repo's Actions cache storage. | ||
| env: | ||
| SAVE_CACHE: ${{ github.event_name == 'push' && github.ref_name == github.event.repository.default_branch }} |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== workflow file =="
if [ -f .github/workflows/build_windows_bin.yml ]; then
nl -ba .github/workflows/build_windows_bin.yml | sed -n '1,140p'
else
echo "missing .github/workflows/build_windows_bin.yml"
fi
echo
echo "== relevant workflow references =="
rg -n "SAVE_CACHE|msys2/setup-msys2|setup-python|cache:|platformio ci|restore|save" .github/workflows/build_windows_bin.yml .github/workflows 2>/dev/null || true
echo
echo "== changed files/stat =="
git diff --stat HEAD~1..HEAD 2>/dev/null || git diff --stat 2>/dev/null || trueRepository: meshtastic/firmware
Length of output: 217
🌐 Web query:
msys2/setup-msys2 v2 cache true restore-only-save-cache branch PR documentation
💡 Result:
The msys2/setup-msys2 action does not provide a specific restore-only-save-cache parameter or feature. The official cache option accepts a boolean value (true or false) [1][2][3], where true (the default) automatically handles both restoring and saving the package cache during workflow runs [1][4][5]. Research into the action's development history reveals the following context regarding caching behavior: 1. Automatic Management: The action was designed to manage caching automatically to avoid complexity for users [6]. It implements internal logic to determine when to restore, prune, and save caches based on environment configuration and package changes [4][7]. 2. Alternative Approaches: There is no documented native parameter to restrict the action to "restore-only" behavior. Previous discussions regarding granular cache control (such as separating restore and save phases) have generally been addressed by the maintainers through the current automated system [4][8][6]. 3. Current Implementation: The action uses GitHub Actions caching to store and retrieve packages [7][3]. If you require specific cache behavior not supported by the action, users typically manage this by setting cache: false and implementing custom cache steps using the official actions/cache action [1][8]. If you are looking for this feature due to issues with cache size or race conditions, note that the action includes built-in safeguards, such as pruning caches before saving and avoiding redundant saves if the cache has not changed [4][7].
Citations:
- 1: https://github.com/msys2/setup-msys2/blob/main/README.md
- 2: https://github.com/msys2/setup-msys2
- 3: https://deepwiki.com/msys2/setup-msys2/2.2-configuration-options
- 4: Rework pacman pkg cache and enable by default msys2/setup-msys2#51
- 5: https://github.com/marketplace/actions/setup-msys2
- 6: Provide a way to cache the installation msys2/setup-msys2#50
- 7: https://deepwiki.com/msys2/setup-msys2/3.2-caching-system
- 8: Save package cache as a post build step msys2/setup-msys2#92
🌐 Web query:
actions/setup-python v6 cache pip restore-default branch PR documentation
💡 Result:
The actions/setup-python action (v6+) provides built-in dependency caching for pip, pipenv, and poetry [1][2]. By default, this action uses the hash of your dependency file (e.g., requirements.txt or pyproject.toml) to create a unique cache key [1][2]. When a workflow runs, the action searches for a cache match based on this key [3]. If an exact match is not found, it can fall back to partial matches using restore keys if they were configured [3][4]. Regarding your specific interest in "restore-default" branch behavior or PR-related caching: 1. Cache Scope and PRs: Caches are scoped by the branch and the repository [3]. For pull requests, the action attempts to restore the cache from the current branch. If no cache is found for the feature branch, GitHub Actions automatically falls back to searching for a cache from the base branch (e.g., main or master) [3]. This ensures that PRs can benefit from existing dependencies installed on the default branch without needing to build from scratch. 2. Read-Only Cache Mode: To prevent issues like "cache poisoning" (where an untrusted PR might upload malicious packages to the cache), you can use the cache-write input [5]. By setting cache-write to false (e.g., cache-write: ${{ github.event_name != 'pull_request' }}), you can allow PRs to restore existing caches in read-only mode while preventing them from writing new cache entries [5]. 3. Advanced Configuration: You can use cache-dependency-path if you need to point to specific dependency files, including multiple files or wildcard patterns, especially if they are located outside the workspace root [1][6][7]. In summary, the "restore" logic for branches happens automatically: the runner looks for a cache on the current branch first, and if that fails, it looks for one on the parent/default branch [3]. You do not need to manually configure "restore-default" branch logic, as this is standard behavior of the underlying GitHub Actions cache service [3].
Citations:
- 1: https://github.com/actions/setup-python?tab=readme-ov-file
- 2: https://github.com/actions/setup-python/blob/main/README.md
- 3: https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching
- 4: https://github.com/actions/cache/blob/main/restore/README.md
- 5: Add cache-write input for read-only cache mode actions/setup-python#1284
- 6: https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md
- 7: Enhance cache-dependency-path handling to support files outside the workspace root actions/setup-python#1128
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== workflow file =="
if [ -f .github/workflows/build_windows_bin.yml ]; then
awk '{printf "%4d\t%s\n", NR, $0}' .github/workflows/build_windows_bin.yml | sed -n '1,140p'
else
echo "missing .github/workflows/build_windows_bin.yml"
fi
echo
echo "== relevant workflow references =="
rg -n "SAVE_CACHE|msys2/setup-msys2|setup-python|cache:|platformio ci|restore|save" .github/workflows/build_windows_bin.yml .github/workflows 2>/dev/null || true
echo
echo "== changed files/stat =="
git diff --stat HEAD~1..HEAD 2>/dev/null || git diff --stat 2>/dev/null || trueRepository: meshtastic/firmware
Length of output: 10184
Gate the built-in dependency caches too.
SAVE_CACHE only skips the PlatformIO save step, but this workflow still allows msys2/setup-msys2@v2 with cache: true and actions/setup-python@v6 with cache: pip to save caches on PR/merge_group runs. That contradicts the comment policy; use cache: false or explicit actions/cache/restore + gated actions/cache/save steps for both package managers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/build_windows_bin.yml around lines 17 - 20, Gate the
built-in caches of msys2/setup-msys2@v2 and actions/setup-python@v6 using the
existing SAVE_CACHE policy, preventing cache saves on PR and merge_group runs.
Configure both steps with caching disabled or replace them with explicit restore
and conditionally gated save steps, while preserving dependency installation
behavior.
Only save cache on the default branch (develop), restore it everywhere it fits
Summary by CodeRabbit