Compare commits

..

11 Commits

Author SHA1 Message Date
f5b55ae568 Delete a 2022-03-24 16:30:32 +05:30
2387ae8f10 Add files via upload 2022-03-24 16:30:14 +05:30
875b52c705 Delete index.js 2022-03-24 16:29:36 +05:30
97ba7aa16d Create a 2022-03-24 16:29:20 +05:30
81375c4b58 Delete a 2022-03-24 16:28:59 +05:30
9716b96acd Add files via upload 2022-03-24 16:28:40 +05:30
eeff95f289 Create a 2022-03-24 16:27:55 +05:30
8584e116c7 Delete index.js 2022-03-24 16:26:43 +05:30
0c44ddbd87 Add files via upload 2022-03-24 16:25:51 +05:30
8de84b9d78 Delete package-lock.json 2022-03-24 16:25:13 +05:30
128caf4219 Update package.json 2022-03-24 16:24:14 +05:30
26 changed files with 3148 additions and 9146 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.1 version: 1.0.10
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

@ -10,15 +10,28 @@ See ["Caching dependencies to speed up workflows"](https://help.github.com/githu
## What's New ## What's New
### v3 ### v3
* Added support for caching from GHES 3.5.
* 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`.
* Fixed zstd failing on amazon linux 2.0 runners
* Fixed cache not working with github workspace directory or current directory
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
@ -31,8 +44,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
@ -57,7 +69,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
@ -74,8 +86,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.
@ -83,7 +93,6 @@ Every programming language and framework has its own way of caching.
See [Examples](examples.md) for a list of `actions/cache` implementations for use with: See [Examples](examples.md) for a list of `actions/cache` implementations for use with:
- [C# - NuGet](./examples.md#c---nuget) - [C# - NuGet](./examples.md#c---nuget)
- [Clojure - Lein Deps](./examples.md#clojure---lein-deps)
- [D - DUB](./examples.md#d---dub) - [D - DUB](./examples.md#d---dub)
- [Deno](./examples.md#deno) - [Deno](./examples.md#deno)
- [Elixir - Mix](./examples.md#elixir---mix) - [Elixir - Mix](./examples.md#elixir---mix)
@ -151,7 +160,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
@ -166,57 +175,17 @@ 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`)
## Known limitation
## Cache Version - `action/cache` is currently not supported on GitHub Enterprise Server. <https://github.com/github/roadmap/issues/273> is tracking this.
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. Since GitHub Enterprise Server uses self-hosted runners, dependencies are typically cached on the runner by whatever dependency management tool is being used (npm, maven, etc.). This eliminates the need for explicit caching in some scenarios.
```yaml ## Changelog schedule and history
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Primes | Status | Version | Date | Highlights |
id: cache-primes |:---|:---|:---|:---|
uses: actions/cache@v3 | Published | v3.0.0 | Mar 21st, 2022 | - Updated minimum runner version support from node 12 -> node 16 <br> |
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

@ -1,24 +0,0 @@
# Releases
### 3.0.0
- Updated minimum runner version support from node 12 -> node 16
### 3.0.1
- Added support for caching from GHES 3.5.
- 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))
### 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

View File

@ -1,4 +1,3 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core"; import * as core from "@actions/core";
import { Events, Outputs, RefKey, State } from "../src/constants"; import { Events, Outputs, RefKey, State } from "../src/constants";
@ -6,7 +5,6 @@ import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils"; import * as testUtils from "../src/utils/testUtils";
jest.mock("@actions/core"); jest.mock("@actions/core");
jest.mock("@actions/cache");
beforeAll(() => { beforeAll(() => {
jest.spyOn(core, "getInput").mockImplementation((name, options) => { jest.spyOn(core, "getInput").mockImplementation((name, options) => {
@ -234,41 +232,3 @@ test("getInputAsInt throws if required and value missing", () => {
actionUtils.getInputAsInt("undefined", { required: true }) actionUtils.getInputAsInt("undefined", { required: true })
).toThrowError(); ).toThrowError();
}); });
test("isCacheFeatureAvailable for ac enabled", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);
expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
});
test("isCacheFeatureAvailable for ac disabled on GHES", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
const message =
"Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.";
const infoMock = jest.spyOn(core, "info");
try {
process.env["GITHUB_SERVER_URL"] = "http://example.com";
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
} finally {
delete process.env["GITHUB_SERVER_URL"];
}
});
test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
const message =
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.";
const infoMock = jest.spyOn(core, "info");
try {
process.env["GITHUB_SERVER_URL"] = "http://github.com";
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
} finally {
delete process.env["GITHUB_SERVER_URL"];
}
});

View File

@ -34,9 +34,6 @@ beforeEach(() => {
process.env[RefKey] = "refs/heads/feature-branch"; process.env[RefKey] = "refs/heads/feature-branch";
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => true
);
}); });
afterEach(() => { afterEach(() => {
@ -58,12 +55,10 @@ test("restore with invalid event outputs warning", async () => {
expect(failedMock).toHaveBeenCalledTimes(0); expect(failedMock).toHaveBeenCalledTimes(0);
}); });
test("restore without AC available should no-op", async () => { test("restore on GHES should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => false
);
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const restoreCacheMock = jest.spyOn(cache, "restoreCache"); const restoreCacheMock = jest.spyOn(cache, "restoreCache");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
@ -72,54 +67,9 @@ test("restore without AC available should no-op", async () => {
expect(restoreCacheMock).toHaveBeenCalledTimes(0); expect(restoreCacheMock).toHaveBeenCalledTimes(0);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
}); expect(logWarningMock).toHaveBeenCalledWith(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
test("restore on GHES without AC available should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => false
); );
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
await run();
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
});
test("restore on GHES with AC available ", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
const path = "node_modules";
const key = "node-test";
testUtils.setInputs({
path: path,
key
});
const infoMock = jest.spyOn(core, "info");
const failedMock = jest.spyOn(core, "setFailed");
const stateMock = jest.spyOn(core, "saveState");
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
const restoreCacheMock = jest
.spyOn(cache, "restoreCache")
.mockImplementationOnce(() => {
return Promise.resolve(key);
});
await run();
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(true);
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
expect(failedMock).toHaveBeenCalledTimes(0);
}); });
test("restore with no path should fail", async () => { test("restore with no path should fail", async () => {
@ -227,6 +177,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

@ -54,9 +54,6 @@ beforeEach(() => {
process.env[RefKey] = "refs/heads/feature-branch"; process.env[RefKey] = "refs/heads/feature-branch";
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => true
);
}); });
afterEach(() => { afterEach(() => {
@ -104,67 +101,18 @@ test("save with no primary key in state outputs warning", async () => {
expect(failedMock).toHaveBeenCalledTimes(0); expect(failedMock).toHaveBeenCalledTimes(0);
}); });
test("save without AC available should no-op", async () => { test("save on GHES should no-op", async () => {
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation( jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
() => false
);
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const saveCacheMock = jest.spyOn(cache, "saveCache"); const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(); await run();
expect(saveCacheMock).toHaveBeenCalledTimes(0); expect(saveCacheMock).toHaveBeenCalledTimes(0);
}); expect(logWarningMock).toHaveBeenCalledWith(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
test("save on ghes without AC available should no-op", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => false
); );
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run();
expect(saveCacheMock).toHaveBeenCalledTimes(0);
});
test("save on GHES with AC available", async () => {
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
const failedMock = jest.spyOn(core, "setFailed");
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-";
jest.spyOn(core, "getState")
// Cache Entry State
.mockImplementationOnce(() => {
return savedCacheKey;
})
// Cache Key State
.mockImplementationOnce(() => {
return primaryKey;
});
const inputPath = "node_modules";
testUtils.setInput(Inputs.Path, inputPath);
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
const cacheId = 4;
const saveCacheMock = jest
.spyOn(cache, "saveCache")
.mockImplementationOnce(() => {
return Promise.resolve(cacheId);
});
await run();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, {
uploadChunkSize: 4000000
});
expect(failedMock).toHaveBeenCalledTimes(0);
}); });
test("save with exact match returns early", async () => { test("save with exact match returns early", async () => {
@ -267,6 +215,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 +254,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'

1534
dist/restore/index.js vendored

File diff suppressed because it is too large Load Diff

1518
dist/save/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
# Examples # Examples
- [C# - NuGet](#c---nuget) - [C# - NuGet](#c---nuget)
- [Clojure - Lein Deps](#clojure---lein-deps)
- [D - DUB](#d---dub) - [D - DUB](#d---dub)
- [POSIX](#posix) - [POSIX](#posix)
- [Windows](#windows) - [Windows](#windows)
@ -10,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)
@ -20,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)
@ -81,19 +82,6 @@ steps:
${{ runner.os }}-nuget- ${{ runner.os }}-nuget-
``` ```
## Clojure - Lein Deps
```yaml
- name: Cache lein project dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-clojure-${{ hashFiles('**/project.clj') }}
restore-keys: |
${{ runner.os }}-clojure
```
## D - DUB ## D - DUB
### POSIX ### POSIX
@ -102,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-
``` ```
@ -113,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-
``` ```
@ -149,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
@ -166,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
@ -237,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
@ -256,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.
@ -306,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

8605
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.6", "version": "3.0.0",
"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": "^3.0.1", "@actions/cache": "file:actions-cache-1.0.10.tgz",
"@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.15.0",
"@typescript-eslint/parser": "^5.22.0", "@typescript-eslint/parser": "^5.15.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.2",
"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.0",
"ts-jest": "^28.0.2", "ts-jest": "^27.1.3",
"typescript": "^4.6.4" "typescript": "^3.9.9"
} }
} }

View File

@ -6,7 +6,10 @@ import * as utils from "./utils/actionUtils";
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
if (!utils.isCacheFeatureAvailable()) { if (utils.isGhes()) {
utils.logWarning(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
);
utils.setCacheHitOutput(false); utils.setCacheHitOutput(false);
return; return;
} }
@ -29,31 +32,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

@ -11,7 +11,10 @@ process.on("uncaughtException", e => utils.logWarning(e.message));
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
if (!utils.isCacheFeatureAvailable()) { if (utils.isGhes()) {
utils.logWarning(
"Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details"
);
return; return;
} }
@ -44,15 +47,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);
} }
} }

View File

@ -1,4 +1,3 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core"; import * as core from "@actions/core";
import { Outputs, RefKey, State } from "../constants"; import { Outputs, RefKey, State } from "../constants";
@ -75,20 +74,3 @@ export function getInputAsInt(
} }
return value; return value;
} }
export function isCacheFeatureAvailable(): boolean {
if (!cache.isFeatureAvailable()) {
if (isGhes()) {
logWarning(
"Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not."
);
} else {
logWarning(
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."
);
}
return false;
}
return true;
}