Compare commits

..

23 Commits

Author SHA1 Message Date
7852e58f8c resolved conflicts 2022-03-30 15:42:54 +05:30
c31528629d typo 2022-03-28 18:17:18 +05:30
0137340fba Update package-lock.json 2022-03-28 17:57:00 +05:30
90e5189d64 Update package.json 2022-03-28 17:55:18 +05:30
5c8d224b05 Update RELEASES.md 2022-03-28 17:54:41 +05:30
d21804b55f Create RELEASES.md 2022-03-28 17:50:46 +05:30
587260d98f Update README.md 2022-03-28 16:06:13 +05:30
f4b8916a4f Update package.json 2022-03-28 15:46:17 +05:30
6bf3948635 Update cache.dep.yml 2022-03-28 15:39:05 +05:30
31da19523d Update actionUtils.test.ts 2022-03-28 15:27:12 +05:30
e093ab00fc linting errors 2022-03-28 14:25:43 +05:30
c5862e209e ran code format 2022-03-28 13:20:40 +05:30
9fae644795 changed with public released package 2022-03-28 10:08:34 +05:30
7e4d931f67 updated with 2.0 2022-03-25 01:57:45 +05:30
bc53ec57f3 changed tookit 2022-03-24 17:34:39 +05:30
234b8019b9 added new line 2022-03-24 15:15:46 +05:30
770facace5 changed name 2022-03-24 15:11:17 +05:30
0be029b716 Merge branch 'testGheswithACFlag' of github.com:actions/cache into testGheswithACFlag 2022-03-24 15:08:17 +05:30
85665c5247 package.json 2022-03-24 15:01:19 +05:30
c29e204c9f review comments and updated test cases 2022-03-24 14:59:36 +05:30
998cb51251 Update package-lock.json 2022-03-23 18:47:48 +05:30
824f444748 Update package-lock.json 2022-03-23 18:43:25 +05:30
1a306b5b35 initial changes 2022-03-23 18:39:24 +05:30
25 changed files with 3117 additions and 8925 deletions

View File

@ -1,18 +0,0 @@
# Set to true to add reviewers to pull requests
addReviewers: true
# Set to true to add assignees to pull requests
addAssignees: false
# A list of reviewers to be added to pull requests (GitHub user name)
reviewers:
- phantsure
- kotewar
- aparna-ravindra
- tiwarishub
- vsvipul
- bishal-pdmsft
# A number of reviewers added to the pull request
# Set 0 to add all the reviewers (default: 0)
numberOfReviewers: 1

View File

@ -1,15 +0,0 @@
name: Issue assignment
on:
issues:
types: [opened]
jobs:
auto-assign:
runs-on: ubuntu-latest
steps:
- name: 'Auto-assign issue'
uses: pozil/auto-assign-issue@v1.4.0
with:
assignees: phantsure,kotewar,tiwarishub,aparna-ravindra,vsvipul,bishal-pdmsft
numOfAssignee: 1

View File

@ -1,10 +0,0 @@
name: 'Auto Assign'
on:
pull_request_target:
types: [opened, ready_for_review]
jobs:
add-reviews:
runs-on: ubuntu-latest
steps:
- uses: kentaro-m/auto-assign-action@v1.2.1

View File

@ -22,13 +22,16 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v2
- name: Setup Node.js 16.x
uses: actions/setup-node@v3 - name: Set Node.js 12.x
uses: actions/setup-node@v1
with: with:
node-version: 16.x node-version: 12.x
- name: Install dependencies - name: Install dependencies
run: npm ci run: npm ci
- name: Rebuild the dist/ directory - name: Rebuild the dist/ directory
run: npm run build run: npm run build
@ -42,7 +45,7 @@ jobs:
id: diff id: diff
# If index.js was different than expected, upload the expected version as an artifact # If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }} if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with: with:
name: dist name: dist

View File

@ -12,10 +12,10 @@ jobs:
steps: steps:
- uses: actions/stale@v3 - uses: actions/stale@v3
with: with:
days-before-issue-stale: 200 days-before-issue-stale: 365
days-before-issue-close: 5 days-before-issue-close: 5
stale-issue-label: "stale" stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days." stale-issue-message: "This issue is stale because it has been open for 365 days with no activity. Leave a comment to avoid closing this issue in 5 days."
close-issue-message: "This issue was closed because it has been inactive for 5 days since being marked as stale." close-issue-message: "This issue was closed because it has been inactive for 5 days since being marked as stale."
days-before-pr-stale: -1 days-before-pr-stale: -1
days-before-pr-close: -1 days-before-pr-close: -1

