-
-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Description
Summary
The cache-homebrew-prefix action caches the entire $(brew --prefix) directory, which on Linux includes the Homebrew/ subdirectory containing the Homebrew source code (git repository). When the cache is restored during a Homebrew/brew PR CI run, it overwrites the PR's code changes that were previously checked out by setup-homebrew.
Steps to reproduce
- Open a PR on
Homebrew/brewthat modifies existing Ruby source files (e.g.,Library/Homebrew/keg.rb) - CI runs the
syntaxjob, which usescache-homebrew-prefixto installshellcheckandshfmt - The
syntaxjob fails becausebrew typecheckruns against stale (cached) source code instead of the PR's code
Root cause
In the syntax job of .github/workflows/tests.yml, the step order is:
setup-homebrew: Fetches the PR's SHA and doesgit checkout --force -B main FETCH_HEADin$HOMEBREW_REPOSITORY(/home/linuxbrew/.linuxbrew/Homebrew)cache-homebrew-prefix: Restores a cached tarball of the entire/home/linuxbrew/.linuxbrewdirectory, overwriting the files checked out in step 1brew typecheck: Runs Sorbet against the now-stale source code
The cache key is based on installed formula versions (shellcheck/shfmt), not on source code, so the same stale cache is restored on every run.
Example
PR Homebrew/brew#21594 has the correct code in its merge ref (refs/pull/21594/merge), verified via:
git fetch upstream refs/pull/21594/merge
git show FETCH_HEAD:Library/Homebrew/keg.rb | sed -n '318p'
# Output: LinkageCacheStore.new(path.to_s, db).delete!But CI reports:
keg.rb:318: Expected `String` but found `Pathname` for argument `keg_path`
318 | LinkageCacheStore.new(path, db).delete!
The old code (path instead of path.to_s) comes from the cached prefix.
Possible fixes
- Exclude
Homebrew/from the cache: Change the cached path to exclude the source code directory, or cache individual subdirectories (Cellar/,bin/,opt/,lib/) instead of the entire prefix - Restore git state after cache: Add a
git checkout -fstep in$HOMEBREW_REPOSITORYafter cache restoration - Scope cache to non-source paths: Use multiple
pathentries that avoid the git repository
Environment
- Introduced by: Use Homebrew/actions/cache-homebrew-prefix@main in workflows brew#21565
- Platform: Linux (Ubuntu 24.04, x86_64)
- Cache key pattern:
homebrew-prefix-ubuntu-24.04-x86_64-{hash}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels