mirror of
https://github.com/actions/cache.git
synced 2026-05-21 04:38:19 +01:00
Compare commits
1 Commits
samirat/es
...
56ad4dd84a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56ad4dd84a |
@@ -17,4 +17,4 @@ jobs:
|
||||
uses: actions/checkout@v5
|
||||
- name: Publish
|
||||
id: publish
|
||||
uses: actions/publish-immutable-action@0.0.3
|
||||
uses: actions/publish-immutable-action@v0.0.4
|
||||
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
steps:
|
||||
- name: Update the ${{ env.TAG_NAME }} tag
|
||||
id: update-major-tag
|
||||
uses: actions/publish-action@v0.3.0
|
||||
uses: actions/publish-action@v0.4.0
|
||||
with:
|
||||
source-tag: ${{ env.TAG_NAME }}
|
||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||
|
||||
2
.licenses/npm/@typespec/ts-http-runtime.dep.yml
generated
2
.licenses/npm/@typespec/ts-http-runtime.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@typespec/ts-http-runtime"
|
||||
version: 0.3.5
|
||||
version: 0.3.2
|
||||
type: npm
|
||||
summary: Isomorphic client library for making HTTP requests in node.js and browser.
|
||||
homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/ts-http-runtime/
|
||||
|
||||
27
README.md
27
README.md
@@ -18,7 +18,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
||||
### ⚠️ Important changes
|
||||
|
||||
> [!IMPORTANT]
|
||||
> `actions/cache@v6` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.
|
||||
> `actions/cache@v5` runs on the Node.js 24 runtime and requires a minimum Actions Runner version of `2.327.1`.
|
||||
> If you are using self-hosted runners, ensure they are updated before upgrading.
|
||||
|
||||
The cache backend service has been rewritten from the ground up for improved performance and reliability. [actions/cache](https://github.com/actions/cache) now integrates with the new cache service (v2) APIs.
|
||||
@@ -38,11 +38,6 @@ Upgrading to the recommended versions will not break your workflows.
|
||||
|
||||
Read more about the change & access the migration guide: [reference to the announcement](https://github.com/actions/cache/discussions/1510).
|
||||
|
||||
### v6
|
||||
|
||||
* Updated `@actions/cache`, `@actions/core`, `@actions/exec` to latest major versions
|
||||
* Migrated to ESM module system
|
||||
|
||||
### v5
|
||||
|
||||
* Updated to node 24
|
||||
@@ -83,7 +78,7 @@ Create a workflow `.yml` file in your repository's `.github/workflows` directory
|
||||
|
||||
If you are using this inside a container, a POSIX-compliant `tar` needs to be included and accessible from the execution path.
|
||||
|
||||
Note: `actions/cache@v6` runs on Node.js 24 and requires a minimum Actions Runner version of `2.327.1`.
|
||||
Note: `actions/cache@v5` runs on Node.js 24 and requires a minimum Actions Runner version of `2.327.1`.
|
||||
|
||||
If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are required for [Cross-OS caching](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cross-os-cache) to work. They are also recommended to be installed in general so the performance is on par with `hosted` Windows runners.
|
||||
|
||||
@@ -132,7 +127,7 @@ jobs:
|
||||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: ${{ runner.os }}-primes
|
||||
@@ -163,7 +158,7 @@ jobs:
|
||||
|
||||
- name: Restore cached Primes
|
||||
id: cache-primes-restore
|
||||
uses: actions/cache/restore@v6
|
||||
uses: actions/cache/restore@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -174,7 +169,7 @@ jobs:
|
||||
.
|
||||
- name: Save Primes
|
||||
id: cache-primes-save
|
||||
uses: actions/cache/save@v6
|
||||
uses: actions/cache/save@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -229,7 +224,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@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -247,7 +242,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@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
|
||||
@@ -269,7 +264,7 @@ Example:
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
id: cache
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
@@ -301,7 +296,7 @@ jobs:
|
||||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: primes
|
||||
@@ -312,7 +307,7 @@ jobs:
|
||||
|
||||
- name: Cache Numbers
|
||||
id: cache-numbers
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: numbers
|
||||
key: primes
|
||||
@@ -328,7 +323,7 @@ jobs:
|
||||
|
||||
- name: Cache Primes
|
||||
id: cache-primes
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: primes
|
||||
|
||||
@@ -25,12 +25,6 @@
|
||||
|
||||
## Changelog
|
||||
|
||||
### 6.0.0
|
||||
|
||||
- Updated `@actions/cache` to ^6.0.1, `@actions/core` to ^3.0.1, `@actions/exec` to ^3.0.0, `@actions/io` to ^3.0.2
|
||||
- Migrated to ESM module system
|
||||
- Upgraded Jest to v30 and test infrastructure to be ESM compatible
|
||||
|
||||
### 5.0.4
|
||||
|
||||
- Bump `minimatch` to v3.1.5 (fixes ReDoS via globstar patterns)
|
||||
|
||||
@@ -1,66 +1,25 @@
|
||||
import { afterAll, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
import { Events, RefKey } from "../src/constants";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
// Mock @actions/cache
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: jest.fn(),
|
||||
saveCache: jest.fn(),
|
||||
isFeatureAvailable: jest.fn(() => true),
|
||||
ReserveCacheError: class ReserveCacheError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ReserveCacheError";
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const cache = await import("@actions/cache");
|
||||
const { Events, RefKey } = await import("../src/constants");
|
||||
const actionUtils = await import("../src/utils/actionUtils");
|
||||
const testUtils = await import("../src/utils/testUtils");
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
|
||||
let pristineEnv: NodeJS.ProcessEnv;
|
||||
|
||||
beforeAll(() => {
|
||||
pristineEnv = process.env;
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
return jest.requireActual("@actions/core").getInput(name, options);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
pristineEnv = { ...process.env };
|
||||
jest.clearAllMocks();
|
||||
(core.getInput as jest.Mock).mockImplementation(
|
||||
(name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||
"";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}
|
||||
);
|
||||
jest.resetModules();
|
||||
process.env = pristineEnv;
|
||||
delete process.env[Events.Key];
|
||||
delete process.env[RefKey];
|
||||
});
|
||||
@@ -88,46 +47,74 @@ test("isGhes returns false when server url is github.com", () => {
|
||||
});
|
||||
|
||||
test("isExactKeyMatch with undefined cache key returns false", () => {
|
||||
expect(actionUtils.isExactKeyMatch("linux-rust", undefined)).toBe(false);
|
||||
const key = "linux-rust";
|
||||
const cacheKey = undefined;
|
||||
|
||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
||||
});
|
||||
|
||||
test("isExactKeyMatch with empty cache key returns false", () => {
|
||||
expect(actionUtils.isExactKeyMatch("linux-rust", "")).toBe(false);
|
||||
const key = "linux-rust";
|
||||
const cacheKey = "";
|
||||
|
||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
||||
});
|
||||
|
||||
test("isExactKeyMatch with different keys returns false", () => {
|
||||
expect(actionUtils.isExactKeyMatch("linux-rust", "linux-")).toBe(false);
|
||||
const key = "linux-rust";
|
||||
const cacheKey = "linux-";
|
||||
|
||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
||||
});
|
||||
|
||||
test("isExactKeyMatch with different key accents returns false", () => {
|
||||
expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe(
|
||||
false
|
||||
);
|
||||
const key = "linux-áccent";
|
||||
const cacheKey = "linux-accent";
|
||||
|
||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
|
||||
});
|
||||
|
||||
test("isExactKeyMatch with same key returns true", () => {
|
||||
expect(actionUtils.isExactKeyMatch("linux-rust", "linux-rust")).toBe(true);
|
||||
const key = "linux-rust";
|
||||
const cacheKey = "linux-rust";
|
||||
|
||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
|
||||
});
|
||||
|
||||
test("isExactKeyMatch with same key and different casing returns true", () => {
|
||||
expect(actionUtils.isExactKeyMatch("linux-rust", "LINUX-RUST")).toBe(true);
|
||||
const key = "linux-rust";
|
||||
const cacheKey = "LINUX-RUST";
|
||||
|
||||
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
|
||||
});
|
||||
|
||||
test("logWarning logs a message with a warning prefix", () => {
|
||||
const message = "A warning occurred.";
|
||||
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
|
||||
actionUtils.logWarning(message);
|
||||
expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
||||
});
|
||||
|
||||
test("isValidEvent returns false for event that does not have a branch or tag", () => {
|
||||
process.env[Events.Key] = "foo";
|
||||
expect(actionUtils.isValidEvent()).toBe(false);
|
||||
const event = "foo";
|
||||
process.env[Events.Key] = event;
|
||||
|
||||
const isValidEvent = actionUtils.isValidEvent();
|
||||
|
||||
expect(isValidEvent).toBe(false);
|
||||
});
|
||||
|
||||
test("isValidEvent returns true for event that has a ref", () => {
|
||||
process.env[Events.Key] = Events.Push;
|
||||
const event = Events.Push;
|
||||
process.env[Events.Key] = event;
|
||||
process.env[RefKey] = "ref/heads/feature";
|
||||
expect(actionUtils.isValidEvent()).toBe(true);
|
||||
|
||||
const isValidEvent = actionUtils.isValidEvent();
|
||||
|
||||
expect(isValidEvent).toBe(true);
|
||||
});
|
||||
|
||||
test("getInputAsArray returns empty array if not required and missing", () => {
|
||||
@@ -137,7 +124,7 @@ test("getInputAsArray returns empty array if not required and missing", () => {
|
||||
test("getInputAsArray throws error if required and missing", () => {
|
||||
expect(() =>
|
||||
actionUtils.getInputAsArray("foo", { required: true })
|
||||
).toThrow();
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test("getInputAsArray handles single line correctly", () => {
|
||||
@@ -193,7 +180,7 @@ test("getInputAsInt returns undefined if input is invalid or NaN", () => {
|
||||
test("getInputAsInt throws if required and value missing", () => {
|
||||
expect(() =>
|
||||
actionUtils.getInputAsInt("undefined", { required: true })
|
||||
).toThrow();
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test("getInputAsBool returns false if input not set", () => {
|
||||
@@ -213,65 +200,68 @@ test("getInputAsBool returns false if input is invalid or NaN", () => {
|
||||
test("getInputAsBool throws if required and value missing", () => {
|
||||
expect(() =>
|
||||
actionUtils.getInputAsBool("undefined2", { required: true })
|
||||
).toThrow();
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test("isCacheFeatureAvailable for ac enabled", () => {
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);
|
||||
|
||||
expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
|
||||
});
|
||||
|
||||
test("isCacheFeatureAvailable for ac disabled on GHES", () => {
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||
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.
|
||||
Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/enterprise-server@3.5/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`;
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
|
||||
try {
|
||||
process.env["GITHUB_SERVER_URL"] = "http://example.com";
|
||||
expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
|
||||
expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
|
||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
||||
} finally {
|
||||
delete process.env["GITHUB_SERVER_URL"];
|
||||
}
|
||||
});
|
||||
|
||||
test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||
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(core.info).toHaveBeenCalledWith(`[warning]${message}`);
|
||||
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
|
||||
} finally {
|
||||
delete process.env["GITHUB_SERVER_URL"];
|
||||
}
|
||||
});
|
||||
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is not defined", () => {
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is not defined", async () => {
|
||||
delete process.env["GITHUB_SERVER_URL"];
|
||||
expect(actionUtils.isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to github.com", () => {
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to github.com", async () => {
|
||||
process.env["GITHUB_SERVER_URL"] = "https://github.com";
|
||||
expect(actionUtils.isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL", () => {
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL", async () => {
|
||||
process.env["GITHUB_SERVER_URL"] = "https://contoso.ghe.com";
|
||||
expect(actionUtils.isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix", () => {
|
||||
test("isGhes returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix", async () => {
|
||||
process.env["GITHUB_SERVER_URL"] = "https://mock-github.localhost";
|
||||
expect(actionUtils.isGhes()).toBeFalsy();
|
||||
});
|
||||
|
||||
test("isGhes returns true when the GITHUB_SERVER_URL environment variable is set to some other URL", () => {
|
||||
test("isGhes returns true when the GITHUB_SERVER_URL environment variable is set to some other URL", async () => {
|
||||
process.env["GITHUB_SERVER_URL"] = "https://src.onpremise.fabrikam.com";
|
||||
expect(actionUtils.isGhes()).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -1,66 +1,50 @@
|
||||
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
import { Events, RefKey } from "../src/constants";
|
||||
import { restoreRun } from "../src/restoreImpl";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
// Mock @actions/cache
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: jest.fn(),
|
||||
saveCache: jest.fn(),
|
||||
isFeatureAvailable: jest.fn(() => true),
|
||||
ReserveCacheError: class ReserveCacheError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ReserveCacheError";
|
||||
}
|
||||
}
|
||||
}));
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const cache = await import("@actions/cache");
|
||||
const { Events, RefKey } = await import("../src/constants");
|
||||
const { restoreRun } = await import("../src/restoreImpl");
|
||||
const testUtils = await import("../src/utils/testUtils");
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(core.getInput as jest.Mock).mockImplementation(
|
||||
(name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||
"";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
beforeAll(() => {
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isExactKeyMatch(key, cacheResult);
|
||||
}
|
||||
);
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||
|
||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isValidEvent();
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
||||
(name, options) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.getInputAsBool(name, options);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
process.env[Events.Key] = Events.Push;
|
||||
process.env[RefKey] = "refs/heads/feature-branch";
|
||||
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => true
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -78,12 +62,19 @@ test("restore with no cache found", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
@@ -93,10 +84,12 @@ test("restore with no cache found", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(1);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(stateMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}`
|
||||
);
|
||||
});
|
||||
@@ -112,12 +105,19 @@ test("restore with restore keys and no cache found", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
@@ -127,10 +127,12 @@ test("restore with restore keys and no cache found", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(1);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(stateMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||
);
|
||||
});
|
||||
@@ -144,12 +146,20 @@ test("restore with cache found for key", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(key);
|
||||
});
|
||||
|
||||
await restoreRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
@@ -159,13 +169,15 @@ test("restore with cache found for key", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore with cache found for restore key", async () => {
|
||||
@@ -179,20 +191,39 @@ test("restore with cache found for restore key", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(restoreKey);
|
||||
});
|
||||
|
||||
await restoreRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("Fail restore when fail on cache miss is enabled and primary + restore keys not found", async () => {
|
||||
@@ -206,17 +237,35 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
|
||||
failOnCacheMiss: true
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(0);
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(1);
|
||||
expect(failedMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
|
||||
@@ -230,20 +279,40 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
|
||||
failOnCacheMiss: true
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(restoreKey);
|
||||
});
|
||||
|
||||
await restoreRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore with fail on cache miss disabled and no cache found", async () => {
|
||||
@@ -257,15 +326,33 @@ test("restore with fail on cache miss disabled and no cache found", async () =>
|
||||
failOnCacheMiss: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(1);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(stateMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
@@ -1,68 +1,51 @@
|
||||
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import { restoreImpl } from "../src/restoreImpl";
|
||||
import { StateProvider } from "../src/stateProvider";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
// Mock @actions/cache
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: jest.fn(),
|
||||
saveCache: jest.fn(),
|
||||
isFeatureAvailable: jest.fn(() => true),
|
||||
ReserveCacheError: class ReserveCacheError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ReserveCacheError";
|
||||
}
|
||||
}
|
||||
}));
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const cache = await import("@actions/cache");
|
||||
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||
const { restoreImpl } = await import("../src/restoreImpl");
|
||||
const { StateProvider } = await import("../src/stateProvider");
|
||||
const testUtils = await import("../src/utils/testUtils");
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(core.getInput as jest.Mock).mockImplementation(
|
||||
(name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||
"";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
beforeAll(() => {
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isExactKeyMatch(key, cacheResult);
|
||||
}
|
||||
);
|
||||
(core.getState as jest.Mock).mockReturnValue("");
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||
|
||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isValidEvent();
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
||||
(name, options) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.getInputAsBool(name, options);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
process.env[Events.Key] = Events.Push;
|
||||
process.env[RefKey] = "refs/heads/feature-branch";
|
||||
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => true
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -72,37 +55,52 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
test("restore with invalid event outputs warning", async () => {
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const invalidEvent = "commit_comment";
|
||||
process.env[Events.Key] = invalidEvent;
|
||||
delete process.env[RefKey];
|
||||
await restoreImpl(new StateProvider());
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
`[warning]Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore without AC available should no-op", async () => {
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => false
|
||||
);
|
||||
|
||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
});
|
||||
|
||||
test("restore on GHES without AC available should no-op", async () => {
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => false
|
||||
);
|
||||
|
||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "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({
|
||||
@@ -111,12 +109,20 @@ test("restore on GHES with AC available ", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(key);
|
||||
});
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
@@ -126,26 +132,32 @@ test("restore on GHES with AC available ", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore with no path should fail", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||
await restoreImpl(new StateProvider());
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.setFailed).not.toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
||||
// this input isn't necessary for restore b/c tarball contains entries relative to workspace
|
||||
expect(failedMock).not.toHaveBeenCalledWith(
|
||||
"Input required and not supplied: path"
|
||||
);
|
||||
});
|
||||
|
||||
test("restore with no key", async () => {
|
||||
testUtils.setInput(Inputs.Path, "node_modules");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||
await restoreImpl(new StateProvider());
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
"Input required and not supplied: key"
|
||||
);
|
||||
});
|
||||
@@ -160,32 +172,46 @@ test("restore with too many keys should fail", async () => {
|
||||
restoreKeys,
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
(cache.restoreCache as jest.Mock).mockRejectedValue(
|
||||
new Error("Key Validation Error: Keys are limited to a maximum of 10.")
|
||||
);
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||
await restoreImpl(new StateProvider());
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
restoreKeys,
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Key Validation Error: Keys are limited to a maximum of 10.`
|
||||
);
|
||||
});
|
||||
|
||||
test("restore with large key should fail", async () => {
|
||||
const path = "node_modules";
|
||||
const key = "foo".repeat(512);
|
||||
const key = "foo".repeat(512); // Over the 512 character limit
|
||||
testUtils.setInputs({
|
||||
path: path,
|
||||
key,
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
(cache.restoreCache as jest.Mock).mockRejectedValue(
|
||||
new Error(
|
||||
`Key Validation Error: ${key} cannot be larger than 512 characters.`
|
||||
)
|
||||
);
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||
await restoreImpl(new StateProvider());
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Key Validation Error: ${key} cannot be larger than 512 characters.`
|
||||
);
|
||||
});
|
||||
@@ -198,12 +224,20 @@ test("restore with invalid key should fail", async () => {
|
||||
key,
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
(cache.restoreCache as jest.Mock).mockRejectedValue(
|
||||
new Error(`Key Validation Error: ${key} cannot contain commas.`)
|
||||
);
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
|
||||
await restoreImpl(new StateProvider());
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Key Validation Error: ${key} cannot contain commas.`
|
||||
);
|
||||
});
|
||||
@@ -217,14 +251,32 @@ test("restore with no cache found", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}`
|
||||
);
|
||||
});
|
||||
@@ -240,14 +292,32 @@ test("restore with restore keys and no cache found", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||
);
|
||||
});
|
||||
@@ -261,16 +331,35 @@ test("restore with cache found for key", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(key);
|
||||
});
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore with cache found for restore key", async () => {
|
||||
@@ -284,18 +373,36 @@ test("restore with cache found for restore key", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(restoreKey);
|
||||
});
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore with lookup-only set", async () => {
|
||||
@@ -307,12 +414,20 @@ test("restore with lookup-only set", async () => {
|
||||
lookupOnly: true
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const stateMock = jest.spyOn(core, "saveState");
|
||||
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(key);
|
||||
});
|
||||
|
||||
await restoreImpl(new StateProvider());
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
@@ -322,30 +437,31 @@ test("restore with lookup-only set", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
|
||||
expect(stateMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
||||
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache found and can be restored from key: ${key}`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore failure with earlyExit should call process exit", async () => {
|
||||
testUtils.setInput(Inputs.Path, "node_modules");
|
||||
const processExitMock = jest
|
||||
.spyOn(process, "exit")
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.mockImplementation((() => {}) as any);
|
||||
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(cache.restoreCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
"Input required and not supplied: key"
|
||||
);
|
||||
expect(processExitMock).toHaveBeenCalledWith(1);
|
||||
processExitMock.mockRestore();
|
||||
});
|
||||
|
||||
@@ -1,66 +1,51 @@
|
||||
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
import { Events, RefKey } from "../src/constants";
|
||||
import { restoreOnlyRun } from "../src/restoreImpl";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
// Mock @actions/cache
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: jest.fn(),
|
||||
saveCache: jest.fn(),
|
||||
isFeatureAvailable: jest.fn(() => true),
|
||||
ReserveCacheError: class ReserveCacheError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ReserveCacheError";
|
||||
}
|
||||
}
|
||||
}));
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const cache = await import("@actions/cache");
|
||||
const { Events, RefKey } = await import("../src/constants");
|
||||
const { restoreOnlyRun } = await import("../src/restoreImpl");
|
||||
const testUtils = await import("../src/utils/testUtils");
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(core.getInput as jest.Mock).mockImplementation(
|
||||
(name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||
"";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
beforeAll(() => {
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isExactKeyMatch(key, cacheResult);
|
||||
}
|
||||
);
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||
|
||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isValidEvent();
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsBool(name, options);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
process.env[Events.Key] = Events.Push;
|
||||
process.env[RefKey] = "refs/heads/feature-branch";
|
||||
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => true
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -78,12 +63,19 @@ test("restore with no cache found", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const outputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreOnlyRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.restoreCache).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
@@ -93,10 +85,11 @@ test("restore with no cache found", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(1);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(outputMock).toHaveBeenCalledTimes(1);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}`
|
||||
);
|
||||
});
|
||||
@@ -112,14 +105,32 @@ test("restore with restore keys and no cache found", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const outputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
|
||||
await restoreOnlyRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache not found for input keys: ${key}, ${restoreKey}`
|
||||
);
|
||||
});
|
||||
@@ -133,17 +144,36 @@ test("restore with cache found for key", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(key);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const outputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(key);
|
||||
});
|
||||
|
||||
await restoreOnlyRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-matched-key", key);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(3);
|
||||
expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-hit", "true");
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-matched-key", key);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledTimes(3);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("restore with cache found for restore key", async () => {
|
||||
@@ -157,20 +187,36 @@ test("restore with cache found for restore key", async () => {
|
||||
enableCrossOsArchive: false
|
||||
});
|
||||
|
||||
(cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const outputMock = jest.spyOn(core, "setOutput");
|
||||
const restoreCacheMock = jest
|
||||
.spyOn(cache, "restoreCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(restoreKey);
|
||||
});
|
||||
|
||||
await restoreOnlyRun();
|
||||
|
||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(core.setOutput).toHaveBeenCalledWith(
|
||||
"cache-matched-key",
|
||||
restoreKey
|
||||
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheMock).toHaveBeenCalledWith(
|
||||
[path],
|
||||
key,
|
||||
[restoreKey],
|
||||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(3);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-hit", "false");
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledTimes(3);
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache restored from key: ${restoreKey}`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
@@ -1,66 +1,70 @@
|
||||
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import { saveRun } from "../src/saveImpl";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
// Mock @actions/cache
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: jest.fn(),
|
||||
saveCache: jest.fn(),
|
||||
isFeatureAvailable: jest.fn(() => true),
|
||||
ReserveCacheError: class ReserveCacheError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ReserveCacheError";
|
||||
}
|
||||
}
|
||||
}));
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const cache = await import("@actions/cache");
|
||||
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||
const { saveRun } = await import("../src/saveImpl");
|
||||
const testUtils = await import("../src/utils/testUtils");
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
return jest.requireActual("@actions/core").getInput(name, options);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(core.getInput as jest.Mock).mockImplementation(
|
||||
(name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||
"";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
jest.spyOn(core, "getState").mockImplementation(name => {
|
||||
return jest.requireActual("@actions/core").getState(name);
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsInt(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsBool(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.isExactKeyMatch(key, cacheResult);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isValidEvent();
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
process.env[Events.Key] = Events.Push;
|
||||
process.env[RefKey] = "refs/heads/feature-branch";
|
||||
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => true
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -70,24 +74,36 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
test("save with valid inputs uploads a cache", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(primaryKey)
|
||||
.mockReturnValueOnce(savedCacheKey);
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return primaryKey;
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return savedCacheKey;
|
||||
});
|
||||
|
||||
const inputPath = "node_modules";
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||
|
||||
const cacheId = 4;
|
||||
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveRun();
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
@@ -96,5 +112,5 @@ test("save with valid inputs uploads a cache", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import { saveImpl } from "../src/saveImpl";
|
||||
import { StateProvider } from "../src/stateProvider";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
// Mock @actions/cache
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: jest.fn(),
|
||||
saveCache: jest.fn(),
|
||||
isFeatureAvailable: jest.fn(() => true),
|
||||
ReserveCacheError: class ReserveCacheError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ReserveCacheError";
|
||||
}
|
||||
}
|
||||
}));
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const cache = await import("@actions/cache");
|
||||
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||
const { saveImpl } = await import("../src/saveImpl");
|
||||
const { StateProvider } = await import("../src/stateProvider");
|
||||
const testUtils = await import("../src/utils/testUtils");
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
return jest.requireActual("@actions/core").getInput(name, options);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(core.getInput as jest.Mock).mockImplementation(
|
||||
(name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||
"";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
(core.getState as jest.Mock).mockReturnValue("");
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsInt(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsBool(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.isExactKeyMatch(key, cacheResult);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isValidEvent();
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
process.env[Events.Key] = Events.Push;
|
||||
process.env[RefKey] = "refs/heads/feature-branch";
|
||||
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => true
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -72,61 +72,99 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
test("save with invalid event outputs warning", async () => {
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const invalidEvent = "commit_comment";
|
||||
process.env[Events.Key] = invalidEvent;
|
||||
delete process.env[RefKey];
|
||||
await saveImpl(new StateProvider());
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
`[warning]Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with no primary key in state outputs warning", async () => {
|
||||
(core.getState as jest.Mock).mockReturnValue("");
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const savedCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return "";
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return savedCacheKey;
|
||||
});
|
||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(`[warning]Key is not specified.`);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(logWarningMock).toHaveBeenCalledWith(`Key is not specified.`);
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save without AC available should no-op", async () => {
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => false
|
||||
);
|
||||
|
||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save on ghes without AC available should no-op", async () => {
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => false
|
||||
);
|
||||
|
||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||
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-";
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(primaryKey)
|
||||
.mockReturnValueOnce(savedCacheKey);
|
||||
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;
|
||||
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
@@ -135,135 +173,229 @@ test("save on GHES with AC available", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with exact match returns early", async () => {
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(primaryKey)
|
||||
.mockReturnValueOnce(primaryKey);
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = primaryKey;
|
||||
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return savedCacheKey;
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return primaryKey;
|
||||
});
|
||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with missing input outputs warning", async () => {
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(savedCacheKey)
|
||||
.mockReturnValueOnce(primaryKey);
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return savedCacheKey;
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return primaryKey;
|
||||
});
|
||||
const saveCacheMock = jest.spyOn(cache, "saveCache");
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(0);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
"[warning]Input required and not supplied: path"
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
"Input required and not supplied: path"
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with large cache outputs warning", async () => {
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(savedCacheKey)
|
||||
.mockReturnValueOnce(primaryKey);
|
||||
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);
|
||||
|
||||
(cache.saveCache as jest.Mock).mockRejectedValue(
|
||||
new Error(
|
||||
"Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
||||
)
|
||||
);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
throw new Error(
|
||||
"Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
||||
);
|
||||
});
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
"[warning]Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
expect.anything(),
|
||||
false
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
"Cache size of ~6144 MB (6442450944 B) is over the 5GB limit, not saving cache."
|
||||
);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with reserve cache failure outputs warning", async () => {
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(savedCacheKey)
|
||||
.mockReturnValueOnce(primaryKey);
|
||||
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);
|
||||
|
||||
(cache.saveCache as jest.Mock).mockRejectedValue(
|
||||
new Error(
|
||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||
)
|
||||
);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
const actualCache = jest.requireActual("@actions/cache");
|
||||
const error = new actualCache.ReserveCacheError(
|
||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||
);
|
||||
throw error;
|
||||
});
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
`[warning]Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
expect.anything(),
|
||||
false
|
||||
);
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||
);
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with server error outputs warning", async () => {
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(savedCacheKey)
|
||||
.mockReturnValueOnce(primaryKey);
|
||||
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);
|
||||
|
||||
(cache.saveCache as jest.Mock).mockRejectedValue(
|
||||
new Error("HTTP Error Occurred")
|
||||
);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
throw new Error("HTTP Error Occurred");
|
||||
});
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(core.info).toHaveBeenCalledWith("[warning]HTTP Error Occurred");
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
expect.anything(),
|
||||
false
|
||||
);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with valid inputs uploads a cache", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
(core.getState as jest.Mock)
|
||||
.mockReturnValueOnce(primaryKey)
|
||||
.mockReturnValueOnce(savedCacheKey);
|
||||
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;
|
||||
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
@@ -272,5 +404,5 @@ test("save with valid inputs uploads a cache", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
@@ -1,66 +1,70 @@
|
||||
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import { saveOnlyRun } from "../src/saveImpl";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
// Mock @actions/cache
|
||||
jest.unstable_mockModule("@actions/cache", () => ({
|
||||
restoreCache: jest.fn(),
|
||||
saveCache: jest.fn(),
|
||||
isFeatureAvailable: jest.fn(() => true),
|
||||
ReserveCacheError: class ReserveCacheError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ReserveCacheError";
|
||||
}
|
||||
}
|
||||
}));
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const cache = await import("@actions/cache");
|
||||
const { Events, Inputs, RefKey } = await import("../src/constants");
|
||||
const { saveOnlyRun } = await import("../src/saveImpl");
|
||||
const testUtils = await import("../src/utils/testUtils");
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
return jest.requireActual("@actions/core").getInput(name, options);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(core.getInput as jest.Mock).mockImplementation(
|
||||
(name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||
"";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
jest.spyOn(core, "setOutput").mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").getInput(key, value);
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsInt(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsBool(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.isExactKeyMatch(key, cacheResult);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isValidEvent();
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
process.env[Events.Key] = Events.Push;
|
||||
process.env[RefKey] = "refs/heads/feature-branch";
|
||||
|
||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||
() => true
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -70,6 +74,8 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
test("save with valid inputs uploads a cache", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
|
||||
const inputPath = "node_modules";
|
||||
@@ -78,12 +84,16 @@ test("save with valid inputs uploads a cache", async () => {
|
||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||
|
||||
const cacheId = 4;
|
||||
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveOnlyRun();
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
@@ -92,10 +102,12 @@ test("save with valid inputs uploads a cache", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save failing logs the warning message", async () => {
|
||||
const warningMock = jest.spyOn(core, "warning");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
|
||||
const inputPath = "node_modules";
|
||||
@@ -104,12 +116,16 @@ test("save failing logs the warning message", async () => {
|
||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||
|
||||
const cacheId = -1;
|
||||
(cache.saveCache as jest.Mock).mockResolvedValue(cacheId);
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveOnlyRun();
|
||||
|
||||
expect(cache.saveCache).toHaveBeenCalledTimes(1);
|
||||
expect(cache.saveCache).toHaveBeenCalledWith(
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
@@ -118,6 +134,6 @@ test("save failing logs the warning message", async () => {
|
||||
false
|
||||
);
|
||||
|
||||
expect(core.warning).toHaveBeenCalledTimes(1);
|
||||
expect(core.warning).toHaveBeenCalledWith("Cache save failed.");
|
||||
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||
expect(warningMock).toHaveBeenCalledWith("Cache save failed.");
|
||||
});
|
||||
|
||||
@@ -1,41 +1,22 @@
|
||||
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import type { IStateProvider } from "../src/stateProvider";
|
||||
import { Events, RefKey, State } from "../src/constants";
|
||||
import {
|
||||
IStateProvider,
|
||||
NullStateProvider,
|
||||
StateProvider
|
||||
} from "../src/stateProvider";
|
||||
|
||||
// Mock @actions/core
|
||||
jest.unstable_mockModule("@actions/core", () => ({
|
||||
getInput: jest.fn((name: string, options?: { required?: boolean }) => {
|
||||
const val =
|
||||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
|
||||
if (options && options.required && !val) {
|
||||
throw new Error(`Input required and not supplied: ${name}`);
|
||||
}
|
||||
return val.trim();
|
||||
}),
|
||||
setOutput: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
saveState: jest.fn(),
|
||||
getState: jest.fn(() => ""),
|
||||
isDebug: jest.fn(() => false),
|
||||
exportVariable: jest.fn(),
|
||||
addPath: jest.fn(),
|
||||
group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
|
||||
startGroup: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}));
|
||||
jest.mock("@actions/core");
|
||||
|
||||
const core = await import("@actions/core");
|
||||
const { Events, RefKey, State } = await import("../src/constants");
|
||||
const { NullStateProvider, StateProvider } =
|
||||
await import("../src/stateProvider");
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
return jest.requireActual("@actions/core").getInput(name, options);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(core.getState as jest.Mock).mockReturnValue("");
|
||||
jest.spyOn(core, "setOutput").mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -45,14 +26,21 @@ afterEach(() => {
|
||||
|
||||
test("StateProvider saves states", async () => {
|
||||
const states = new Map<string, string>();
|
||||
(core.getState as jest.Mock).mockImplementation(
|
||||
(key: string) => states.get(key) || ""
|
||||
);
|
||||
(core.saveState as jest.Mock).mockImplementation(
|
||||
(key: string, value: string) => {
|
||||
const getStateMock = jest
|
||||
.spyOn(core, "getState")
|
||||
.mockImplementation(key => states.get(key) || "");
|
||||
|
||||
const saveStateMock = jest
|
||||
.spyOn(core, "saveState")
|
||||
.mockImplementation((key, value) => {
|
||||
states.set(key, value);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const setOutputMock = jest
|
||||
.spyOn(core, "setOutput")
|
||||
.mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
||||
});
|
||||
|
||||
const cacheMatchedKey = "node-cache";
|
||||
|
||||
@@ -64,19 +52,38 @@ test("StateProvider saves states", async () => {
|
||||
|
||||
expect(stateValue).toBe("stateValue");
|
||||
expect(cacheStateValue).toBe(cacheMatchedKey);
|
||||
expect(core.getState).toHaveBeenCalledTimes(2);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(2);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(0);
|
||||
expect(getStateMock).toHaveBeenCalledTimes(2);
|
||||
expect(saveStateMock).toHaveBeenCalledTimes(2);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("NullStateProvider saves outputs", async () => {
|
||||
const getStateMock = jest
|
||||
.spyOn(core, "getState")
|
||||
.mockImplementation(name =>
|
||||
jest.requireActual("@actions/core").getState(name)
|
||||
);
|
||||
|
||||
const setOutputMock = jest
|
||||
.spyOn(core, "setOutput")
|
||||
.mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").setOutput(key, value);
|
||||
});
|
||||
|
||||
const saveStateMock = jest
|
||||
.spyOn(core, "saveState")
|
||||
.mockImplementation((key, value) => {
|
||||
return jest.requireActual("@actions/core").saveState(key, value);
|
||||
});
|
||||
|
||||
const cacheMatchedKey = "node-cache";
|
||||
const nullStateProvider: IStateProvider = new NullStateProvider();
|
||||
nullStateProvider.setState(State.CacheMatchedKey, "outputValue");
|
||||
nullStateProvider.setState(State.CachePrimaryKey, "node-cache");
|
||||
nullStateProvider.setState(State.CachePrimaryKey, cacheMatchedKey);
|
||||
nullStateProvider.getState("outputKey");
|
||||
nullStateProvider.getCacheState();
|
||||
|
||||
expect(core.getState).toHaveBeenCalledTimes(0);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(2);
|
||||
expect(core.saveState).toHaveBeenCalledTimes(0);
|
||||
expect(getStateMock).toHaveBeenCalledTimes(0);
|
||||
expect(setOutputMock).toHaveBeenCalledTimes(2);
|
||||
expect(saveStateMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ This document lists some of the strategies (and example workflows if possible) w
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
key: ${{ some-metadata }}-cache
|
||||
```
|
||||
@@ -24,7 +24,7 @@ In your workflows, you can use different strategies to name your key depending o
|
||||
One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile.
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -37,7 +37,7 @@ One of the most common use case is to use hash for lockfile as key. This way, sa
|
||||
If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time.
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -54,7 +54,7 @@ The restore keys can be provided as a complete name, or a prefix, read more [her
|
||||
In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS.
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -73,7 +73,7 @@ Caches scoped to the particular workflow run id or run attempt can be stored and
|
||||
On similar lines, commit sha can be used to create a very specialized and short lived cache.
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -86,7 +86,7 @@ On similar lines, commit sha can be used to create a very specialized and short
|
||||
Cache key can be formed by combination of more than one metadata, evaluated info.
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -148,7 +148,7 @@ In case you are using a centralized job to create and save your cache that can b
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/cache/restore@v6
|
||||
- uses: actions/cache/restore@v5
|
||||
id: cache
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
@@ -173,7 +173,7 @@ You can use the output of this action to exit the workflow on cache miss. This w
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/cache/restore@v6
|
||||
- uses: actions/cache/restore@v5
|
||||
id: cache
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
@@ -194,7 +194,7 @@ steps:
|
||||
If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action.
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache/restore@v6
|
||||
- uses: actions/cache/restore@v5
|
||||
id: restore-cache
|
||||
with:
|
||||
path: |
|
||||
@@ -204,7 +204,7 @@ If you want to avoid re-computing the cache key again in `save` action, the outp
|
||||
.
|
||||
.
|
||||
.
|
||||
- uses: actions/cache/save@v6
|
||||
- uses: actions/cache/save@v5
|
||||
with:
|
||||
path: |
|
||||
path/to/dependencies
|
||||
@@ -219,7 +219,7 @@ On the other hand, the key can also be explicitly re-computed while executing th
|
||||
Let's say we have a restore step that computes key at runtime
|
||||
|
||||
```yaml
|
||||
uses: actions/cache/restore@v6
|
||||
uses: actions/cache/restore@v5
|
||||
id: restore-cache
|
||||
with:
|
||||
key: cache-${{ hashFiles('**/lockfiles') }}
|
||||
@@ -228,7 +228,7 @@ with:
|
||||
Case 1: Where an user would want to reuse the key as it is
|
||||
|
||||
```yaml
|
||||
uses: actions/cache/save@v6
|
||||
uses: actions/cache/save@v5
|
||||
with:
|
||||
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
|
||||
```
|
||||
@@ -236,7 +236,7 @@ with:
|
||||
Case 2: Where the user would want to re-evaluate the key
|
||||
|
||||
```yaml
|
||||
uses: actions/cache/save@v6
|
||||
uses: actions/cache/save@v5
|
||||
with:
|
||||
key: npm-cache-${{hashfiles(package-lock.json)}}
|
||||
```
|
||||
@@ -258,7 +258,7 @@ steps:
|
||||
- name: Build
|
||||
run: ./build-parent-module.sh
|
||||
|
||||
- uses: actions/cache/save@v6
|
||||
- uses: actions/cache/save@v5
|
||||
id: cache
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
@@ -271,7 +271,7 @@ steps:
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: actions/cache/restore@v6
|
||||
- uses: actions/cache/restore@v5
|
||||
id: cache
|
||||
with:
|
||||
path: path/to/dependencies
|
||||
|
||||
7927
dist/restore-only/index.js
vendored
7927
dist/restore-only/index.js
vendored
File diff suppressed because it is too large
Load Diff
7927
dist/restore/index.js
vendored
7927
dist/restore/index.js
vendored
File diff suppressed because it is too large
Load Diff
7927
dist/save-only/index.js
vendored
7927
dist/save-only/index.js
vendored
File diff suppressed because it is too large
Load Diff
7927
dist/save/index.js
vendored
7927
dist/save/index.js
vendored
File diff suppressed because it is too large
Load Diff
90
examples.md
90
examples.md
@@ -45,7 +45,7 @@
|
||||
## Bun
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.bun/install/cache
|
||||
@@ -55,7 +55,7 @@
|
||||
### Windows
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~\.bun
|
||||
@@ -67,7 +67,7 @@
|
||||
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||
@@ -79,7 +79,7 @@ Depending on the environment, huge packages might be pre-installed in the global
|
||||
From `actions/cache@v3` onwards, you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.nuget/packages
|
||||
@@ -96,7 +96,7 @@ Or you could move the cache folder like below.
|
||||
env:
|
||||
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
|
||||
steps:
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ${{ github.workspace }}/.nuget/packages
|
||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
||||
@@ -108,7 +108,7 @@ steps:
|
||||
|
||||
```yaml
|
||||
- name: Cache lein project dependencies
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-clojure-${{ hashFiles('**/project.clj') }}
|
||||
@@ -122,7 +122,7 @@ steps:
|
||||
### POSIX
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.dub
|
||||
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
|
||||
@@ -133,7 +133,7 @@ steps:
|
||||
### Windows
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ~\AppData\Local\dub
|
||||
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
|
||||
@@ -146,7 +146,7 @@ steps:
|
||||
### Linux
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.deno
|
||||
@@ -157,7 +157,7 @@ steps:
|
||||
### macOS
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.deno
|
||||
@@ -168,7 +168,7 @@ steps:
|
||||
### Windows
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~\.deno
|
||||
@@ -179,7 +179,7 @@ steps:
|
||||
## Elixir - Mix
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
deps
|
||||
@@ -191,7 +191,7 @@ steps:
|
||||
|
||||
## Erlang - Rebar3
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.cache/rebar3
|
||||
@@ -206,7 +206,7 @@ steps:
|
||||
### Linux
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
@@ -219,7 +219,7 @@ steps:
|
||||
### macOS
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/Library/Caches/go-build
|
||||
@@ -232,7 +232,7 @@ steps:
|
||||
### Windows
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~\AppData\Local\go-build
|
||||
@@ -248,7 +248,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
||||
|
||||
```yaml
|
||||
- name: Cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.cabal/packages
|
||||
@@ -263,14 +263,14 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
||||
### Linux or macOS
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
name: Cache ~/.stack
|
||||
with:
|
||||
path: ~/.stack
|
||||
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-stack-global-
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
name: Cache .stack-work
|
||||
with:
|
||||
path: .stack-work
|
||||
@@ -282,7 +282,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
||||
### Windows
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack
|
||||
with:
|
||||
path: |
|
||||
@@ -291,7 +291,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
||||
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-stack-global-
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
name: Cache .stack-work
|
||||
with:
|
||||
path: .stack-work
|
||||
@@ -305,7 +305,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
||||
> **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons.
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
@@ -319,7 +319,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
|
||||
|
||||
```yaml
|
||||
- name: Cache local Maven repository
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
@@ -355,7 +355,7 @@ After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-depr
|
||||
`Get npm cache directory` step can then be used with `actions/cache` as shown below
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
|
||||
with:
|
||||
path: ${{ steps.npm-cache-dir.outputs.dir }}
|
||||
@@ -368,7 +368,7 @@ After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-depr
|
||||
|
||||
```yaml
|
||||
- name: restore lerna
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
|
||||
@@ -382,7 +382,7 @@ The yarn cache directory will depend on your operating system and version of `ya
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
@@ -400,7 +400,7 @@ The yarn 2 cache directory will depend on your config. See https://yarnpkg.com/c
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
@@ -415,7 +415,7 @@ Esy allows you to export built dependencies and import pre-built dependencies.
|
||||
```yaml
|
||||
- name: Restore Cache
|
||||
id: restore-cache
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: _export
|
||||
key: ${{ runner.os }}-esy-${{ hashFiles('esy.lock/index.json') }}
|
||||
@@ -444,7 +444,7 @@ Esy allows you to export built dependencies and import pre-built dependencies.
|
||||
id: composer-cache
|
||||
run: |
|
||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
||||
@@ -465,7 +465,7 @@ Locations:
|
||||
### Simple example
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||
@@ -478,7 +478,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
||||
### Multiple OS's in a workflow
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
if: startsWith(runner.os, 'Linux')
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
@@ -486,7 +486,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
if: startsWith(runner.os, 'macOS')
|
||||
with:
|
||||
path: ~/Library/Caches/pip
|
||||
@@ -494,7 +494,7 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
if: startsWith(runner.os, 'Windows')
|
||||
with:
|
||||
path: ~\AppData\Local\pip\Cache
|
||||
@@ -520,7 +520,7 @@ jobs:
|
||||
- os: windows-latest
|
||||
path: ~\AppData\Local\pip\Cache
|
||||
steps:
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ${{ matrix.path }}
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||
@@ -539,7 +539,7 @@ jobs:
|
||||
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: pip cache
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ${{ steps.pip-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||
@@ -557,7 +557,7 @@ jobs:
|
||||
|
||||
⋮
|
||||
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.local/share/virtualenvs
|
||||
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
|
||||
@@ -584,7 +584,7 @@ For renv, the cache directory will vary by OS. The `RENV_PATHS_ROOT` environment
|
||||
cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
|
||||
shell: Rscript {0}
|
||||
- name: Restore Renv package cache
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ${{ env.RENV_PATHS_ROOT }}
|
||||
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}
|
||||
@@ -610,7 +610,7 @@ whenever possible:
|
||||
## Rust - Cargo
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
@@ -625,7 +625,7 @@ whenever possible:
|
||||
|
||||
```yaml
|
||||
- name: Cache SBT
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.ivy2/cache
|
||||
@@ -636,7 +636,7 @@ whenever possible:
|
||||
## Swift, Objective-C - Carthage
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: Carthage
|
||||
key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
|
||||
@@ -647,7 +647,7 @@ whenever possible:
|
||||
## Swift, Objective-C - CocoaPods
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: Pods
|
||||
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
|
||||
@@ -658,7 +658,7 @@ whenever possible:
|
||||
## Swift - Swift Package Manager
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: .build
|
||||
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
|
||||
@@ -673,7 +673,7 @@ env:
|
||||
MINT_PATH: .mint/lib
|
||||
MINT_LINK_PATH: .mint/bin
|
||||
steps:
|
||||
- uses: actions/cache@v6
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
path: .mint
|
||||
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
|
||||
@@ -689,7 +689,7 @@ steps:
|
||||
|
||||
```yaml
|
||||
- name: Cache Bazel
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.cache/bazel
|
||||
@@ -703,7 +703,7 @@ steps:
|
||||
|
||||
```yaml
|
||||
- name: Cache Bazel
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
/private/var/tmp/_bazel_runner/
|
||||
|
||||
23
jest.config.js
Normal file
23
jest.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
require("nock").disableNetConnect();
|
||||
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ["js", "ts"],
|
||||
testEnvironment: "node",
|
||||
testMatch: ["**/*.test.ts"],
|
||||
testRunner: "jest-circus/runner",
|
||||
transform: {
|
||||
"^.+\\.ts$": "ts-jest"
|
||||
},
|
||||
verbose: true
|
||||
};
|
||||
|
||||
const processStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
process.stdout.write = (str, encoding, cb) => {
|
||||
// Core library will directly call process.stdout.write for commands
|
||||
// We don't want :: commands to be executed by the runner during tests
|
||||
if (!String(str).match(/^::/)) {
|
||||
return processStdoutWrite(str, encoding, cb);
|
||||
}
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
export default {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
roots: ['<rootDir>/__tests__'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
transform: {
|
||||
'^.+\\.ts$': [
|
||||
'ts-jest',
|
||||
{
|
||||
useESM: true,
|
||||
diagnostics: {
|
||||
ignoreCodes: [151002]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
extensionsToTreatAsEsm: ['.ts'],
|
||||
transformIgnorePatterns: ['node_modules/(?!(@actions)/)'],
|
||||
verbose: true
|
||||
}
|
||||
2550
package-lock.json
generated
2550
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@@ -1,13 +1,12 @@
|
||||
{
|
||||
"name": "cache",
|
||||
"version": "6.0.0",
|
||||
"version": "5.0.4",
|
||||
"private": true,
|
||||
"description": "Cache dependencies and build outputs",
|
||||
"type": "module",
|
||||
"main": "dist/restore/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc && ncc build -o dist/restore src/restore.ts && ncc build -o dist/save src/save.ts && ncc build -o dist/restore-only src/restoreOnly.ts && ncc build -o dist/save-only src/saveOnly.ts",
|
||||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
||||
"test": "tsc --noEmit && jest --coverage",
|
||||
"lint": "eslint **/*.ts --cache",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts"
|
||||
@@ -24,13 +23,13 @@
|
||||
"author": "GitHub",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^6.0.1",
|
||||
"@actions/core": "^3.0.1",
|
||||
"@actions/exec": "^3.0.0",
|
||||
"@actions/io": "^3.0.2"
|
||||
"@actions/cache": "^5.0.5",
|
||||
"@actions/core": "^2.0.3",
|
||||
"@actions/exec": "^2.0.0",
|
||||
"@actions/io": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/nock": "^11.1.0",
|
||||
"@types/node": "^24.1.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
||||
@@ -42,11 +41,11 @@
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-prettier": "^5.5.3",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"jest": "^30.2.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"nock": "^13.2.9",
|
||||
"prettier": "^3.6.2",
|
||||
"ts-jest": "^29.4.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -12,7 +12,7 @@ A cache today is immutable and cannot be updated. But some use cases require the
|
||||
|
||||
```yaml
|
||||
- name: update cache on every commit
|
||||
uses: actions/cache@v6
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: prime-numbers
|
||||
key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well
|
||||
|
||||
@@ -1,13 +1,63 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"moduleResolution": "bundler",
|
||||
"esModuleInterop": true
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts", "jest.config.ts", "__tests__"]
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user