View File

@ -14,7 +14,7 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v2
with: with:
# We must fetch at least the immediate parents so that if this is # We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head. # a pull request then we can checkout the head.
@ -24,7 +24,7 @@ jobs:
# the head of the pull request instead of the merge commit. # the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2 - run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }} if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v1

View File

@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Check licenses name: Check licenses
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v2
- run: npm ci - run: npm ci
- name: Install licensed - name: Install licensed
run: | run: |

View File

@ -24,11 +24,11 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v2
- name: Setup Node.js 16.x - name: Setup Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v1
with: with:
node-version: 16.x node-version: '12.x'
- name: Determine npm cache directory - name: Determine npm cache directory
id: npm-cache id: npm-cache
run: | run: |
@ -57,7 +57,7 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v2
- name: Generate files in working directory - name: Generate files in working directory
shell: bash shell: bash
run: __tests__/create-cache-files.sh ${{ runner.os }} test-cache run: __tests__/create-cache-files.sh ${{ runner.os }} test-cache
@ -80,7 +80,7 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v2
- name: Restore cache - name: Restore cache
uses: ./ uses: ./
with: with:
@ -110,7 +110,7 @@ jobs:
https_proxy: http://squid-proxy:3128 https_proxy: http://squid-proxy:3128
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v2
- name: Generate files - name: Generate files
run: __tests__/create-cache-files.sh proxy test-cache run: __tests__/create-cache-files.sh proxy test-cache
- name: Save cache - name: Save cache
@ -133,7 +133,7 @@ jobs:
https_proxy: http://squid-proxy:3128 https_proxy: http://squid-proxy:3128
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v2
- name: Restore cache - name: Restore cache
uses: ./ uses: ./
with: with:

View File

@ -1,6 +1,6 @@
--- ---
name: "@actions/cache" name: "@actions/cache"
version: 3.0.0 version: 2.0.0
type: npm type: npm
summary: summary:
homepage: homepage:

View File

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

View File

@ -1,9 +1,9 @@
--- ---
name: "@opentelemetry/api" name: "@opentelemetry/api"
version: 1.0.4 version: 1.1.0
type: npm type: npm
summary: Public API for OpenTelemetry summary:
homepage: https://github.com/open-telemetry/opentelemetry-js-api#readme homepage:
license: apache-2.0 license: apache-2.0
licenses: licenses:
- sources: LICENSE - sources: LICENSE

View File

@ -1,9 +1,9 @@
--- ---
name: "@types/node" name: "@types/node"
version: 16.11.33 version: 16.11.26
type: npm type: npm
summary: TypeScript definitions for Node.js summary:
homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node homepage:
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE

View File

@ -13,10 +13,27 @@ See ["Caching dependencies to speed up workflows"](https://help.github.com/githu
* Added support for caching from GHES 3.5. * Added support for caching from GHES 3.5.
* Fixed download issue for files > 2GB during restore. * Fixed download issue for files > 2GB during restore.
* Updated the minimum runner version support from node 12 -> node 16. * Updated the minimum runner version support from node 12 -> node 16.
* Fixed avoiding empty cache save when no files are available for caching.
* Fixed tar creation error while trying to create tar with path as `~/` home folder on `ubuntu-latest`.
Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions ### v2
* Increased the cache size limit to 10 GB.
* Added support for multiple paths, [glob patterns](https://github.com/actions/toolkit/tree/main/packages/glob), and single file caches.
```yaml
- name: Cache multiple paths
uses: actions/cache@v3
with:
path: |
~/cache
!~/cache/exclude
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
* Increased performance and improved cache sizes using `zstd` compression for Linux and macOS runners
* Allowed caching for all events with a ref. See [events that trigger workflow](https://help.github.com/en/actions/reference/events-that-trigger-workflows) for info on which events do not have a `GITHUB_REF`
* Released the [`@actions/cache`](https://github.com/actions/toolkit/tree/main/packages/cache) npm package to allow other actions to utilize caching
* Added a best-effort cleanup step to delete the archive after extraction to reduce storage space
Refer [here](https://github.com/actions/cache/blob/v1/README.md) for previous versions
## Usage ## Usage
@ -29,8 +46,7 @@ If you are using this inside a container, a POSIX-compliant `tar` needs to be in
* `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. * `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.
* `key` - An explicit key for restoring and saving the cache * `key` - An explicit key for restoring and saving the cache
* `restore-keys` - An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note * `restore-keys` - An ordered list of keys to use for restoring the cache if no cache hit occurred for key
`cache-hit` returns false in this case.
### Outputs ### Outputs
@ -55,7 +71,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v2
- name: Cache Primes - name: Cache Primes
id: cache-primes id: cache-primes
@ -72,8 +88,6 @@ jobs:
run: /primes.sh -d prime-numbers run: /primes.sh -d prime-numbers
``` ```
> Note: You must use the `cache` action in your workflow before you need to use the files that might be restored from the cache. If the provided `key` doesn't match an existing cache, a new cache is automatically created if the job completes successfully.
## Implementation Examples ## Implementation Examples
Every programming language and framework has its own way of caching. Every programming language and framework has its own way of caching.
@ -148,7 +162,7 @@ Using the `cache-hit` output, subsequent steps (such as install or build) can be
Example: Example:
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v2
- uses: actions/cache@v3 - uses: actions/cache@v3
id: cache id: cache
@ -163,58 +177,6 @@ steps:
> Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`) > Note: The `id` defined in `actions/cache` must match the `id` in the `if` statement (i.e. `steps.[ID].outputs.cache-hit`)
## Cache Version
Cache version is unique for a combination of compression tool used for compression of cache (Gzip, Zstd, etc based on runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique cache entries. This also means that a cache created on `windows-latest` runner can't be restored on `ubuntu-latest` as cache `Version`s are different.
Example: Below example will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
```yaml
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v3
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d prime-numbers
- name: Cache Numbers
id: cache-numbers
uses: actions/cache@v3
with:
path: numbers
key: primes
- name: Generate Numbers
if: steps.cache-numbers.outputs.cache-hit != 'true'
run: ./generate-primes.sh -d numbers
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes
id: cache-primes
uses: actions/cache@v3
with:
path: prime-numbers
key: primes
- name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true'
run: ./generate-primes -d prime-numbers
```
## Contributing ## Contributing
We would love for you to contribute to `actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. We would love for you to contribute to `actions/cache`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

View File

@ -6,15 +6,3 @@
### 3.0.1 ### 3.0.1
- Added support for caching from GHES 3.5. - Added support for caching from GHES 3.5.
- Fixed download issue for files > 2GB during restore. - Fixed download issue for files > 2GB during restore.
### 3.0.2
- Added support for dynamic cache size cap on GHES.
### 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.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.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))

View File

@ -227,6 +227,40 @@ test("restore with no cache found", async () => {
); );
}); });
test("restore with server error should fail", async () => {
const path = "node_modules";
const key = "node-test";
testUtils.setInputs({
path: path,
key
});
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const failedMock = jest.spyOn(core, "setFailed");
const stateMock = jest.spyOn(core, "saveState");
const restoreCacheMock = jest
.spyOn(cache, "restoreCache")
.mockImplementationOnce(() => {
throw new Error("HTTP Error Occurred");
});
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
await run();
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(logWarningMock).toHaveBeenCalledTimes(1);
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("restore with restore keys and no cache found", async () => { test("restore with restore keys and no cache found", async () => {
const path = "node_modules"; const path = "node_modules";
const key = "node-test"; const key = "node-test";

View File

@ -267,6 +267,7 @@ test("save with large cache outputs warning", async () => {
}); });
test("save with reserve cache failure outputs warning", async () => { test("save with reserve cache failure outputs warning", async () => {
const infoMock = jest.spyOn(core, "info");
const logWarningMock = jest.spyOn(actionUtils, "logWarning"); const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const failedMock = jest.spyOn(core, "setFailed"); const failedMock = jest.spyOn(core, "setFailed");
@ -305,10 +306,10 @@ test("save with reserve cache failure outputs warning", async () => {
expect.anything() expect.anything()
); );
expect(logWarningMock).toHaveBeenCalledWith( expect(infoMock).toHaveBeenCalledWith(
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.` `Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
); );
expect(logWarningMock).toHaveBeenCalledTimes(1); expect(logWarningMock).toHaveBeenCalledTimes(0);
expect(failedMock).toHaveBeenCalledTimes(0); expect(failedMock).toHaveBeenCalledTimes(0);
}); });

View File

@ -9,7 +9,7 @@ inputs:
description: 'An explicit key for restoring and saving the cache' description: 'An explicit key for restoring and saving the cache'
required: true required: true
restore-keys: 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 list of keys to use for restoring the cache if no cache hit occurred for key'
required: false required: false
upload-chunk-size: upload-chunk-size:
description: 'The chunk size used to split up large files during upload, in bytes' description: 'The chunk size used to split up large files during upload, in bytes'

Binary file not shown.

1521
dist/restore/index.js vendored

File diff suppressed because it is too large Load Diff

1505
dist/save/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,6 @@
- [macOS](#macos) - [macOS](#macos)
- [Windows](#windows-1) - [Windows](#windows-1)
- [Elixir - Mix](#elixir---mix) - [Elixir - Mix](#elixir---mix)
- [Erlang - Rebar3](#erlang--rebar3)
- [Go - Modules](#go---modules) - [Go - Modules](#go---modules)
- [Linux](#linux-1) - [Linux](#linux-1)
- [macOS](#macos-1) - [macOS](#macos-1)
@ -19,6 +18,9 @@
- [Java - Gradle](#java---gradle) - [Java - Gradle](#java---gradle)
- [Java - Maven](#java---maven) - [Java - Maven](#java---maven)
- [Node - npm](#node---npm) - [Node - npm](#node---npm)
- [macOS and Ubuntu](#macos-and-ubuntu)
- [Windows](#windows-3)
- [Using multiple systems and `npm config`](#using-multiple-systems-and-npm-config)
- [Node - Lerna](#node---lerna) - [Node - Lerna](#node---lerna)
- [Node - Yarn](#node---yarn) - [Node - Yarn](#node---yarn)
- [Node - Yarn 2](#node---yarn-2) - [Node - Yarn 2](#node---yarn-2)
@ -88,7 +90,7 @@ steps:
- uses: actions/cache@v3 - uses: actions/cache@v3
with: with:
path: ~/.dub path: ~/.dub
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }} key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-dub- ${{ runner.os }}-dub-
``` ```
@ -99,7 +101,7 @@ steps:
- uses: actions/cache@v3 - uses: actions/cache@v3
with: with:
path: ~\AppData\Local\dub path: ~\AppData\Local\dub
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }} key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-dub- ${{ runner.os }}-dub-
``` ```
@ -135,10 +137,11 @@ steps:
with: with:
path: | path: |
~\.deno ~\.deno
~\AppData\Local\deno %LocalAppData%\deno
key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }} key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}
``` ```
## Elixir - Mix ## Elixir - Mix
```yaml ```yaml
@ -152,18 +155,6 @@ steps:
${{ runner.os }}-mix- ${{ runner.os }}-mix-
``` ```
## Erlang - Rebar3
```yaml
- uses: actions/cache@v2
with:
path: |
~/.cache/rebar3
_build
key: ${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-${{ hashFiles('**/*rebar.lock') }}
restore-keys: |
${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-
```
## Go - Modules ## Go - Modules
### Linux ### Linux
@ -223,8 +214,6 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
## Haskell - Stack ## Haskell - Stack
### Linux or macOS
```yaml ```yaml
- uses: actions/cache@v3 - uses: actions/cache@v3
name: Cache ~/.stack name: Cache ~/.stack
@ -242,27 +231,6 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
${{ runner.os }}-stack-work- ${{ runner.os }}-stack-work-
``` ```
### Windows
```yaml
- uses: actions/cache@v3
name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack
with:
path: |
~\AppData\Roaming\stack
~\AppData\Local\Programs\stack
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
restore-keys: |
${{ runner.os }}-stack-global-
- uses: actions/cache@v3
name: Cache .stack-work
with:
path: .stack-work
key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }}
restore-keys: |
${{ runner.os }}-stack-work-
```
## Java - Gradle ## Java - Gradle
>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. >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.
@ -292,12 +260,40 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
## Node - npm ## Node - npm
For npm, cache files are stored in `~/.npm` on Posix, or `~\AppData\npm-cache` on Windows, but it's possible to use `npm config get cache` to find the path on any platform. See [the npm docs](https://docs.npmjs.com/cli/cache#cache) for more details. For npm, cache files are stored in `~/.npm` on Posix, or `%AppData%/npm-cache` on Windows. See https://docs.npmjs.com/cli/cache#cache
If using `npm config` to retrieve the cache directory, ensure you run [actions/setup-node](https://github.com/actions/setup-node) first to ensure your `npm` version is correct. If using `npm config` to retrieve the cache directory, ensure you run [actions/setup-node](https://github.com/actions/setup-node) first to ensure your `npm` version is correct.
>Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci` >Note: It is not recommended to cache `node_modules`, as it can break across Node versions and won't work with `npm ci`
### macOS and Ubuntu
```yaml
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
```
### Windows
```yaml
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
```
### Using multiple systems and `npm config`
```yaml ```yaml
- name: Get npm cache directory - name: Get npm cache directory
id: npm-cache-dir id: npm-cache-dir

8602
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "cache", "name": "cache",
"version": "3.0.5", "version": "3.0.1",
"private": true, "private": true,
"description": "Cache dependencies and build outputs", "description": "Cache dependencies and build outputs",
"main": "dist/restore/index.js", "main": "dist/restore/index.js",
@ -23,29 +23,29 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "file:actions-cache-3.0.1.tgz", "@actions/cache": "^2.0.0",
"@actions/core": "^1.7.0", "@actions/core": "^1.2.6",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/io": "^1.1.2" "@actions/io": "^1.1.2"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.5.0", "@types/jest": "^27.4.1",
"@types/nock": "^11.1.0", "@types/nock": "^11.1.0",
"@types/node": "^16.11.33", "@types/node": "^16.11.26",
"@typescript-eslint/eslint-plugin": "^5.22.0", "@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.22.0", "@typescript-eslint/parser": "^5.16.0",
"@zeit/ncc": "^0.20.5", "@zeit/ncc": "^0.20.5",
"eslint": "^8.14.0", "eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.5", "eslint-plugin-jest": "^26.1.3",
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0", "eslint-plugin-simple-import-sort": "^7.0.0",
"jest": "^28.0.3", "jest": "^27.5.1",
"jest-circus": "^27.5.1", "jest-circus": "^27.5.1",
"nock": "^13.2.4", "nock": "^11.7.0",
"prettier": "^2.6.2", "prettier": "^2.6.1",
"ts-jest": "^28.0.2", "ts-jest": "^27.1.4",
"typescript": "^4.6.4" "typescript": "^3.9.9"
} }
} }

View File

@ -29,31 +29,39 @@ async function run(): Promise<void> {
required: true required: true
}); });
const cacheKey = await cache.restoreCache( try {
cachePaths, const cacheKey = await cache.restoreCache(
primaryKey, cachePaths,
restoreKeys primaryKey,
); restoreKeys
if (!cacheKey) {
core.info(
`Cache not found for input keys: ${[
primaryKey,
...restoreKeys
].join(", ")}`
); );
if (!cacheKey) {
core.info(
`Cache not found for input keys: ${[
primaryKey,
...restoreKeys
].join(", ")}`
);
return;
}
return; // Store the matched cache key
utils.setCacheState(cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
utils.setCacheHitOutput(isExactKeyMatch);
core.info(`Cache restored from key: ${cacheKey}`);
} catch (error) {
if (error.name === cache.ValidationError.name) {
throw error;
} else {
utils.logWarning(error.message);
utils.setCacheHitOutput(false);
}
} }
} catch (error) {
// Store the matched cache key core.setFailed(error.message);
utils.setCacheState(cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
utils.setCacheHitOutput(isExactKeyMatch);
core.info(`Cache restored from key: ${cacheKey}`);
} catch (error: unknown) {
core.setFailed((error as Error).message);
} }
} }

View File

@ -44,15 +44,22 @@ async function run(): Promise<void> {
required: true required: true
}); });
const cacheId = await cache.saveCache(cachePaths, primaryKey, { try {
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize) await cache.saveCache(cachePaths, primaryKey, {
}); uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
});
if (cacheId != -1) {
core.info(`Cache saved with key: ${primaryKey}`); core.info(`Cache saved with key: ${primaryKey}`);
} catch (error) {
if (error.name === cache.ValidationError.name) {
throw error;
} else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message);
} else {
utils.logWarning(error.message);
}
} }
} catch (error: unknown) { } catch (error) {
utils.logWarning((error as Error).message); utils.logWarning(error.message);
} }
} }