Commit Graph
107 Commits
Author SHA1 Message Date
Philip GaiandCopilot Autofix powered by AI 8d05a01e45 feat(cache): add cache-mode client behavior (read-denied warning + ACTIONS_CACHE_MODE skip) (#2447)
* feat(cache): surface cache read-denied as a distinct restore warning

Mirror the existing cache write-denied handling on the restore path. When
the receiver refuses a download URL because the run's token has no readable
cache scopes, it returns a twirp PermissionDenied (HTTP 403). The twirp
client wraps that 403 in a generic Error, so the stable 'cache read denied:'
prefix is embedded in the message rather than at the start.

- Add CACHE_READ_DENIED_PREFIX and CacheReadDeniedError
- Dispatch on the prefix in the restoreCacheV2 catch block (V2 only), log a
  policy-specific warning, and report a cache miss so the run continues
- Add a test mirroring the write-denied coverage

* chore(cache): trim comments, bump to 6.2.0, add RELEASES entry

* refactor(cache): dispatch read-denied by error name to mirror write path

Re-throw CacheReadDeniedError from an inner try/catch around
GetCacheEntryDownloadURL and dispatch on typedError.name in the outer catch,
matching how saveCacheV2 handles CacheWriteDeniedError.

* feat(cache): handle read-denied on the v1 restore path

Extend the read-denied handling to Cache Service v1 so GHES (which forces v1
via _apis/artifactcache) is covered when read-scope enforcement ships there.

- Surface the receiver's error body message from getCacheEntry instead of a
  generic status-code error, so the cache read denied: prefix reaches callers
- Re-throw CacheReadDeniedError from restoreCacheV1 and dispatch on it in the
  outer catch, mirroring restoreCacheV2 and the write-denied v1 handling
- Add a v1 read-denied test

* refactor(cache): only surface receiver body for read-denied on v1

* test(cache): assert getCacheEntry only surfaces body for read-denied

* test(cache): cover non-read-denied getCacheEntry passthrough on v1

* refactor(cache): share read-denied prefix via constants to avoid drift

* feat(cache): skip restore/save per ACTIONS_CACHE_MODE

* test(cache): expand ACTIONS_CACHE_MODE skip coverage across v1/v2 and unknown modes

* fix copilot pr feedback

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* docs(cache): remove internal reference from cache-mode comment

* test(cache): merge redundant cache-mode skip tests and simplify read-denied handling

Address PR review feedback:
- Merge the duplicate restore/save skip test.each blocks into single blocks parametrized over ACTIONS_CACHE_SERVICE_V2.
- Drop the redundant CacheReadDeniedError catch arms; the typed error is not an HttpClientError so it already falls through to a non-fatal warning.
- Clarify why read-denied classification happens both in getCacheEntry and cache.ts (dependency-free internal module cannot import the typed error).

* refactor(cache): drop redundant CacheWriteDeniedError catch arms

Mirror the read-denied simplification on the save path. CacheWriteDeniedError
is not an HttpClientError and its name does not match the ReserveCacheError
arm, so it falls through to the same non-fatal warning. Logging behavior is
unchanged (warns, never fails the run) and the exported type is still thrown
internally for consumers and tests. Also refresh stale doc wording.

* test(cache): collapse redundant restore getCacheEntry-failure tests

The two restoreCache tests exercised the identical warning + cache-miss path
now that read-denied is no longer reclassified in the catch, so merge them into
one. The read-denied prefix detection that actually branches on the message is
covered by getCacheEntry tests in cacheHttpClient.test.ts.

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-13 10:03:16 -05:00
Jason Ginchereau 66801604fb Adit fix, address copilot comments 2026-06-11 17:17:55 -07:00
Jason Ginchereau c99fedd87a Handle cache write error due to read-only token 2026-06-11 17:02:12 -07:00
Daniel Kennedy f0055b449b @actions/cache: convert to an ESM module (#2275)
* `@actions/cache`: convert to an ESM module

* Update the fixture to ESM syntax

* Update the cache workflows

* Bump `@actions/glob` to `0.6.1`

* Fix awaiting in the cache unit tests

* Fix a type issues in contracts

* Export the `DownloadOptions`/`UploadOptions` like before

* More cache test fixes

* Make the cache units tests better

* Add some more logging

* Add retries to restore-cache.mjs
2026-01-29 14:23:32 -05:00
Ryan Ghadimi 395e6a7175 new error state, tests to cover 2025-08-13 13:00:46 +00:00
Ryan Ghadimi 6767cb420a remove cache size limit 2025-08-13 10:14:18 +00:00
Bassem Dghaidi 23733c502e Merge pull request #2100 from actions/copilot/fix-2099
Improve cache service availability determination and implement conditional error logging
2025-07-28 16:49:10 +02:00
copilot-swe-agent[bot]andLink- 780c52920e Fix v1 cache service to only check ACTIONS_CACHE_URL
Co-authored-by: Link- <568794+Link-@users.noreply.github.com>
2025-07-14 13:39:13 +00:00
copilot-swe-agent[bot]andLink- a5f3dac9b5 Remove logCacheError function and implement inline 5xx error detection as requested
Co-authored-by: Link- <568794+Link-@users.noreply.github.com>
2025-07-14 12:42:37 +00:00
copilot-swe-agent[bot]andLink- 768c09e245 Implement 5xx server error detection and fix most cache tests
Co-authored-by: Link- <568794+Link-@users.noreply.github.com>
2025-07-14 12:23:44 +00:00
copilot-swe-agent[bot]andLink- 0632db1508 Update tests to expect warnings instead of errors for non-5xx cache failures
Co-authored-by: Link- <568794+Link-@users.noreply.github.com>
2025-07-14 12:07:37 +00:00
Bassem Dghaidi 355b96f648 Fix linting issues 2025-07-14 03:49:28 -07:00
Bassem Dghaidi 50df04cfa4 Fix logging of cache key and restore key matches 2025-07-14 03:45:17 -07:00
copilot-swe-agent[bot]andLink- 6c9465b976 Improve cache service availability determination and change warnings to errors
- Update isFeatureAvailable() to leverage ACTIONS_CACHE_SERVICE_V2 feature flag
- For v2: check ACTIONS_RESULTS_URL availability
- For v1: check either ACTIONS_CACHE_URL or ACTIONS_RESULTS_URL availability
- Change warning logs to error logs for cache failures
- Add comprehensive tests covering all scenarios

Co-authored-by: Link- <568794+Link-@users.noreply.github.com>
2025-07-14 10:32:34 +00:00
Art Leo 54ac8fc2b0 Log cache version requested 2025-03-15 10:13:43 +11:00
Rob Herley c6b0a26648 cache: wrap create failures in ReserveCacheError 2025-02-25 12:49:08 -05:00
Rob Herley 3259ff2c2f cache miss as debug, not warning annotation 2025-02-14 09:28:01 -05:00
Bassem Dghaidi 61623c2e2b Minor comment adjustments 2024-12-02 11:10:25 -08:00
Bassem Dghaidi 00ba0e14b3 Minor comment adjustments 2024-12-02 10:55:33 -08:00
Bassem Dghaidi d779b4bc2a Merge branch 'enhance-blob-client' of github.com:actions/toolkit into enhance-blob-client 2024-12-02 10:55:00 -08:00
Bassem Dghaidi 4cde3217d2 Minor comment adjustments 2024-12-02 10:53:29 -08:00
Bassem DghaidiandJosh Gross f3451f4e32 Fix comments
Co-authored-by: Josh Gross <joshmgross@github.com>
2024-12-02 19:46:18 +01:00
Bassem DghaidiandJosh Gross a38b7c8c85 Fix comments
Co-authored-by: Josh Gross <joshmgross@github.com>
2024-12-02 19:46:11 +01:00
Bassem Dghaidi e93d126075 Minor refactoring 2024-12-02 04:08:21 -08:00
Bassem Dghaidi dd7886c186 Fix upload progress bug 2024-12-02 03:55:57 -08:00
Bassem Dghaidi f51d6a5578 Troubleshoot 2024-12-02 03:35:20 -08:00
Bassem Dghaidi b1ea5b92cd Fix tests 2024-11-29 07:36:51 -08:00
Bassem Dghaidi dc9b9ba34f Fine tune blob uploads 2024-11-29 07:09:05 -08:00
Bassem Dghaidi ff642a18e3 Force use of Azure for restoreCacheV2 2024-11-28 07:42:07 -08:00
Bassem Dghaidi 3e095368f1 Refactor saveCacheV2 to use saveCache from cacheHttpClient 2024-11-28 07:22:01 -08:00
Bassem Dghaidi 10c2c22dd2 Respect download options for restore 2024-11-28 04:56:37 -08:00
Bassem Dghaidi ffe895ecd9 Linter fixes 2024-11-28 03:53:34 -08:00
Bassem Dghaidi af0425c904 Refactor cache upload functionality and improve test cases 2024-11-28 03:52:09 -08:00
Bassem Dghaidi 33f6373861 Refactor code formatting for consistency and readability 2024-11-27 05:58:22 -08:00
Bassem Dghaidi f1aa7811eb Update the useragent of the old http client to pass cache version 2024-11-27 05:50:01 -08:00
Bassem Dghaidi 82befd3a8f Replace downloadCacheFile with downloadCacheStorageSDK 2024-11-27 04:51:21 -08:00
John Sudol f4bb9a563c run prettier 2024-11-26 00:56:07 +00:00
John Sudol 29b76597d9 Add debug message for uploadResponse 2024-11-26 00:43:37 +00:00
John Sudol 8e0c67a6ea Add saveCacheV2 tests 2024-11-26 00:23:42 +00:00
Bassem Dghaidi 5cd6c0376f Add the download cache file status code to debug log 2024-11-25 07:34:52 -08:00
Bassem Dghaidi 01128265a9 Add the download cache file status code to debug log 2024-11-25 07:34:07 -08:00
Bassem Dghaidi 2360eb3d26 Fix cache lookup scenario 2024-11-25 05:47:51 -08:00
Bassem Dghaidi b39d23cb38 Add support for matching on restore key values 2024-11-25 05:42:50 -08:00
Bassem Dghaidi 7c9c946d7e Add cache service version debug message 2024-11-25 04:08:47 -08:00
Bassem Dghaidi d464c6fdaf Add more tests for restoreCacheV2 2024-11-25 03:53:03 -08:00
Bassem Dghaidi eafd0f7f46 Add restore tests 2024-11-22 09:01:59 -08:00
Bassem Dghaidi edb731e24f Linter fixes and remove unnecessary dependency 2024-11-21 04:05:04 -08:00
Bassem Dghaidi b72fc22ab7 Add isGhes gate and refactor to clean up circular dependencies 2024-11-21 04:01:44 -08:00
Bassem Dghaidi f1bb07f5f0 Update cache service APIs & cleanup 2024-11-20 13:53:47 -08:00
Bassem Dghaidi 8a57bddafb Remove unused definitions 2024-11-14 07:11:12 -08:00