Compare commits

...
Author SHA1 Message Date
dependabot[bot] 97a407914f build(deps): bump the minor-actions-dependencies group across 1 directory with 2 updates
Bumps the minor-actions-dependencies group with 2 updates in the / directory: [actions/publish-immutable-action](https://github.com/actions/publish-immutable-action) and [actions/publish-action](https://github.com/actions/publish-action).


Updates `actions/publish-immutable-action` from 0.0.3 to 0.0.4
- [Release notes](https://github.com/actions/publish-immutable-action/releases)
- [Commits](https://github.com/actions/publish-immutable-action/compare/0.0.3...v0.0.4)

Updates `actions/publish-action` from 0.3.0 to 0.4.0
- [Commits](https://github.com/actions/publish-action/compare/v0.3.0...v0.4.0)

---
updated-dependencies:
- dependency-name: actions/publish-action
  dependency-version: 0.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: minor-actions-dependencies
- dependency-name: actions/publish-immutable-action
  dependency-version: 0.0.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: minor-actions-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>
2026-06-29 21:13:29 +00:00
Daniel Kennedy 55cc834586 Merge pull request #1768 from jasongin/readonly-cache
Bump @actions/cache to v6.1.0 - handle read-only cache access
2026-06-23 16:30:28 -04:00
Jason Ginchereau d8cd72f230 Bump @actions/cache to v6.1.0 - handle cache write error due to RO token 2026-06-23 13:13:25 -07:00
Joshua Brooks 2c8a9bd745 Merge pull request #1760 from actions/samirat/esm_migration_and_package_update
Update packages, migrate to ESM
2026-06-23 10:42:53 -04:00
Joshua Brooks e9b91fdc3f Prettier fixes 2026-06-11 16:23:52 +00:00
Joshua Brooks e4884b8ff7 Rebuild dist 2026-06-11 15:59:57 +00:00
Joshua Brooks 10baf0191a Fixed licenses 2026-06-11 15:50:44 +00:00
Joshua Brooks e39b386c90 Fix test mock return order 2026-06-11 15:08:26 +00:00
Joshua Brooks b692820337 PR feedback 2026-06-11 14:46:05 +00:00
Joshua Brooks 60749128a4 Rebuild dist bundles as ESM to match type:module 2026-06-11 14:22:50 +00:00
Joshua Brooks 5a912e8b4a Fix lint and jest issues 2026-05-20 20:18:29 +00:00
Joshua Brooks b9bf592b98 Update documentation for v6 release 2026-05-20 19:47:09 +00:00
Joshua Brooks 80f777761d Update packages, migrate to ESM 2026-05-20 19:31:39 +00:00
53 changed files with 218144 additions and 187774 deletions
@@ -17,4 +17,4 @@ jobs:
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: Publish - name: Publish
id: publish id: publish
uses: actions/[email protected].3 uses: actions/publish-immutable-action@v0.0.4
@@ -24,7 +24,7 @@ jobs:
steps: steps:
- name: Update the ${{ env.TAG_NAME }} tag - name: Update the ${{ env.TAG_NAME }} tag
id: update-major-tag id: update-major-tag
uses: actions/publish-action@v0.3.0 uses: actions/publish-action@v0.4.0
with: with:
source-tag: ${{ env.TAG_NAME }} source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }} slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@actions/cache" name: "@actions/cache"
version: 5.0.5 version: 6.1.0
type: npm type: npm
summary: Actions cache lib summary: Actions cache lib
homepage: https://github.com/actions/toolkit/tree/main/packages/cache homepage: https://github.com/actions/toolkit/tree/main/packages/cache
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@actions/core" name: "@actions/core"
version: 2.0.3 version: 3.0.1
type: npm type: npm
summary: Actions core lib summary: Actions core lib
homepage: https://github.com/actions/toolkit/tree/main/packages/core homepage: https://github.com/actions/toolkit/tree/main/packages/core
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@actions/exec" name: "@actions/exec"
version: 2.0.0 version: 3.0.0
type: npm type: npm
summary: Actions exec lib summary: Actions exec lib
homepage: https://github.com/actions/toolkit/tree/main/packages/exec homepage: https://github.com/actions/toolkit/tree/main/packages/exec
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@actions/glob" name: "@actions/glob"
version: 0.5.1 version: 0.6.1
type: npm type: npm
summary: Actions glob lib summary: Actions glob lib
homepage: https://github.com/actions/toolkit/tree/main/packages/glob homepage: https://github.com/actions/toolkit/tree/main/packages/glob
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@actions/http-client" name: "@actions/http-client"
version: 3.0.2 version: 4.0.1
type: npm type: npm
summary: Actions Http Client summary: Actions Http Client
homepage: https://github.com/actions/toolkit/tree/main/packages/http-client homepage: https://github.com/actions/toolkit/tree/main/packages/http-client
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@actions/io" name: "@actions/io"
version: 2.0.0 version: 3.0.2
type: npm type: npm
summary: Actions io lib summary: Actions io lib
homepage: https://github.com/actions/toolkit/tree/main/packages/io homepage: https://github.com/actions/toolkit/tree/main/packages/io
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@azure/core-client" name: "@azure/core-client"
version: 1.10.1 version: 1.10.2
type: npm type: npm
summary: Core library for interfacing with AutoRest generated code summary: Core library for interfacing with AutoRest generated code
homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-client/ homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-client/
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@azure/core-http-compat" name: "@azure/core-http-compat"
version: 2.3.1 version: 2.4.0
type: npm type: npm
summary: Core HTTP Compatibility Library to bridge the gap between Core V1 & V2 packages. summary: Core HTTP Compatibility Library to bridge the gap between Core V1 & V2 packages.
homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-compat/ homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-compat/
+2 -2
View File
@@ -1,9 +1,9 @@
--- ---
name: "@azure/core-rest-pipeline" name: "@azure/core-rest-pipeline"
version: 1.22.2 version: 1.24.0
type: npm type: npm
summary: Isomorphic client library for making HTTP requests in node.js and browser. 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/core-rest-pipeline/ homepage: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-rest-pipeline/README.md
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: "@azure/core-xml" name: "@azure/core-xml"
version: 1.5.0 version: 1.5.1
type: npm type: npm
summary: Core library for interacting with XML payloads summary: Core library for interacting with XML payloads
homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-xml/ homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-xml/
+2 -2
View File
@@ -1,9 +1,9 @@
--- ---
name: "@azure/storage-blob" name: "@azure/storage-blob"
version: 12.30.0 version: 12.32.0
type: npm type: npm
summary: Microsoft Azure Storage SDK for JavaScript - Blob summary: Microsoft Azure Storage SDK for JavaScript - Blob
homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-blob/ homepage: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob/README.md
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
+2 -2
View File
@@ -1,9 +1,9 @@
--- ---
name: "@azure/storage-common" name: "@azure/storage-common"
version: 12.2.0 version: 12.4.0
type: npm type: npm
summary: Azure Storage Common Client Library for JavaScript summary: Azure Storage Common Client Library for JavaScript
homepage: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-internal-avro/ homepage: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-common/README.md
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
+11
View File
@@ -0,0 +1,11 @@
---
name: "@nodable/entities"
version: 2.2.0
type: npm
summary: Entity parser for XML, HTML, External entites with security and NCR control
homepage:
license: mit
licenses:
- sources: README.md
text: MIT
notices: []
+2 -2
View File
@@ -1,9 +1,9 @@
--- ---
name: "@typespec/ts-http-runtime" name: "@typespec/ts-http-runtime"
version: 0.3.5 version: 0.3.6
type: npm type: npm
summary: Isomorphic client library for making HTTP requests in node.js and browser. 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/ homepage: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/ts-http-runtime/README.md
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
@@ -1,16 +1,17 @@
--- ---
name: "@azure/abort-controller" name: anynum
version: 1.1.0 version: 1.0.1
type: npm type: npm
summary: Microsoft Azure SDK for JavaScript - Aborter summary: Normalize all Unicode decimal digits (Devanagari, Arabic, Thai, etc.) to
homepage: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/abort-controller/README.md ASCII numerals. Zero dependencies, performance-first.
homepage:
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
text: | text: |
The MIT License (MIT) MIT License
Copyright (c) 2020 Microsoft Copyright (c) 2026 Natural Intelligence
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@@ -29,4 +30,6 @@ licenses:
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
- sources: README.md
text: MIT
notices: [] notices: []
+2 -2
View File
@@ -1,9 +1,9 @@
--- ---
name: fast-xml-builder name: fast-xml-builder
version: 1.1.4 version: 1.2.0
type: npm type: npm
summary: Build XML from JSON without C/C++ based libraries summary: Build XML from JSON without C/C++ based libraries
homepage: homepage:
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
+2 -2
View File
@@ -1,9 +1,9 @@
--- ---
name: fast-xml-parser name: fast-xml-parser
version: 5.5.6 version: 5.9.2
type: npm type: npm
summary: Validate XML, Parse XML, Build XML without C/C++ based libraries summary: Validate XML, Parse XML, Build XML without C/C++ based libraries
homepage: homepage:
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
+35
View File
@@ -0,0 +1,35 @@
---
name: is-unsafe
version: 1.0.1
type: npm
summary: Zero-dependency, DOM-free, pure predicate for detecting unsafe strings across
HTML, XML, SVG, SQL, SHELL, and REGEX contexts
homepage:
license: mit
licenses:
- sources: LICENSE
text: |
MIT License
Copyright (c) 2026 Natural Intelligence
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- sources: README.md
text: MIT
notices: []
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: path-expression-matcher name: path-expression-matcher
version: 1.1.3 version: 1.5.0
type: npm type: npm
summary: Efficient path tracking and pattern matching for XML/JSON parsers summary: Efficient path tracking and pattern matching for XML/JSON parsers
homepage: https://github.com/NaturalIntelligence/path-expression-matcher#readme homepage: https://github.com/NaturalIntelligence/path-expression-matcher#readme
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: semver name: semver
version: 6.3.1 version: 7.8.5
type: npm type: npm
summary: The semantic version parser used by npm. summary: The semantic version parser used by npm.
homepage: homepage:
+2 -2
View File
@@ -1,9 +1,9 @@
--- ---
name: strnum name: strnum
version: 2.1.2 version: 2.4.1
type: npm type: npm
summary: Parse String to Number based on configuration summary: Parse String to Number based on configuration
homepage: homepage:
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
+1 -1
View File
@@ -1,6 +1,6 @@
--- ---
name: undici name: undici
version: 6.24.1 version: 6.27.0
type: npm type: npm
summary: An HTTP/1.1 client, written from scratch for Node.js summary: An HTTP/1.1 client, written from scratch for Node.js
homepage: https://undici.nodejs.org homepage: https://undici.nodejs.org
+12
View File
@@ -0,0 +1,12 @@
---
name: xml-naming
version: 0.1.0
type: npm
summary: Validates XML name productions — Name, NCName, QName, NMToken, NMTokens —
for XML 1.0 and 1.1
homepage:
license: mit
licenses:
- sources: README.md
text: MIT
notices: []
+25 -12
View File
@@ -33,11 +33,16 @@ If you do not upgrade, all workflow runs using any of the deprecated [actions/ca
Upgrading to the recommended versions will not break your workflows. Upgrading to the recommended versions will not break your workflows.
> **Additionally, if you are managing your own GitHub runners, you must update your runner version to `2.231.0` or newer to ensure compatibility with the new cache service.** > **Additionally, if you are managing your own GitHub runners, you must update your runner version to `2.231.0` or newer to ensure compatibility with the new cache service.**
> Failure to update both the action version and your runner version may result in workflow failures after the migration date. > Failure to update both the action version and your runner version may result in workflow failures after the migration date.
Read more about the change & access the migration guide: [reference to the announcement](https://github.com/actions/cache/discussions/1510). 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 ### v5
* Updated to node 24 * Updated to node 24
@@ -109,6 +114,14 @@ The cache is scoped to the key, [version](#cache-version), and branch. The defau
See [Matching a cache key](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) for more info. See [Matching a cache key](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) for more info.
### Read-only access
Some workflow runs only have read-only access to the cache. A common case is a workflow triggered by a pull request from a fork: such runs can **restore** existing caches but may not be permitted to **save** new ones.
When the cache token is read-only, the save step does not fail the job. Instead, `@actions/cache` reports the denial once as a warning (for example, `Failed to save: ... cache write denied: ...`) and the step completes successfully without writing a cache entry. Restores in the same run continue to work as usual.
> **Note** This applies to the action's normal save path as well as the standalone [Save action](./save/README.md). If you intentionally want a restore-only setup, see [Make cache read only / Reuse cache from centralized job](./caching-strategies.md#make-cache-read-only--reuse-cache-from-centralized-job).
### Example cache workflow ### Example cache workflow
#### Restoring and saving cache using a single action #### Restoring and saving cache using a single action
@@ -127,7 +140,7 @@ jobs:
- name: Cache Primes - name: Cache Primes
id: cache-primes id: cache-primes
uses: actions/cache@v5 uses: actions/cache@v6
with: with:
path: prime-numbers path: prime-numbers
key: ${{ runner.os }}-primes key: ${{ runner.os }}-primes
@@ -158,7 +171,7 @@ jobs:
- name: Restore cached Primes - name: Restore cached Primes
id: cache-primes-restore id: cache-primes-restore
uses: actions/cache/restore@v5 uses: actions/cache/restore@v6
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
@@ -169,7 +182,7 @@ jobs:
. .
- name: Save Primes - name: Save Primes
id: cache-primes-save id: cache-primes-save
uses: actions/cache/save@v5 uses: actions/cache/save@v6
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
@@ -224,7 +237,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. 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 ```yaml
- uses: actions/cache@v5 - uses: actions/cache@v6
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
@@ -242,7 +255,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 echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash shell: bash
- uses: actions/cache@v5 - uses: actions/cache@v6
with: with:
path: path/to/dependencies path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
@@ -264,7 +277,7 @@ Example:
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions/cache@v5 - uses: actions/cache@v6
id: cache id: cache
with: with:
path: path/to/dependencies path: path/to/dependencies
@@ -296,7 +309,7 @@ jobs:
- name: Cache Primes - name: Cache Primes
id: cache-primes id: cache-primes
uses: actions/cache@v5 uses: actions/cache@v6
with: with:
path: prime-numbers path: prime-numbers
key: primes key: primes
@@ -307,7 +320,7 @@ jobs:
- name: Cache Numbers - name: Cache Numbers
id: cache-numbers id: cache-numbers
uses: actions/cache@v5 uses: actions/cache@v6
with: with:
path: numbers path: numbers
key: primes key: primes
@@ -323,7 +336,7 @@ jobs:
- name: Cache Primes - name: Cache Primes
id: cache-primes id: cache-primes
uses: actions/cache@v5 uses: actions/cache@v6
with: with:
path: prime-numbers path: prime-numbers
key: primes key: primes
@@ -351,7 +364,7 @@ Please note that Windows environment variables (like `%LocalAppData%`) will NOT
## Note ## Note
Thank you for your interest in this GitHub repo, however, right now we are not taking contributions. Thank you for your interest in this GitHub repo, however, right now we are not taking contributions.
We continue to focus our resources on strategic areas that help our customers be successful while making developers' lives easier. While GitHub Actions remains a key part of this vision, we are allocating resources towards other areas of Actions and are not taking contributions to this repository at this time. The GitHub public roadmap is the best place to follow along for any updates on features we’re working on and what stage they’re in. We continue to focus our resources on strategic areas that help our customers be successful while making developers' lives easier. While GitHub Actions remains a key part of this vision, we are allocating resources towards other areas of Actions and are not taking contributions to this repository at this time. The GitHub public roadmap is the best place to follow along for any updates on features we’re working on and what stage they’re in.
@@ -369,4 +382,4 @@ You are welcome to still raise bugs in this repo.
## License ## License
The scripts and documentation in this project are released under the [MIT License](LICENSE) The scripts and documentation in this project are released under the [MIT License](LICENSE)
+13 -2
View File
@@ -2,7 +2,7 @@
## How to prepare a release ## How to prepare a release
> [!NOTE] > [!NOTE]
> Relevant for maintainers with write access only. > Relevant for maintainers with write access only.
1. Switch to a new branch from `main`. 1. Switch to a new branch from `main`.
@@ -21,10 +21,21 @@
1. Publish the release. 1. Publish the release.
1. Navigate to https://github.com/actions/cache/actions/workflows/release-new-action-version.yml 1. Navigate to https://github.com/actions/cache/actions/workflows/release-new-action-version.yml
1. There should be a workflow run queued with the same version number. 1. There should be a workflow run queued with the same version number.
1. Approve the run to publish the new version and update the major tags for this action. 1. Approve the run to publish the new version and update the major tags for this action.
## Changelog ## Changelog
### 6.1.0
- Bump `@actions/cache` to v6.1.0 to pick up [actions/toolkit#2435 Handle cache write error due to read-only token](https://github.com/actions/toolkit/pull/2435)
- Switch redundant "Cache save failed" warning to debug log in save-only
### 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 ### 5.0.4
- Bump `minimatch` to v3.1.5 (fixes ReDoS via globstar patterns) - Bump `minimatch` to v3.1.5 (fixes ReDoS via globstar patterns)
+83 -73
View File
@@ -1,25 +1,66 @@
import * as cache from "@actions/cache"; import { afterAll, beforeEach, expect, jest, test } from "@jest/globals";
import * as core from "@actions/core";
import { Events, RefKey } from "../src/constants"; // Mock @actions/core
import * as actionUtils from "../src/utils/actionUtils"; jest.unstable_mockModule("@actions/core", () => ({
import * as testUtils from "../src/utils/testUtils"; 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"); // Mock @actions/cache
jest.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");
let pristineEnv: NodeJS.ProcessEnv; let pristineEnv: NodeJS.ProcessEnv;
beforeAll(() => {
pristineEnv = process.env;
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
return jest.requireActual("@actions/core").getInput(name, options);
});
});
beforeEach(() => { beforeEach(() => {
jest.resetModules(); pristineEnv = { ...process.env };
process.env = pristineEnv; jest.clearAllMocks();
jest.mocked(core.getInput).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();
}
);
delete process.env[Events.Key]; delete process.env[Events.Key];
delete process.env[RefKey]; delete process.env[RefKey];
}); });
@@ -47,74 +88,46 @@ test("isGhes returns false when server url is github.com", () => {
}); });
test("isExactKeyMatch with undefined cache key returns false", () => { test("isExactKeyMatch with undefined cache key returns false", () => {
const key = "linux-rust"; expect(actionUtils.isExactKeyMatch("linux-rust", undefined)).toBe(false);
const cacheKey = undefined;
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
}); });
test("isExactKeyMatch with empty cache key returns false", () => { test("isExactKeyMatch with empty cache key returns false", () => {
const key = "linux-rust"; expect(actionUtils.isExactKeyMatch("linux-rust", "")).toBe(false);
const cacheKey = "";
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
}); });
test("isExactKeyMatch with different keys returns false", () => { test("isExactKeyMatch with different keys returns false", () => {
const key = "linux-rust"; expect(actionUtils.isExactKeyMatch("linux-rust", "linux-")).toBe(false);
const cacheKey = "linux-";
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
}); });
test("isExactKeyMatch with different key accents returns false", () => { test("isExactKeyMatch with different key accents returns false", () => {
const key = "linux-áccent"; expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe(
const cacheKey = "linux-accent"; false
);
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
}); });
test("isExactKeyMatch with same key returns true", () => { test("isExactKeyMatch with same key returns true", () => {
const key = "linux-rust"; expect(actionUtils.isExactKeyMatch("linux-rust", "linux-rust")).toBe(true);
const cacheKey = "linux-rust";
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
}); });
test("isExactKeyMatch with same key and different casing returns true", () => { test("isExactKeyMatch with same key and different casing returns true", () => {
const key = "linux-rust"; expect(actionUtils.isExactKeyMatch("linux-rust", "LINUX-RUST")).toBe(true);
const cacheKey = "LINUX-RUST";
expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
}); });
test("logWarning logs a message with a warning prefix", () => { test("logWarning logs a message with a warning prefix", () => {
const message = "A warning occurred."; const message = "A warning occurred.";
const infoMock = jest.spyOn(core, "info");
actionUtils.logWarning(message); 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", () => { test("isValidEvent returns false for event that does not have a branch or tag", () => {
const event = "foo"; process.env[Events.Key] = "foo";
process.env[Events.Key] = event; expect(actionUtils.isValidEvent()).toBe(false);
const isValidEvent = actionUtils.isValidEvent();
expect(isValidEvent).toBe(false);
}); });
test("isValidEvent returns true for event that has a ref", () => { test("isValidEvent returns true for event that has a ref", () => {
const event = Events.Push; process.env[Events.Key] = Events.Push;
process.env[Events.Key] = event;
process.env[RefKey] = "ref/heads/feature"; 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", () => { test("getInputAsArray returns empty array if not required and missing", () => {
@@ -124,7 +137,7 @@ test("getInputAsArray returns empty array if not required and missing", () => {
test("getInputAsArray throws error if required and missing", () => { test("getInputAsArray throws error if required and missing", () => {
expect(() => expect(() =>
actionUtils.getInputAsArray("foo", { required: true }) actionUtils.getInputAsArray("foo", { required: true })
).toThrowError(); ).toThrow();
}); });
test("getInputAsArray handles single line correctly", () => { test("getInputAsArray handles single line correctly", () => {
@@ -180,7 +193,7 @@ test("getInputAsInt returns undefined if input is invalid or NaN", () => {
test("getInputAsInt throws if required and value missing", () => { test("getInputAsInt throws if required and value missing", () => {
expect(() => expect(() =>
actionUtils.getInputAsInt("undefined", { required: true }) actionUtils.getInputAsInt("undefined", { required: true })
).toThrowError(); ).toThrow();
}); });
test("getInputAsBool returns false if input not set", () => { test("getInputAsBool returns false if input not set", () => {
@@ -200,68 +213,65 @@ test("getInputAsBool returns false if input is invalid or NaN", () => {
test("getInputAsBool throws if required and value missing", () => { test("getInputAsBool throws if required and value missing", () => {
expect(() => expect(() =>
actionUtils.getInputAsBool("undefined2", { required: true }) actionUtils.getInputAsBool("undefined2", { required: true })
).toThrowError(); ).toThrow();
}); });
test("isCacheFeatureAvailable for ac enabled", () => { test("isCacheFeatureAvailable for ac enabled", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true); jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
expect(actionUtils.isCacheFeatureAvailable()).toBe(true); expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
}); });
test("isCacheFeatureAvailable for ac disabled on GHES", () => { test("isCacheFeatureAvailable for ac disabled on GHES", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false); jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
const message = `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not. const 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/[email protected]/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)`; 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/[email protected]/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 { try {
process.env["GITHUB_SERVER_URL"] = "http://example.com"; process.env["GITHUB_SERVER_URL"] = "http://example.com";
expect(actionUtils.isCacheFeatureAvailable()).toBe(false); expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`); expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
} finally { } finally {
delete process.env["GITHUB_SERVER_URL"]; delete process.env["GITHUB_SERVER_URL"];
} }
}); });
test("isCacheFeatureAvailable for ac disabled on dotcom", () => { test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false); jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
const message = const message =
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions."; "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 { try {
process.env["GITHUB_SERVER_URL"] = "http://github.com"; process.env["GITHUB_SERVER_URL"] = "http://github.com";
expect(actionUtils.isCacheFeatureAvailable()).toBe(false); expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`); expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
} finally { } finally {
delete process.env["GITHUB_SERVER_URL"]; delete process.env["GITHUB_SERVER_URL"];
} }
}); });
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is not defined", async () => { test("isGhes returns false when the GITHUB_SERVER_URL environment variable is not defined", () => {
delete process.env["GITHUB_SERVER_URL"]; delete process.env["GITHUB_SERVER_URL"];
expect(actionUtils.isGhes()).toBeFalsy(); expect(actionUtils.isGhes()).toBeFalsy();
}); });
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to github.com", async () => { test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to github.com", () => {
process.env["GITHUB_SERVER_URL"] = "https://github.com"; process.env["GITHUB_SERVER_URL"] = "https://github.com";
expect(actionUtils.isGhes()).toBeFalsy(); expect(actionUtils.isGhes()).toBeFalsy();
}); });
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL", async () => { test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL", () => {
process.env["GITHUB_SERVER_URL"] = "https://contoso.ghe.com"; process.env["GITHUB_SERVER_URL"] = "https://contoso.ghe.com";
expect(actionUtils.isGhes()).toBeFalsy(); expect(actionUtils.isGhes()).toBeFalsy();
}); });
test("isGhes returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix", async () => { test("isGhes returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix", () => {
process.env["GITHUB_SERVER_URL"] = "https://mock-github.localhost"; process.env["GITHUB_SERVER_URL"] = "https://mock-github.localhost";
expect(actionUtils.isGhes()).toBeFalsy(); expect(actionUtils.isGhes()).toBeFalsy();
}); });
test("isGhes returns true when the GITHUB_SERVER_URL environment variable is set to some other URL", async () => { test("isGhes returns true when the GITHUB_SERVER_URL environment variable is set to some other URL", () => {
process.env["GITHUB_SERVER_URL"] = "https://src.onpremise.fabrikam.com"; process.env["GITHUB_SERVER_URL"] = "https://src.onpremise.fabrikam.com";
expect(actionUtils.isGhes()).toBeTruthy(); expect(actionUtils.isGhes()).toBeTruthy();
}); });
+108 -195
View File
@@ -1,50 +1,66 @@
import * as cache from "@actions/cache"; import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
import * as core from "@actions/core";
import { Events, RefKey } from "../src/constants"; // Mock @actions/core
import { restoreRun } from "../src/restoreImpl"; jest.unstable_mockModule("@actions/core", () => ({
import * as actionUtils from "../src/utils/actionUtils"; getInput: jest.fn((name: string, options?: { required?: boolean }) => {
import * as testUtils from "../src/utils/testUtils"; const val =
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
jest.mock("../src/utils/actionUtils"); if (options && options.required && !val) {
throw new Error(`Input required and not supplied: ${name}`);
beforeAll(() => {
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
(key, cacheResult) => {
const actualUtils = jest.requireActual("../src/utils/actionUtils");
return actualUtils.isExactKeyMatch(key, cacheResult);
} }
); 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.spyOn(actionUtils, "isValidEvent").mockImplementation(() => { // Mock @actions/cache
const actualUtils = jest.requireActual("../src/utils/actionUtils"); jest.unstable_mockModule("@actions/cache", () => ({
return actualUtils.isValidEvent(); restoreCache: jest.fn(),
}); saveCache: jest.fn(),
isFeatureAvailable: jest.fn(() => true),
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation( ReserveCacheError: class ReserveCacheError extends Error {
(name, options) => { constructor(message: string) {
const actualUtils = jest.requireActual("../src/utils/actionUtils"); super(message);
return actualUtils.getInputAsArray(name, options); this.name = "ReserveCacheError";
} }
); }
}));
jest.spyOn(actionUtils, "getInputAsBool").mockImplementation( const core = await import("@actions/core");
(name, options) => { const cache = await import("@actions/cache");
const actualUtils = jest.requireActual("../src/utils/actionUtils"); const { Events, RefKey } = await import("../src/constants");
return actualUtils.getInputAsBool(name, options); const { restoreRun } = await import("../src/restoreImpl");
} const testUtils = await import("../src/utils/testUtils");
);
});
beforeEach(() => { beforeEach(() => {
jest.restoreAllMocks(); 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();
}
);
(cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
process.env[Events.Key] = Events.Push; process.env[Events.Key] = Events.Push;
process.env[RefKey] = "refs/heads/feature-branch"; process.env[RefKey] = "refs/heads/feature-branch";
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
() => true
);
}); });
afterEach(() => { afterEach(() => {
@@ -62,19 +78,12 @@ test("restore with no cache found", async () => {
enableCrossOsArchive: false enableCrossOsArchive: false
}); });
const infoMock = jest.spyOn(core, "info"); (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
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(); await restoreRun();
expect(restoreCacheMock).toHaveBeenCalledTimes(1); expect(cache.restoreCache).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith( expect(cache.restoreCache).toHaveBeenCalledWith(
[path], [path],
key, key,
[], [],
@@ -84,12 +93,10 @@ test("restore with no cache found", async () => {
false false
); );
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledTimes(1); expect(core.saveState).toHaveBeenCalledTimes(1);
expect(core.setFailed).toHaveBeenCalledTimes(0);
expect(failedMock).toHaveBeenCalledTimes(0); expect(core.info).toHaveBeenCalledWith(
expect(infoMock).toHaveBeenCalledWith(
`Cache not found for input keys: ${key}` `Cache not found for input keys: ${key}`
); );
}); });
@@ -105,19 +112,12 @@ test("restore with restore keys and no cache found", async () => {
enableCrossOsArchive: false enableCrossOsArchive: false
}); });
const infoMock = jest.spyOn(core, "info"); (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
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(); await restoreRun();
expect(restoreCacheMock).toHaveBeenCalledTimes(1); expect(cache.restoreCache).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith( expect(cache.restoreCache).toHaveBeenCalledWith(
[path], [path],
key, key,
[restoreKey], [restoreKey],
@@ -127,12 +127,10 @@ test("restore with restore keys and no cache found", async () => {
false false
); );
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledTimes(1); expect(core.saveState).toHaveBeenCalledTimes(1);
expect(core.setFailed).toHaveBeenCalledTimes(0);
expect(failedMock).toHaveBeenCalledTimes(0); expect(core.info).toHaveBeenCalledWith(
expect(infoMock).toHaveBeenCalledWith(
`Cache not found for input keys: ${key}, ${restoreKey}` `Cache not found for input keys: ${key}, ${restoreKey}`
); );
}); });
@@ -146,20 +144,12 @@ test("restore with cache found for key", async () => {
enableCrossOsArchive: false enableCrossOsArchive: false
}); });
const infoMock = jest.spyOn(core, "info"); (cache.restoreCache as jest.Mock).mockResolvedValue(key);
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(); await restoreRun();
expect(restoreCacheMock).toHaveBeenCalledTimes(1); expect(cache.restoreCache).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith( expect(cache.restoreCache).toHaveBeenCalledWith(
[path], [path],
key, key,
[], [],
@@ -169,15 +159,13 @@ test("restore with cache found for key", async () => {
false false
); );
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", key);
expect(stateMock).toHaveBeenCalledTimes(2); expect(core.saveState).toHaveBeenCalledTimes(2);
expect(core.setOutput).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
expect(core.setFailed).toHaveBeenCalledTimes(0);
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
expect(failedMock).toHaveBeenCalledTimes(0);
}); });
test("restore with cache found for restore key", async () => { test("restore with cache found for restore key", async () => {
@@ -191,39 +179,20 @@ test("restore with cache found for restore key", async () => {
enableCrossOsArchive: false enableCrossOsArchive: false
}); });
const infoMock = jest.spyOn(core, "info"); (cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
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(); await restoreRun();
expect(restoreCacheMock).toHaveBeenCalledTimes(1); expect(cache.restoreCache).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith( expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
[path], expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
key, expect(core.saveState).toHaveBeenCalledTimes(2);
[restoreKey], expect(core.setOutput).toHaveBeenCalledTimes(1);
{ expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
lookupOnly: false expect(core.info).toHaveBeenCalledWith(
},
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}` `Cache restored from key: ${restoreKey}`
); );
expect(failedMock).toHaveBeenCalledTimes(0); expect(core.setFailed).toHaveBeenCalledTimes(0);
}); });
test("Fail restore when fail on cache miss is enabled and primary + restore keys not found", async () => { test("Fail restore when fail on cache miss is enabled and primary + restore keys not found", async () => {
@@ -237,35 +206,17 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
failOnCacheMiss: true failOnCacheMiss: true
}); });
const failedMock = jest.spyOn(core, "setFailed"); (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
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(); await restoreRun();
expect(restoreCacheMock).toHaveBeenCalledTimes(1); expect(cache.restoreCache).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith( expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
[path], expect(core.setOutput).toHaveBeenCalledTimes(0);
key, expect(core.setFailed).toHaveBeenCalledWith(
[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}` `Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`
); );
expect(failedMock).toHaveBeenCalledTimes(1); expect(core.setFailed).toHaveBeenCalledTimes(1);
}); });
test("restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => { test("restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
@@ -279,40 +230,20 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
failOnCacheMiss: true failOnCacheMiss: true
}); });
const infoMock = jest.spyOn(core, "info"); (cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);
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(); await restoreRun();
expect(restoreCacheMock).toHaveBeenCalledTimes(1); expect(cache.restoreCache).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith( expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
[path], expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
key, expect(core.saveState).toHaveBeenCalledTimes(2);
[restoreKey], expect(core.setOutput).toHaveBeenCalledTimes(1);
{ expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
lookupOnly: false expect(core.info).toHaveBeenCalledWith(
},
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}` `Cache restored from key: ${restoreKey}`
); );
expect(failedMock).toHaveBeenCalledTimes(0); expect(core.setFailed).toHaveBeenCalledTimes(0);
}); });
test("restore with fail on cache miss disabled and no cache found", async () => { test("restore with fail on cache miss disabled and no cache found", async () => {
@@ -326,33 +257,15 @@ test("restore with fail on cache miss disabled and no cache found", async () =>
failOnCacheMiss: false failOnCacheMiss: false
}); });
const infoMock = jest.spyOn(core, "info"); (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);
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(); await restoreRun();
expect(restoreCacheMock).toHaveBeenCalledTimes(1); expect(cache.restoreCache).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith( expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
[path], expect(core.saveState).toHaveBeenCalledTimes(1);
key, expect(core.info).toHaveBeenCalledWith(
[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}` `Cache not found for input keys: ${key}, ${restoreKey}`
); );
expect(failedMock).toHaveBeenCalledTimes(0); expect(core.setFailed).toHaveBeenCalledTimes(0);
}); });

Some files were not shown because too many files have changed in this diff Show More