Compare commits

...

40 Commits

Author SHA1 Message Date
Bassem Dghaidi 81382a721f
Merge pull request #1311 from todgru/todgru/v4-documentation-update
docs: update examples to v4
2024-08-14 12:13:33 +02:00
Bassem Dghaidi c4ee99a3bd
Merge branch 'main' into todgru/v4-documentation-update 2024-08-14 12:09:56 +02:00
Soubhik Kumar Mitra 57b8e405f0
Clarify that the `restore-keys` input is a string in the docs (#1434)
* Fix Description for restore-keys at Readme

As previously the restore-keys were defined as an ordered lists which is
wrong as per the issue description where the actual format is a
multi-line string with one key per line.

* Added a space between the sentence of restore-keys description

While at the PR review it's been identified there's a need for a space
between the sentence

	```
	An ordered multiline string listing the prefix-matched keys,that are
	used for restoring stale cache if no cache hit occurred for key.
	```

where it's written as "prefix-matched keys,that are" this commit will
address the review comment and introduce a space between
"prefix-matched keys, that are" and change the sentence to

	```
	An ordered multiline string listing the prefix-matched keys, that are
        used for restoring stale cache if no cache hit occurred for key.
	```

* Change restore-keys description at cache/restore/action.yml and cache/action.yml
2024-08-06 14:26:54 +00:00
r4mimu 40c3b67b29
Fix cache-hit output when cache missed (#1404)
* fix: cache-hit output

* fix: Output chache hit timing

* fix: Output chache hit timing

---------

Co-authored-by: Josh Gross <joshmgross@github.com>
2024-07-31 16:56:48 +00:00
Oleg A. e47d9f9ec8
Explicit use bash for Windows (#1377)
Co-authored-by: Josh Gross <joshmgross@github.com>
2024-07-31 16:52:21 +00:00
P. Ottlinger 4a28cbc054
Update README.md and use v4 of checkout action (#1437)
Update examples to use latest available checkout action v4.
2024-07-29 16:07:30 -04:00
todgru bf9a7572fe
Merge branch 'main' into todgru/v4-documentation-update 2024-04-24 07:24:11 -07:00
Bethany 0c45773b62
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
Fix `fail-on-cache-miss` not working
2024-03-19 09:31:49 -04:00
Marc Mueller 8a55f839aa Add test case for process exit
Co-authored-by: Bethany <bethanyj28@users.noreply.github.com>
2024-03-19 09:28:12 +01:00
Marc Mueller 3884cace14 Bump version 2024-03-01 07:28:18 +01:00
Marc Mueller e29dad3e36 Fix fail-on-cache-miss not working 2024-03-01 07:28:18 +01:00
Bethany ab5e6d0c87
Merge pull request #1341 from bethanyj28/main
Update @actions/cache
2024-02-29 13:25:25 -05:00
bethanyj28 89c7d86c71 licensed cache 2024-02-29 13:17:11 -05:00
bethanyj28 d2c84da363 update @actions/cache 2024-02-29 13:11:38 -05:00
Bethany 37e7d4eb16
Merge pull request #1340 from actions/bethanyj28/update-publish-flow
Update actions/cache publish flow
2024-02-29 10:13:02 -05:00
Bethany a18323f504
add release action 2024-02-29 09:43:02 -05:00
todgru 104f95683b update documentation to use <action>@v4 2024-01-26 14:08:22 -08:00
Yang Cao a2ed59d39b
Merge pull request #1305 from actions/yacaovsnc/update_examples
Update examples
2024-01-17 11:44:48 -05:00
Yang Cao dc88ab52d7 Update examples 2024-01-17 11:42:01 -05:00
Yang Cao 1d78355196
Merge pull request #1304 from actions/yacaovsnc/update_readme
Update README.md
2024-01-17 11:35:20 -05:00
Yang Cao c36458f13b
Update README.md 2024-01-17 11:31:56 -05:00
Rob Herley 13aacd865c
Merge pull request #1242 from to-s/main
feat: save-always flag
2024-01-16 14:54:22 -05:00
Rob Herley 53b35c5439
Merge branch 'main' into main 2024-01-16 14:51:14 -05:00
Yang Cao 65b8989fab
Merge pull request #1284 from takost/update-to-node-20
Update action to node20
2024-01-16 10:16:06 -05:00
Tatyana Kostromskaya d0be34d544 Fix dist 2024-01-15 14:19:39 +00:00
Tatyana Kostromskaya 66cf064d47 Merge branch 'main' into update-to-node-20 2024-01-15 14:13:28 +00:00
Rob Herley 1326563738
Merge branch 'main' into main 2024-01-11 15:19:28 -05:00
Rob Herley e12d46a63a
Merge pull request #1302 from actions/robherley/v3.3.3
Cache v3.3.3
2024-01-11 11:38:08 -05:00
Tatyana Kostromskaya e71876755e Fix format 2024-01-10 15:40:24 +00:00
Tatyana Kostromskaya 01229828ff Apply workaround for earlyExit 2024-01-10 15:36:58 +00:00
Tatyana Kostromskaya 3185ecfd61 Update "only-" actions to node20 2024-01-10 15:00:25 +00:00
Tatyana Kostromskaya 25618a0a67 Bump version 2024-01-10 14:37:39 +00:00
Tatyana Kostromskaya a0a285ffd4 replace deprecated @zeit/ncc with @vercel/ncc 2023-12-15 11:00:48 +00:00
Tatyana Kostromskaya b00bedba4a Update license 2023-12-15 10:37:48 +00:00
Tatyana Kostromskaya 99d573b49d Rebuild dist 2023-12-15 10:17:02 +00:00
Tatyana Kostromskaya 6f0a1fdd90 Update check-dist node version 2023-12-14 15:30:15 +00:00
Tatyana Kostromskaya 2001ca4114 Update action to node20 2023-11-20 13:30:40 +00:00
to-s 0e9aed0d0d Revert "Update action.yml"
This reverts commit 3b7dac1789.
2023-11-09 00:31:17 +01:00
to-s 3b7dac1789
Update action.yml
Co-authored-by: Tomasz Janiszewski <janiszt@gmail.com>
2023-11-06 07:23:38 +01:00
to-s b1378c8403
added save-always input 2023-09-13 13:58:52 +02:00
30 changed files with 112789 additions and 114793 deletions

View File

@ -15,3 +15,5 @@ jobs:
call-check-dist:
name: Check dist/
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
with:
node-version: "20.x"

View File

@ -0,0 +1,28 @@
name: Release new action version
on:
release:
types: [released]
workflow_dispatch:
inputs:
TAG_NAME:
description: 'Tag name that the major tag will point to'
required: true
env:
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
permissions:
contents: write
jobs:
update_tag:
name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes
environment:
name: releaseNewActionVersion
runs-on: ubuntu-latest
steps:
- name: Update the ${{ env.TAG_NAME }} tag
id: update-major-tag
uses: actions/publish-action@v0.3.0
with:
source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

View File

@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js 16.x
- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
cache: npm
- run: npm ci
- name: Prettier Format Check

View File

@ -1,6 +1,6 @@
---
name: "@actions/cache"
version: 3.2.3
version: 3.2.4
type: npm
summary: Actions cache lib
homepage: https://github.com/actions/toolkit/tree/main/packages/cache

View File

@ -14,6 +14,11 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
## What's New
### v4
* Updated to node 20
* Added a `save-always` flag to save the cache even if a prior step fails
### v3
* Added support for caching in GHES 3.5+.
@ -49,7 +54,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir
* `key` - An explicit key for a cache entry. See [creating a cache key](#creating-a-cache-key).
* `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns.
* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key.
* `restore-keys` - An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key.
* `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false`
* `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false`
* `lookup-only` - If true, only checks if cache entry exists and skips download. Does not change save cache behavior. Default: `false`
@ -86,11 +91,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache Primes
id: cache-primes
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: prime-numbers
key: ${{ runner.os }}-primes
@ -117,11 +122,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: |
path/to/dependencies
@ -132,7 +137,7 @@ jobs:
.
- name: Save Primes
id: cache-primes-save
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
@ -186,7 +191,7 @@ A cache key can include any of the contexts, functions, literals, and operators
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
@ -204,7 +209,7 @@ Additionally, you can use arbitrary command output in a cache key, such as a dat
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
@ -224,9 +229,9 @@ Example:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache
with:
path: path/to/dependencies
@ -254,11 +259,11 @@ jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache Primes
id: cache-primes
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: prime-numbers
key: primes
@ -269,7 +274,7 @@ jobs:
- name: Cache Numbers
id: cache-numbers
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: numbers
key: primes
@ -281,11 +286,11 @@ jobs:
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache Primes
id: cache-primes
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: prime-numbers
key: primes

View File

@ -1,77 +1,54 @@
# Releases
### 3.0.0
### 4.0.2
- Updated minimum runner version support from node 12 -> node 16
- Fixed restore `fail-on-cache-miss` not working.
### 3.0.1
### 4.0.1
- Added support for caching from GHES 3.5.
- Fixed download issue for files > 2GB during restore.
- Updated `isGhes` check
### 3.0.2
### 4.0.0
- Added support for dynamic cache size cap on GHES.
- Updated minimum runner version support from node 12 -> node 20
### 3.0.3
### 3.3.3
- Fixed avoiding empty cache save when no files are available for caching. ([issue](https://github.com/actions/cache/issues/624))
- Updates @actions/cache to v3.2.3 to fix accidental mutated path arguments to `getCacheVersion` [actions/toolkit#1378](https://github.com/actions/toolkit/pull/1378)
- Additional audit fixes of npm package(s)
### 3.0.4
### 3.3.2
- Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`. ([issue](https://github.com/actions/cache/issues/689))
- Fixes bug with Azure SDK causing blob downloads to get stuck.
### 3.0.5
### 3.3.1
- Removed error handling by consuming actions/cache 3.0 toolkit, Now cache server error handling will be done by toolkit. ([PR](https://github.com/actions/cache/pull/834))
- Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
### 3.0.6
### 3.3.0
- Fixed [#809](https://github.com/actions/cache/issues/809) - zstd -d: no such file or directory error
- Fixed [#833](https://github.com/actions/cache/issues/833) - cache doesn't work with github workspace directory
- Added option to lookup cache without downloading it.
### 3.0.7
### 3.2.6
- Fixed [#810](https://github.com/actions/cache/issues/810) - download stuck issue. A new timeout is introduced in the download process to abort the download if it gets stuck and doesn't finish within an hour.
- Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners.
### 3.0.8
### 3.2.5
- Fix zstd not working for windows on gnu tar in issues [#888](https://github.com/actions/cache/issues/888) and [#891](https://github.com/actions/cache/issues/891).
- Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 60 minutes.
- Added fix to prevent from setting MYSYS environment variable globally.
### 3.0.9
### 3.2.4
- Enhanced the warning message for cache unavailablity in case of GHES.
- Added option to fail job on cache miss.
### 3.0.10
### 3.2.3
- Fix a bug with sorting inputs.
- Update definition for restore-keys in README.md
- Support cross os caching on Windows as an opt-in feature.
- Fix issue with symlink restoration on Windows for cross-os caches.
### 3.0.11
### 3.2.2
- Update toolkit version to 3.0.5 to include `@actions/core@^1.10.0`
- Update `@actions/cache` to use updated `saveState` and `setOutput` functions from `@actions/core@^1.10.0`
### 3.1.0-beta.1
- Update `@actions/cache` on windows to use gnu tar and zstd by default and fallback to bsdtar and zstd if gnu tar is not available. ([issue](https://github.com/actions/cache/issues/984))
### 3.1.0-beta.2
- Added support for fallback to gzip to restore old caches on windows.
### 3.1.0-beta.3
- Bug fixes for bsdtar fallback if gnutar not available and gzip fallback if cache saved using old cache action on windows.
### 3.2.0-beta.1
- Added two new actions - [restore](restore/action.yml) and [save](save/action.yml) for granular control on cache.
### 3.2.0
- Released the two new actions - [restore](restore/action.yml) and [save](save/action.yml) for granular control on cache
- Reverted the changes made in 3.2.1 to use gnu tar and zstd by default on windows.
### 3.2.1
@ -79,40 +56,75 @@
- Added support for fallback to gzip to restore old caches on windows.
- Added logs for cache version in case of a cache miss.
### 3.2.2
### 3.2.0
- Reverted the changes made in 3.2.1 to use gnu tar and zstd by default on windows.
- Released the two new actions - [restore](restore/action.yml) and [save](save/action.yml) for granular control on cache
### 3.2.3
### 3.2.0-beta.1
- Support cross os caching on Windows as an opt-in feature.
- Fix issue with symlink restoration on Windows for cross-os caches.
- Added two new actions - [restore](restore/action.yml) and [save](save/action.yml) for granular control on cache.
### 3.2.4
### 3.1.0-beta.3
- Added option to fail job on cache miss.
- Bug fixes for bsdtar fallback if gnutar not available and gzip fallback if cache saved using old cache action on windows.
### 3.2.5
### 3.1.0-beta.2
- Added fix to prevent from setting MYSYS environment variable globally.
- Added support for fallback to gzip to restore old caches on windows.
### 3.2.6
### 3.1.0-beta.1
- Fix zstd not being used after zstd version upgrade to 1.5.4 on hosted runners.
- Update `@actions/cache` on windows to use gnu tar and zstd by default and fallback to bsdtar and zstd if gnu tar is not available. ([issue](https://github.com/actions/cache/issues/984))
### 3.3.0
### 3.0.11
- Added option to lookup cache without downloading it.
- Update toolkit version to 3.0.5 to include `@actions/core@^1.10.0`
- Update `@actions/cache` to use updated `saveState` and `setOutput` functions from `@actions/core@^1.10.0`
### 3.3.1
### 3.0.10
- Reduced segment size to 128MB and segment timeout to 10 minutes to fail fast in case the cache download is stuck.
- Fix a bug with sorting inputs.
- Update definition for restore-keys in README.md
### 3.3.2
### 3.0.9
- Fixes bug with Azure SDK causing blob downloads to get stuck.
- Enhanced the warning message for cache unavailablity in case of GHES.
### 3.3.3
### 3.0.8
- Updates @actions/cache to v3.2.3 to fix accidental mutated path arguments to `getCacheVersion` [actions/toolkit#1378](https://github.com/actions/toolkit/pull/1378)
- Additional audit fixes of npm package(s)
- Fix zstd not working for windows on gnu tar in issues [#888](https://github.com/actions/cache/issues/888) and [#891](https://github.com/actions/cache/issues/891).
- Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 60 minutes.
### 3.0.7
- Fixed [#810](https://github.com/actions/cache/issues/810) - download stuck issue. A new timeout is introduced in the download process to abort the download if it gets stuck and doesn't finish within an hour.
### 3.0.6
- Fixed [#809](https://github.com/actions/cache/issues/809) - zstd -d: no such file or directory error
- Fixed [#833](https://github.com/actions/cache/issues/833) - cache doesn't work with github workspace directory
### 3.0.5
- Removed error handling by consuming actions/cache 3.0 toolkit, Now cache server error handling will be done by toolkit. ([PR](https://github.com/actions/cache/pull/834))
### 3.0.4
- Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`. ([issue](https://github.com/actions/cache/issues/689))
### 3.0.3
- Fixed avoiding empty cache save when no files are available for caching. ([issue](https://github.com/actions/cache/issues/624))
### 3.0.2
- Added support for dynamic cache size cap on GHES.
### 3.0.1
- Added support for caching from GHES 3.5.
- Fixed download issue for files > 2GB during restore.
### 3.0.0
- Updated minimum runner version support from node 12 -> node 16

View File

@ -260,7 +260,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
);
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(failedMock).toHaveBeenCalledWith(
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`

View File

@ -449,3 +449,19 @@ test("restore with lookup-only set", async () => {
);
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("restore failure with earlyExit should call process exit", async () => {
testUtils.setInput(Inputs.Path, "node_modules");
const failedMock = jest.spyOn(core, "setFailed");
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
const processExitMock = jest.spyOn(process, "exit").mockImplementation();
// call restoreImpl with `earlyExit` set to true
await restoreImpl(new StateProvider(), true);
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
expect(failedMock).toHaveBeenCalledWith(
"Input required and not supplied: key"
);
expect(processExitMock).toHaveBeenCalledWith(1);
});

View File

@ -86,7 +86,8 @@ test("restore with no cache found", async () => {
);
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
expect(outputMock).toHaveBeenCalledTimes(1);
expect(outputMock).toHaveBeenCalledWith("cache-hit", "false");
expect(outputMock).toHaveBeenCalledTimes(2);
expect(failedMock).toHaveBeenCalledTimes(0);
expect(infoMock).toHaveBeenCalledWith(

View File

@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, RefKey } from "../src/constants";
import run from "../src/save";
import { saveRun } from "../src/saveImpl";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
@ -100,7 +100,7 @@ test("save with valid inputs uploads a cache", async () => {
return Promise.resolve(cacheId);
});
await run();
await saveRun();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(

View File

@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, RefKey } from "../src/constants";
import run from "../src/saveImpl";
import { saveImpl } from "../src/saveImpl";
import { StateProvider } from "../src/stateProvider";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
@ -77,7 +77,7 @@ test("save with invalid event outputs warning", async () => {
const invalidEvent = "commit_comment";
process.env[Events.Key] = invalidEvent;
delete process.env[RefKey];
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(logWarningMock).toHaveBeenCalledWith(
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
);
@ -100,7 +100,7 @@ test("save with no primary key in state outputs warning", async () => {
});
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(logWarningMock).toHaveBeenCalledWith(`Key is not specified.`);
@ -115,7 +115,7 @@ test("save without AC available should no-op", async () => {
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
});
@ -128,7 +128,7 @@ test("save on ghes without AC available should no-op", async () => {
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
});
@ -161,7 +161,7 @@ test("save on GHES with AC available", async () => {
return Promise.resolve(cacheId);
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -194,7 +194,7 @@ test("save with exact match returns early", async () => {
});
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(infoMock).toHaveBeenCalledWith(
@ -221,7 +221,7 @@ test("save with missing input outputs warning", async () => {
});
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(logWarningMock).toHaveBeenCalledWith(
@ -259,7 +259,7 @@ test("save with large cache outputs warning", async () => {
);
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -306,7 +306,7 @@ test("save with reserve cache failure outputs warning", async () => {
throw error;
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -349,7 +349,7 @@ test("save with server error outputs warning", async () => {
throw new Error("HTTP Error Occurred");
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -392,7 +392,7 @@ test("save with valid inputs uploads a cache", async () => {
return Promise.resolve(cacheId);
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(

View File

@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, RefKey } from "../src/constants";
import run from "../src/saveOnly";
import { saveOnlyRun } from "../src/saveImpl";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
@ -90,7 +90,7 @@ test("save with valid inputs uploads a cache", async () => {
return Promise.resolve(cacheId);
});
await run();
await saveOnlyRun();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -122,7 +122,7 @@ test("save failing logs the warning message", async () => {
return Promise.resolve(cacheId);
});
await run();
await saveOnlyRun();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(

View File

@ -9,7 +9,7 @@ inputs:
description: 'An explicit key for restoring and saving the cache'
required: true
restore-keys:
description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.'
description: 'An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.'
required: false
upload-chunk-size:
description: 'The chunk size used to split up large files during upload, in bytes'
@ -26,14 +26,18 @@ inputs:
description: 'Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache'
default: 'false'
required: false
save-always:
description: 'Run the post step to save the cache even if another step before fails'
default: 'false'
required: false
outputs:
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
runs:
using: 'node16'
using: 'node20'
main: 'dist/restore/index.js'
post: 'dist/save/index.js'
post-if: success()
post-if: "success() || github.event.inputs.save-always"
branding:
icon: 'archive'
color: 'gray-dark'

View File

@ -12,7 +12,7 @@ This document lists some of the strategies (and example workflows if possible) w
jobs:
build:
runs-on: ubuntu-latest
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
key: ${{ some-metadata }}-cache
```
@ -24,7 +24,7 @@ In your workflows, you can use different strategies to name your key depending o
One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile.
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
@ -37,7 +37,7 @@ One of the most common use case is to use hash for lockfile as key. This way, sa
If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time.
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
@ -54,7 +54,7 @@ The restore keys can be provided as a complete name, or a prefix, read more [her
In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS.
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
@ -73,7 +73,7 @@ Caches scoped to the particular workflow run id or run attempt can be stored and
On similar lines, commit sha can be used to create a very specialized and short lived cache.
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
@ -86,7 +86,7 @@ On similar lines, commit sha can be used to create a very specialized and short
Cache key can be formed by combination of more than one metadata, evaluated info.
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
path/to/dependencies
@ -146,9 +146,9 @@ In case you are using a centralized job to create and save your cache that can b
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache/restore@v3
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies
@ -171,9 +171,9 @@ You can use the output of this action to exit the workflow on cache miss. This w
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache/restore@v3
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies
@ -194,7 +194,7 @@ steps:
If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action.
```yaml
- uses: actions/cache/restore@v3
- uses: actions/cache/restore@v4
id: restore-cache
with:
path: |
@ -204,7 +204,7 @@ If you want to avoid re-computing the cache key again in `save` action, the outp
.
.
.
- uses: actions/cache/save@v3
- uses: actions/cache/save@v4
with:
path: |
path/to/dependencies
@ -219,7 +219,7 @@ On the other hand, the key can also be explicitly re-computed while executing th
Let's say we have a restore step that computes key at runtime
```yaml
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
id: restore-cache
with:
key: cache-${{ hashFiles('**/lockfiles') }}
@ -228,7 +228,7 @@ with:
Case 1: Where an user would want to reuse the key as it is
```yaml
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
```
@ -236,7 +236,7 @@ with:
Case 2: Where the user would want to re-evaluate the key
```yaml
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
key: npm-cache-${{hashfiles(package-lock.json)}}
```
@ -249,13 +249,13 @@ Similarly, `actions/cache/save` action can be conditionally used based on the ou
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
.
. // restore if need be
.
- name: Build
run: /build.sh
- uses: actions/cache/save@v3
- uses: actions/cache/save@v4
if: always() // or any other condition to invoke the save action
with:
path: path/to/dependencies
@ -270,12 +270,12 @@ In case of multi-module projects, where the built artifact of one project needs
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: ./build-parent-module.sh
- uses: actions/cache/save@v3
- uses: actions/cache/save@v4
id: cache
with:
path: path/to/dependencies
@ -286,9 +286,9 @@ steps:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache/restore@v3
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies

File diff suppressed because one or more lines are too long

56687
dist/restore/index.js vendored

File diff suppressed because one or more lines are too long

56804
dist/save-only/index.js vendored

File diff suppressed because one or more lines are too long

56777
dist/save/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -46,7 +46,7 @@
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
@ -55,10 +55,10 @@ Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/packa
```
Depending on the environment, huge packages might be pre-installed in the global cache folder.
With `actions/cache@v3` you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
With `actions/cache@v4` you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.nuget/packages
@ -75,7 +75,7 @@ Or you could move the cache folder like below.
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps:
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
@ -87,7 +87,7 @@ steps:
```yaml
- name: Cache lein project dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-clojure-${{ hashFiles('**/project.clj') }}
@ -101,7 +101,7 @@ steps:
### POSIX
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.dub
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
@ -112,7 +112,7 @@ steps:
### Windows
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~\AppData\Local\dub
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
@ -125,7 +125,7 @@ steps:
### Linux
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.deno
@ -136,7 +136,7 @@ steps:
### macOS
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.deno
@ -147,7 +147,7 @@ steps:
### Windows
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~\.deno
@ -158,7 +158,7 @@ steps:
## Elixir - Mix
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
deps
@ -185,7 +185,7 @@ steps:
### Linux
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
@ -198,7 +198,7 @@ steps:
### macOS
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/Library/Caches/go-build
@ -211,7 +211,7 @@ steps:
### Windows
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~\AppData\Local\go-build
@ -227,7 +227,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
```yaml
- name: Cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cabal/packages
@ -242,14 +242,14 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
### Linux or macOS
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Cache ~/.stack
with:
path: ~/.stack
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
restore-keys: |
${{ runner.os }}-stack-global-
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Cache .stack-work
with:
path: .stack-work
@ -261,7 +261,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
### Windows
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack
with:
path: |
@ -270,7 +270,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
restore-keys: |
${{ runner.os }}-stack-global-
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Cache .stack-work
with:
path: .stack-work
@ -284,7 +284,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
> **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons.
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
@ -298,7 +298,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
```yaml
- name: Cache local Maven repository
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
@ -334,7 +334,7 @@ After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-depr
`Get npm cache directory` step can then be used with `actions/cache` as shown below
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
@ -347,7 +347,7 @@ After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-depr
```yaml
- name: restore lerna
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
@ -361,7 +361,7 @@ The yarn cache directory will depend on your operating system and version of `ya
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
@ -379,7 +379,7 @@ The yarn 2 cache directory will depend on your config. See https://yarnpkg.com/c
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
@ -394,7 +394,7 @@ Esy allows you to export built dependencies and import pre-built dependencies.
```yaml
- name: Restore Cache
id: restore-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: _export
key: ${{ runner.os }}-esy-${{ hashFiles('esy.lock/index.json') }}
@ -423,7 +423,7 @@ Esy allows you to export built dependencies and import pre-built dependencies.
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
@ -444,7 +444,7 @@ Locations:
### Simple example
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
@ -457,7 +457,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
### Multiple OS's in a workflow
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pip
@ -465,7 +465,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/cache@v3
- uses: actions/cache@v4
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/pip
@ -473,7 +473,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/cache@v3
- uses: actions/cache@v4
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
@ -499,7 +499,7 @@ jobs:
- os: windows-latest
path: ~\AppData\Local\pip\Cache
steps:
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
@ -513,11 +513,12 @@ jobs:
```yaml
- name: Get pip cache dir
id: pip-cache
shell: bash
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
@ -535,7 +536,7 @@ jobs:
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
@ -562,7 +563,7 @@ For renv, the cache directory will vary by OS. The `RENV_PATHS_ROOT` environment
cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
shell: Rscript {0}
- name: Restore Renv package cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}
@ -588,7 +589,7 @@ whenever possible:
## Rust - Cargo
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
@ -603,7 +604,7 @@ whenever possible:
```yaml
- name: Cache SBT
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.ivy2/cache
@ -614,7 +615,7 @@ whenever possible:
## Swift, Objective-C - Carthage
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: Carthage
key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
@ -625,7 +626,7 @@ whenever possible:
## Swift, Objective-C - CocoaPods
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
@ -636,7 +637,7 @@ whenever possible:
## Swift - Swift Package Manager
```yaml
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
@ -651,7 +652,7 @@ env:
MINT_PATH: .mint/lib
MINT_LINK_PATH: .mint/bin
steps:
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: .mint
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
@ -667,7 +668,7 @@ steps:
```yaml
- name: Cache Bazel
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
@ -681,7 +682,7 @@ steps:
```yaml
- name: Cache Bazel
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
/private/var/tmp/_bazel_runner/

35
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "cache",
"version": "3.3.2",
"version": "4.0.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "cache",
"version": "3.3.2",
"version": "4.0.2",
"license": "MIT",
"dependencies": {
"@actions/cache": "^3.2.3",
@ -20,7 +20,7 @@
"@types/node": "^16.18.3",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@zeit/ncc": "^0.20.5",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
@ -36,9 +36,9 @@
}
},
"node_modules/@actions/cache": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.2.3.tgz",
"integrity": "sha512-m8KvmcD+JxSLOfNUXuBF2jL0Lp+co/Fhbf0NTt0M9lz61WnXRdqpIGrOvTRZmKIl+7HaHil6kGE3fkEfrKQCQA==",
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.2.4.tgz",
"integrity": "sha512-RuHnwfcDagtX+37s0ZWy7clbOfnZ7AlDJQ7k/9rzt2W4Gnwde3fa/qjSjVuz4vLcLIpc7fUob27CMrqiWZytYA==",
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.0.1",
@ -3135,11 +3135,10 @@
"url": "https://opencollective.com/typescript-eslint"
}
},
"node_modules/@zeit/ncc": {
"version": "0.20.5",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.20.5.tgz",
"integrity": "sha512-XU6uzwvv95DqxciQx+aOLhbyBx/13ky+RK1y88Age9Du3BlA4mMPCy13BGjayOrrumOzlq1XV3SD/BWiZENXlw==",
"deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.",
"node_modules/@vercel/ncc": {
"version": "0.38.1",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.1.tgz",
"integrity": "sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==",
"dev": true,
"bin": {
"ncc": "dist/ncc/cli.js"
@ -9534,9 +9533,9 @@
},
"dependencies": {
"@actions/cache": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.2.3.tgz",
"integrity": "sha512-m8KvmcD+JxSLOfNUXuBF2jL0Lp+co/Fhbf0NTt0M9lz61WnXRdqpIGrOvTRZmKIl+7HaHil6kGE3fkEfrKQCQA==",
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.2.4.tgz",
"integrity": "sha512-RuHnwfcDagtX+37s0ZWy7clbOfnZ7AlDJQ7k/9rzt2W4Gnwde3fa/qjSjVuz4vLcLIpc7fUob27CMrqiWZytYA==",
"requires": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.0.1",
@ -12014,10 +12013,10 @@
"eslint-visitor-keys": "^3.3.0"
}
},
"@zeit/ncc": {
"version": "0.20.5",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.20.5.tgz",
"integrity": "sha512-XU6uzwvv95DqxciQx+aOLhbyBx/13ky+RK1y88Age9Du3BlA4mMPCy13BGjayOrrumOzlq1XV3SD/BWiZENXlw==",
"@vercel/ncc": {
"version": "0.38.1",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.1.tgz",
"integrity": "sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==",
"dev": true
},
"abort-controller": {

View File

@ -1,6 +1,6 @@
{
"name": "cache",
"version": "3.3.3",
"version": "4.0.2",
"private": true,
"description": "Cache dependencies and build outputs",
"main": "dist/restore/index.js",
@ -34,7 +34,7 @@
"@types/node": "^16.18.3",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@zeit/ncc": "^0.20.5",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",

View File

@ -35,9 +35,9 @@ If you are using separate jobs to create and save your cache(s) to be reused by
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache/restore@v3
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies
@ -64,12 +64,12 @@ In case of multi-module projects, where the built artifact of one project needs
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: /build-parent-module.sh
- uses: actions/cache/save@v3
- uses: actions/cache/save@v4
id: cache
with:
path: path/to/dependencies
@ -80,9 +80,9 @@ steps:
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache/restore@v3
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies
@ -107,9 +107,9 @@ To fail if there is no cache hit for the primary key, leave `restore-keys` empty
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache/restore@v3
- uses: actions/cache/restore@v4
id: cache
with:
path: path/to/dependencies

View File

@ -9,7 +9,7 @@ inputs:
description: 'An explicit key for restoring the cache'
required: true
restore-keys:
description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.'
description: 'An ordered multiline string listing the prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.'
required: false
enableCrossOsArchive:
description: 'An optional boolean when enabled, allows windows runners to restore caches that were saved on other platforms'
@ -31,7 +31,7 @@ outputs:
cache-matched-key:
description: 'Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys'
runs:
using: 'node16'
using: 'node20'
main: '../dist/restore-only/index.js'
branding:
icon: 'archive'

View File

@ -23,7 +23,7 @@ If you are using separate jobs for generating common artifacts and sharing them
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Dependencies
run: /install.sh
@ -31,7 +31,7 @@ steps:
- name: Build artifacts
run: /build.sh
- uses: actions/cache/save@v3
- uses: actions/cache/save@v4
id: cache
with:
path: path/to/dependencies
@ -47,7 +47,7 @@ Let's say we have a restore step that computes a key at runtime.
#### Restore a cache
```yaml
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
id: restore-cache
with:
key: cache-${{ hashFiles('**/lockfiles') }}
@ -55,7 +55,7 @@ with:
#### Case 1 - Where a user would want to reuse the key as it is
```yaml
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
```
@ -63,7 +63,7 @@ with:
#### Case 2 - Where the user would want to re-evaluate the key
```yaml
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
key: npm-cache-${{hashfiles(package-lock.json)}}
```
@ -74,13 +74,13 @@ There are instances where some flaky test cases would fail the entire workflow a
```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
.
. // restore if need be
.
- name: Build
run: /build.sh
- uses: actions/cache/save@v3
- uses: actions/cache/save@v4
if: always() // or any other condition to invoke the save action
with:
path: path/to/dependencies

View File

@ -16,7 +16,7 @@ inputs:
default: 'false'
required: false
runs:
using: 'node16'
using: 'node20'
main: '../dist/save-only/index.js'
branding:
icon: 'archive'

View File

@ -10,7 +10,8 @@ import {
import * as utils from "./utils/actionUtils";
export async function restoreImpl(
stateProvider: IStateProvider
stateProvider: IStateProvider,
earlyExit?: boolean | undefined
): Promise<string | undefined> {
try {
if (!utils.isCacheFeatureAvailable()) {
@ -50,6 +51,7 @@ export async function restoreImpl(
);
if (!cacheKey) {
core.setOutput(Outputs.CacheHit, false.toString());
if (failOnCacheMiss) {
throw new Error(
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`
@ -61,7 +63,6 @@ export async function restoreImpl(
...restoreKeys
].join(", ")}`
);
return;
}
@ -83,6 +84,9 @@ export async function restoreImpl(
return cacheKey;
} catch (error: unknown) {
core.setFailed((error as Error).message);
if (earlyExit) {
process.exit(1);
}
}
}
@ -90,14 +94,7 @@ async function run(
stateProvider: IStateProvider,
earlyExit: boolean | undefined
): Promise<void> {
try {
await restoreImpl(stateProvider);
} catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
await restoreImpl(stateProvider, earlyExit);
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling

View File

@ -1,10 +1,3 @@
import saveImpl from "./saveImpl";
import { StateProvider } from "./stateProvider";
import { saveRun } from "./saveImpl";
async function run(): Promise<void> {
await saveImpl(new StateProvider());
}
run();
export default run;
saveRun(true);

View File

@ -2,7 +2,11 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, State } from "./constants";
import { IStateProvider } from "./stateProvider";
import {
IStateProvider,
NullStateProvider,
StateProvider
} from "./stateProvider";
import * as utils from "./utils/actionUtils";
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
@ -10,7 +14,9 @@ import * as utils from "./utils/actionUtils";
// throw an uncaught exception. Instead of failing this action, just warn.
process.on("uncaughtException", e => utils.logWarning(e.message));
async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
export async function saveImpl(
stateProvider: IStateProvider
): Promise<number | void> {
let cacheId = -1;
try {
if (!utils.isCacheFeatureAvailable()) {
@ -72,4 +78,47 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
return cacheId;
}
export default saveImpl;
export async function saveOnlyRun(
earlyExit?: boolean | undefined
): Promise<void> {
try {
const cacheId = await saveImpl(new NullStateProvider());
if (cacheId === -1) {
core.warning(`Cache save failed.`);
}
} catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
if (earlyExit) {
process.exit(0);
}
}
export async function saveRun(earlyExit?: boolean | undefined): Promise<void> {
try {
await saveImpl(new StateProvider());
} catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
if (earlyExit) {
process.exit(0);
}
}

View File

@ -1,15 +1,3 @@
import * as core from "@actions/core";
import { saveOnlyRun } from "./saveImpl";
import saveImpl from "./saveImpl";
import { NullStateProvider } from "./stateProvider";
async function run(): Promise<void> {
const cacheId = await saveImpl(new NullStateProvider());
if (cacheId === -1) {
core.warning(`Cache save failed.`);
}
}
run();
export default run;
saveOnlyRun(true);

View File

@ -12,7 +12,7 @@ A cache today is immutable and cannot be updated. But some use cases require the
```yaml
- name: update cache on every commit
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: prime-numbers
key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well
@ -61,7 +61,7 @@ jobs:
contents: read
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Cleanup
run: |