mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-05-20 08:11:25 +02:00
Compare commits
36 commits
6710a4f1f6
...
3182ee571c
Author | SHA1 | Date | |
---|---|---|---|
3182ee571c | |||
8fc291c114 | |||
0c45773b62 | |||
8a55f839aa | |||
3884cace14 | |||
e29dad3e36 | |||
ab5e6d0c87 | |||
89c7d86c71 | |||
d2c84da363 | |||
37e7d4eb16 | |||
a18323f504 | |||
a2ed59d39b | |||
dc88ab52d7 | |||
1d78355196 | |||
c36458f13b | |||
13aacd865c | |||
53b35c5439 | |||
65b8989fab | |||
d0be34d544 | |||
66cf064d47 | |||
1326563738 | |||
e12d46a63a | |||
1baebfc3ba | |||
eb94f1a6bf | |||
e71876755e | |||
01229828ff | |||
3185ecfd61 | |||
25618a0a67 | |||
a0a285ffd4 | |||
b00bedba4a | |||
99d573b49d | |||
6f0a1fdd90 | |||
2001ca4114 | |||
0e9aed0d0d | |||
3b7dac1789 | |||
b1378c8403 |
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
|
@ -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"
|
||||
|
|
28
.github/workflows/release-new-action-version.yml
vendored
Normal file
28
.github/workflows/release-new-action-version.yml
vendored
Normal 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 }}
|
4
.github/workflows/workflow.yml
vendored
4
.github/workflows/workflow.yml
vendored
|
@ -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
|
||||
|
|
BIN
.licenses/npm/@actions/cache.dep.yml
generated
BIN
.licenses/npm/@actions/cache.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-http.dep.yml
generated
BIN
.licenses/npm/@azure/core-http.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/ms-rest-js.dep.yml
generated
BIN
.licenses/npm/@azure/ms-rest-js.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/ip-regex.dep.yml
generated
BIN
.licenses/npm/ip-regex.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/psl.dep.yml
generated
BIN
.licenses/npm/psl.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/punycode.dep.yml
generated
BIN
.licenses/npm/punycode.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/semver.dep.yml
generated
BIN
.licenses/npm/semver.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/tough-cookie.dep.yml
generated
BIN
.licenses/npm/tough-cookie.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/xml2js.dep.yml
generated
BIN
.licenses/npm/xml2js.dep.yml
generated
Binary file not shown.
32
README.md
32
README.md
|
@ -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+.
|
||||
|
@ -60,11 +65,12 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir
|
|||
|
||||
### Outputs
|
||||
|
||||
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
|
||||
* `cache-hit` - A string with three possible values indicating whether a matching cache was found:
|
||||
1. `'true'` if a cache exactly matching `key` was found.
|
||||
2. `'false'` if a cache matching one of the `restore-keys` was found.
|
||||
3. Empty if no matching cache was found (cache miss).
|
||||
|
||||
> **Note** `cache-hit` will only be set to `true` when a cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
|
||||
|
||||
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
|
||||
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output.
|
||||
|
||||
### Cache scopes
|
||||
|
||||
|
@ -90,7 +96,7 @@ jobs:
|
|||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: ${{ runner.os }}-primes
|
||||
|
@ -121,7 +127,7 @@ jobs:
|
|||
|
||||
- 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 +138,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 +192,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 +210,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') }}
|
||||
|
@ -226,7 +232,7 @@ Example:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/cache@v3
|
||||
- uses: actions/cache@v4
|
||||
id: cache
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
|
@ -258,7 +264,7 @@ jobs:
|
|||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: primes
|
||||
|
@ -269,7 +275,7 @@ jobs:
|
|||
|
||||
- name: Cache Numbers
|
||||
id: cache-numbers
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: numbers
|
||||
key: primes
|
||||
|
@ -285,7 +291,7 @@ jobs:
|
|||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: primes
|
||||
|
|
149
RELEASES.md
149
RELEASES.md
|
@ -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,35 +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.0.8
|
||||
|
||||
- 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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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'
|
||||
|
|
56680
dist/restore-only/index.js
vendored
56680
dist/restore-only/index.js
vendored
File diff suppressed because one or more lines are too long
56646
dist/restore/index.js
vendored
56646
dist/restore/index.js
vendored
File diff suppressed because one or more lines are too long
56764
dist/save-only/index.js
vendored
56764
dist/save-only/index.js
vendored
File diff suppressed because one or more lines are too long
56737
dist/save/index.js
vendored
56737
dist/save/index.js
vendored
File diff suppressed because one or more lines are too long
1173
package-lock.json
generated
1173
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cache",
|
||||
"version": "3.3.2",
|
||||
"version": "4.0.2",
|
||||
"private": true,
|
||||
"description": "Cache dependencies and build outputs",
|
||||
"main": "dist/restore/index.js",
|
||||
|
@ -23,7 +23,7 @@
|
|||
"author": "GitHub",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.2.2",
|
||||
"@actions/cache": "^3.2.3",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/io": "^1.1.2"
|
||||
|
@ -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",
|
||||
|
|
|
@ -14,13 +14,14 @@ The restore action restores a cache. It works similarly to the `cache` action ex
|
|||
|
||||
### Outputs
|
||||
|
||||
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
|
||||
* `cache-hit` - A string with three possible values indicating whether a matching cache was found:
|
||||
1. `'true'` if a cache exactly matching `key` was found.
|
||||
In this case, `cache-primary-key == cache-matched-key`.
|
||||
2. `'false'` if a cache matching one of the `restore-keys` was found.
|
||||
3. Empty if no matching cache was found (cache miss).
|
||||
* `cache-primary-key` - Cache primary key passed in the input to use in subsequent steps of the workflow.
|
||||
* `cache-matched-key` - 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.
|
||||
|
||||
> **Note**
|
||||
`cache-hit` will be set to `true` only when cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
|
||||
|
||||
### Environment Variables
|
||||
|
||||
* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `10`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout)
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -16,7 +16,7 @@ inputs:
|
|||
default: 'false'
|
||||
required: false
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: '../dist/save-only/index.js'
|
||||
branding:
|
||||
icon: 'archive'
|
||||
|
|
|
@ -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()) {
|
||||
|
@ -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
|
||||
|
|
11
src/save.ts
11
src/save.ts
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue