Skip to content

fix(cache): resolve pub cache path from PUB_CACHE for cross-OS runners - #2

Merged
Project516 merged 2 commits into
Project516:mainfrom
cappy-dev:fix/cache-pub-cache-path
Aug 3, 2026
Merged

fix(cache): resolve pub cache path from PUB_CACHE for cross-OS runners#2
Project516 merged 2 commits into
Project516:mainfrom
cappy-dev:fix/cache-pub-cache-path

Conversation

@cappy-dev

@cappy-dev cappy-dev commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

On behalf of @Project516

Problem

The Cache pub step hardcoded path: ~/.pub-cache:

- name: Cache pub
  uses: actions/cache@v6
  with:
    path: ~/.pub-cache
    key: ${{ runner.os }}-pub-${{ hashFiles('pubspec.lock') }}

The cache key branches on ${{ runner.os }}, so the step is clearly meant to run on more than one runner OS. But Flutter does not write its packages to ~/.pub-cache on Windows. On a windows-latest job, flutter pub get populates %LOCALAPPDATA%\Pub\Cache, so this step was saving and restoring a directory Flutter never touches. The pub restore was a no-op there every run, and a stale ~/.pub-cache snapshot kept getting written back into the cache.

Fix

subosito/flutter-action@v2 already exports PUB_CACHE to the job environment, pointing at the directory flutter pub get actually populates on the current runner:

  • Linux and macOS: ~/pub-cache (that is, $HOME/.pub-cache)
  • Windows: %LOCALAPPDATA%\Pub\Cache

This change caches that path directly:

path: ${{ env.PUB_CACHE }}

Because env vars written to GITHUB_ENV by a prior step are available to later steps in the same job, the Install Flutter step's PUB_CACHE is already set by the time Cache pub evaluates its path.

Behavior

  • Linux / macOS: PUB_CACHE equals ~/.pub-cache, so this is a no-op there.
  • Windows: the step now caches the directory Flutter actually uses, instead of a phantom ~/.pub-cache, so the pub restore starts hitting on windows-latest.

Verification

  • action.yml parses as valid YAML (yaml.safe_load).
  • No em dashes used anywhere in the diff or this body.
  • One commit, authored as cappy-dev <cappy-dev@users.noreply.github.com>.

Summary by CodeRabbit

  • New Features

    • Improved Flutter package caching across runner operating systems by using the configured pub cache location.
  • Documentation

    • Added guidance on platform-specific pub cache paths.
    • Clarified that cache keys should remain OS-specific to prevent incompatible cache reuse.

The Cache pub step hardcoded ~/.pub-cache, which is the right directory on
Linux and macOS but not on Windows runners, where Flutter writes pub
packages to %LOCALAPPDATA%\Pub\Cache. The cache key is keyed on runner.os,
so the step was cross-OS in intent but cached a directory Flutter never
touches on Windows, meaning windows-latest jobs silently missed the pub
cache every time.

subosito/flutter-action@v2 already exports PUB_CACHE to the job environment
pointing at the directory flutter pub get populates on the current runner
(~/.pub-cache on Linux/macOS, the LOCALAPPDATA Pub Cache on Windows). Cache
that path directly via ${{ env.PUB_CACHE }}. On Linux and macOS this is
identical to ~/.pub-cache, so behavior is unchanged there; on Windows it now
caches the directory flutter pub get actually uses.

On behalf of @Project516
@cappy-dev

Copy link
Copy Markdown
Contributor Author

cc @Project516

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b4198d70-f45a-418e-8d12-55e5b059dbc1

📥 Commits

Reviewing files that changed from the base of the PR and between 20a31f9 and 15f445c.

📒 Files selected for processing (2)
  • README.md
  • action.yml

📝 Walkthrough

Walkthrough

The action now uses PUB_CACHE for Flutter pub caching. The README documents platform-specific cache paths and OS-specific cache keys.

Changes

Pub cache configuration

Layer / File(s) Summary
Resolve and document the pub cache
action.yml, README.md
action.yml uses ${{ env.PUB_CACHE }} instead of ~/.pub-cache. README.md documents platform-specific paths and cache keys.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit with cache to share,
PUB_CACHE finds it everywhere.
Linux, macOS, Windows agree,
OS-specific keys keep builds tidy.
A hop, a key, a cache in place—
Pub dependencies leave no trace.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main cache path change for cross-OS runners.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@action.yml`:
- Line 33: Correct the documented Linux/macOS pub cache path from ~/pub-cache to
~/.pub-cache in action.yml lines 33-33 and README.md lines 44-44; update both
descriptions consistently without changing surrounding content.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8caa2330-cdfc-4829-8e22-df89abea30ec

📥 Commits

Reviewing files that changed from the base of the PR and between 4998a3d and 20a31f9.

📒 Files selected for processing (2)
  • README.md
  • action.yml

Comment thread action.yml Outdated
Flutter's default PUB_CACHE on Linux and macOS is ~/.pub-cache, not
~/pub-cache. Fix both descriptions to match. Addresses CodeRabbit
review feedback.

@Project516 Project516 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the finding against current code — still valid. Flutter's default PUB_CACHE on Linux/macOS is ~/.pub-cache, not ~/pub-cache; both action.yml and README.md had it wrong. Fixed both descriptions consistently (commit 15f445c). YAML re-validated with yaml.safe_load. Docstring coverage is not applicable — changed files are YAML and README, no functions.

@Project516
Project516 merged commit 723a637 into Project516:main Aug 3, 2026
1 check passed
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