fix(system): ignore already_exists when saving to GitHub Actions cache - #1302
Open
Soner (shyim) wants to merge 1 commit into
Open
fix(system): ignore already_exists when saving to GitHub Actions cache#1302Soner (shyim) wants to merge 1 commit into
Soner (shyim) wants to merge 1 commit into
Conversation
The GitHub Actions cache v2 API returns `already_exists` when an entry for
a key has already been uploaded. Since the asset cache key is deterministic
(`sw-cli-<shopware-version>-<content-hash>`), this happens on re-runs of the
same commit and when concurrent jobs build the same extension.
`go-actions-cache` maps that response to an error matching `os.ErrExist`,
but both save paths wrapped every error unconditionally, so a benign
"already cached" response propagated up and failed the whole command:
ERROR building assets: failed to save folder to GitHub Actions cache: already_exists
The store happens after the assets are already built, so this aborted
builds that had completed their actual work.
Treat `os.ErrExist` as success in `Set` and `StoreFolderCache`, matching
the idiom the upstream library uses internally.
To make this testable, the client field is now a small `actionsCacheClient`
interface covering the two methods used, which `*actionscache.Cache`
satisfies as-is, so there is no production behaviour change.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1302 +/- ##
==========================================
+ Coverage 54.00% 54.20% +0.19%
==========================================
Files 303 303
Lines 23453 23457 +4
==========================================
+ Hits 12666 12715 +49
+ Misses 10759 10714 -45
Partials 28 28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Builds using the GitHub Actions cache can fail with:
Real-world occurrence: FriendsOfShopware/FroshAdminDashboard run #30348425342, where
shopware-cli extension zipexited 1 and took down the whole e2e job.Cause
The GH Actions cache v2 API returns
already_existswhen an entry for a key has already been uploaded. The asset cache key is deterministic —sw-cli-<shopware-version>-<content-hash>— so this is hit whenever the same commit is re-run, or two jobs build the same extension concurrently.go-actions-cachemaps that response to an error matchingos.ErrExist, butSetandStoreFolderCachewrapped everySaveerror unconditionally. A benign "this is already cached" response therefore propagated up throughstoreAssetCache→building assetsand failed the command.Worth noting: the cache store runs after the assets are already built successfully, so this aborted builds that had completed all their real work.
Fix
Treat
os.ErrExistas success in both save paths, matching the idiom the upstream library already uses internally (cache.go:451).To make this testable, the
clientfield becomes a smallactionsCacheClientinterface covering the two methods used.*actionscache.Cachesatisfies it as-is, soNewGitHubActionsCacheis unchanged and there is no production behaviour change.Tests
Four new cases in
internal/system/cache_github_actions_test.go, using a fake client that returns the exact error shape the library builds from a v2already_existsresponse (HTTPError{409, GithubAPIError{TypeKey: "ArtifactCacheItemAlreadyExistsException"}}):SetIgnoresAlreadyExistsSetswallows already-existsSetReturnsOtherErrorsSetstill propagates real failuresStoreFolderCacheIgnoresAlreadyExistsStoreFolderCacheReturnsOtherErrorsThe negative cases pin down that the guard is narrow and genuine cache failures still fail the build.
Verified the tests actually catch the regression: with the
errors.Isguards temporarily removed, both positive tests fail with the same message as the CI log, while the two negative tests keep passing.go build ./..., the fullgo test ./...suite, andgolangci-lint run ./internal/system/...(0 issues) all pass.🤖 Generated with Claude Code