Repository navigation
Conversation
Reuse downloaded modules across Go versions, runner architectures, and runner images on the same OS instead of duplicating them in each build cache archive. Restore and save each entry independently, running operations in parallel when safe. Serialize restores for overlapping or aliased paths, preserve the original paths for the post step, and report cache-hit only when both entries match their primary keys. Update the documented manual restore keys and generated action bundles.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The split-cache behavior is consistently implemented, documented, bundled, and covered across success, failure, and concurrency scenarios.
Review effort: Balanced
Findings: None
What changed in this PR
Splits Go module and build caches to improve reuse while preserving build-cache isolation.
Changes:
- Adds independent cache keys, restore/save operations, and hit tracking.
- Safely parallelizes non-overlapping cache operations.
- Updates documentation, bundles, and comprehensive tests.
| File | Description |
|---|---|
src/package-managers.ts |
Associates cache paths with module/build kinds. |
src/constants.ts |
Stores cache entries in action state. |
src/cache-utils.ts |
Resolves paths and detects safe parallel restores. |
src/cache-save.ts |
Saves cache entries independently. |
src/cache-restore.ts |
Restores split caches and computes combined hit status. |
README.md |
Documents split-cache behavior. |
docs/advanced-usage.md |
Updates caching guidance and examples. |
action.yml |
Clarifies cache-hit semantics. |
dist/setup/index.js |
Updates the setup runtime bundle. |
dist/cache-save/index.js |
Updates the post-action runtime bundle. |
__tests__/cache-utils.test.ts |
Tests cache path identity and overlap detection. |
__tests__/cache-save.test.ts |
Tests independent and concurrent saves. |
__tests__/cache-restore.test.ts |
Tests split keys, restores, failures, and reuse. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dagood
left a comment
There was a problem hiding this comment.
Mainly doc comments. Looked through the src/ changes and only one thing jumped out at me.
|
|
||
| Both entries use the hash of `cache-dependency-path`, or the root `go.mod` by default. Adding source files or build settings to that input invalidates both entries when those files change. Custom cache locations and the cache service's normal access restrictions still apply. | ||
|
|
||
| Each entry is restored and saved independently, with concurrent transfers where safe. An exact hit is not uploaded again, even when the other entry misses. A failure for one entry does not prevent caching the other. The `cache-hit` output is `true` only when both entries are restored on their primary keys. |
There was a problem hiding this comment.
This doc only mentioned "primary" key once before this PR. (And it may have been a mistake to use that terminology, an implementation detail leaking into the doc?)
Now it's a bit more confusing, because "primary key" has been added a few more times, like this prominent case. I don't see anything about what a secondary key would potentially be, or any other reason to call it "primary".
This term was added to docs/advanced-usage.md, but also action.yml and README.md.
There was a problem hiding this comment.
Agreed: "primary" is cache-library terminology here, not a useful new user-facing concept. It means the key computed for the current run, as distinct from the key returned by the restore call. It does not mean that modules are the primary cache and build outputs are secondary, and setup-go does not supply a list of fallback restore keys.
The public contract is clearer as:
cache-hitistrueonly when both the module cache and the build cache are restored with exact matches for their cache keys. If only one matches, the output isfalse; that entry is still used and is not uploaded again.
That wording should be consistent across the README, action output description, and advanced usage. The sentence about a "non-primary key" can also be removed from the user documentation; it exposes the implementation rather than helping explain this feature. This wording cleanup is still outstanding in the current revision.
| return paths.every((parent, index) => | ||
| paths.every((child, otherIndex) => { |
There was a problem hiding this comment.
I'm not sure what the intent of this is, and it seems like it deserves justification in part because it appears to be N^2 on the number of paths involved....
There was a problem hiding this comment.
Yes, the pairwise check is O(N^2) in the number of cache roots. In the current Go configuration N is at most two: one module directory and one build directory, or just one if discovery of the other fails. There are therefore at most two non-self path comparisons; this does not walk the files inside either cache.
The purpose is to make the new concurrent restores safe when users customize GOMODCACHE and GOCACHE. They can point to the same directory or to ancestor/descendant directories, in which case two archive extractions could write to the same locations. Disjoint roots restore concurrently; overlapping roots restore sequentially.
The alias handling is deliberately conservative too: one archive can replace a symlink traversed by the other extraction, so checking only the final canonical destinations is insufficient. Missing cache directories are resolved through their existing ancestors, and aliases or unresolved paths fall back to sequential restores. The tests cover equal/nested paths in either order, case-insensitive paths, missing directories, symlink aliases, and resolution failures.
So this is a bounded safety check for splitting one restore into two, rather than a general-purpose many-path algorithm. If more cache roots were introduced, the pairwise approach would be worth revisiting.
There was a problem hiding this comment.
Seems worth documenting this intent in the code, so future revisions are more likely to in fact revisit this.
Co-authored-by: Davis Goodin <dagood@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore cache entries sequentially, keep saves parallel with per-entry error handling, and simplify the cache test setup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit aa2cac0. The split-cache implementation and sequential-restore simplifications are retained. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot rebase with main |
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Description:
Cache downloaded Go modules (
GOMODCACHE) separately from compiled build outputs (GOCACHE). The current combined archive stores another copy of the module sources for every Go version, runner architecture, and Linux runner image. Separating the entries lets those variants reuse one module archive on the same OS, subject to compatible cache paths, archive versions, and cache access scope. Build outputs keep their existing partitioning dimensions.Restore the entries sequentially and save them in parallel, so an exact module hit is not uploaded again when the build cache misses. Sequential restores avoid concurrent extraction into overlapping or aliased custom cache directories without path-overlap detection or filesystem-resolution helpers. Each operation still handles failures independently. Parallel saves use the Windows archive-read isolation fix already included by #794. No new inputs or automatic
GOOS/GOARCHkey dimensions are introduced.Implementation and test restructuring
cache-hitchange: the old hit test accepted any nonempty returned key. The replacement tests require exact matches for both cache entries; a single matching entry remains usable but does not make the overall outputtrue.Use cases that benefit
These reuse cases require an unchanged dependency-file hash and compatible cache paths/archive versions within an accessible cache scope:
Measured storage and upload savings
The seven-project hosted benchmark compared the combined action with an earlier revision of this PR on Windows using pinned project sources,
go mod download, andgo build. The two toolchains were Go 1.26.7 and 1.26.8, with automatic toolchain downloads disabled. All sizes below are compressed archives actually persisted by the GitHub cache service, not unpacked disk sizes. Hugo and Prometheus used bounded build-package selections; these are workload-specific results, not full release-build cache sizes.These measurements predate the sequential-restore simplification and have not been rerun for this revision. They describe the measured storage/upload savings of split archives, not the latency of the latest implementation.
Across these workloads, sharing modules avoided 1,385.69 MiB of retained storage across two Go versions and 1,386.13 MiB of upload traffic when populating the second version. The aggregate is weighted toward the dependency-heavy projects; sharing is repository/cache-scope-local, not global deduplication.
For N compatible variants, compressed module size M, and similarly sized compressed build archives B, the expected footprint changes from approximately N × (M + B) to M + N × B. Each additional variant therefore avoids another M bytes of module storage and, on an existing module hit, approximately M bytes of upload. Workflows with large dependency caches relative to their build caches benefit most. The measurements above cover a patch upgrade; architecture matrices, Linux-image changes, and matrices across different Go release lines were not measured.
Scope and trade-offs
Sequential restores: removing concurrency and path-overlap detection simplifies correctness for custom cache layouts, but restoring two hits may take longer than extracting both at once. The storage/upload benefits do not depend on concurrent restores; saves remain parallel.
One variant or both entries missing: there is essentially no compression-size gain. The combined and split totals differed by less than 0.11% in magnitude for each measured workload. Splitting reduces duplication across entries, not the size of their underlying contents.
Source-only changes with unchanged Go version and dependency hash: neither key changes, so both designs upload zero bytes on exact hits. This PR does not refresh the immutable remote build snapshot with newly compiled artifacts.
Source files or target settings included in
cache-dependency-path: both entries still use that same hash. A source/settings change invalidates the module entry too, so it does not retain module sharing across those revisions. Separate invalidation inputs and automatic cross-compilation target dimensions remain outside this PR.Two entries add cache lookups and metadata. There is no demonstrated reduction in download bytes for full hits, and module reuse on an otherwise cold key can increase GitHub cache egress while avoiding module-proxy downloads. Hosted latency was mixed; the storage/write savings do not imply universally faster workflows.
A shared immutable module snapshot may lack dependencies downloaded only by another variant; Go downloads missing modules, but exact hits do not merge later additions. Cold competing module writers still prepare archives before reservation.
Compatibility
setup-go-modules-andsetup-go-build-namespaces deliberately do not restore the old combined archives. Existing workflows need an initial refill; old and new entries can coexist until eviction.setup-goneed no input changes. Manualactions/cache/restoreintegrations must use two entries and the new keys; the documentation is updated accordingly.cache-hitistrueonly when both entries are restored with exact matches for their cache keys. One exact hit plus one miss reportsfalse, while the exact-hit entry remains usable and is not uploaded again.Validation
Local validation on Windows with the original dependency lockfile:
npm test- passed: 6 suites, 160 tests, including sequential restores, per-entry failure isolation, and concurrent saves.npm run build- passed: TypeScript compilation and both action bundles rebuilt.npm run lint- passed.npm run format-check- passed.git --no-pager diff HEAD --check- passed before committing.npm audit --audit-level=high --json- failed on pre-existing dependency findings in the branch's original lockfile. Dependency maintenance is intentionally outside this PR's scope.No dependency-manifest or license-record changes are included in this PR. Hosted CI results for the latest revision are not yet verified.
Related issue:
Related to #630.
Check list: