1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2024-11-23 20:19:16 +01:00

Merge branch 'main' into main

This commit is contained in:
Rob Herley 2024-01-16 14:51:14 -05:00 committed by GitHub
commit 53b35c5439
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 112518 additions and 114586 deletions

View file

@ -15,3 +15,5 @@ jobs:
call-check-dist:
name: Check dist/
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
with:
node-version: "20.x"

View file

@ -21,10 +21,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js 16.x
- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
cache: npm
- run: npm ci
- name: Prettier Format Check

View file

@ -116,3 +116,7 @@
- Updates @actions/cache to v3.2.3 to fix accidental mutated path arguments to `getCacheVersion` [actions/toolkit#1378](https://github.com/actions/toolkit/pull/1378)
- Additional audit fixes of npm package(s)
### 4.0.0
- Updated minimum runner version support from node 12 -> node 20

View file

@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, RefKey } from "../src/constants";
import run from "../src/save";
import { saveRun } from "../src/saveImpl";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
@ -100,7 +100,7 @@ test("save with valid inputs uploads a cache", async () => {
return Promise.resolve(cacheId);
});
await run();
await saveRun();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(

View file

@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, RefKey } from "../src/constants";
import run from "../src/saveImpl";
import { saveImpl } from "../src/saveImpl";
import { StateProvider } from "../src/stateProvider";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
@ -77,7 +77,7 @@ test("save with invalid event outputs warning", async () => {
const invalidEvent = "commit_comment";
process.env[Events.Key] = invalidEvent;
delete process.env[RefKey];
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(logWarningMock).toHaveBeenCalledWith(
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
);
@ -100,7 +100,7 @@ test("save with no primary key in state outputs warning", async () => {
});
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(logWarningMock).toHaveBeenCalledWith(`Key is not specified.`);
@ -115,7 +115,7 @@ test("save without AC available should no-op", async () => {
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
});
@ -128,7 +128,7 @@ test("save on ghes without AC available should no-op", async () => {
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
});
@ -161,7 +161,7 @@ test("save on GHES with AC available", async () => {
return Promise.resolve(cacheId);
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -194,7 +194,7 @@ test("save with exact match returns early", async () => {
});
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(infoMock).toHaveBeenCalledWith(
@ -221,7 +221,7 @@ test("save with missing input outputs warning", async () => {
});
const saveCacheMock = jest.spyOn(cache, "saveCache");
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(logWarningMock).toHaveBeenCalledWith(
@ -259,7 +259,7 @@ test("save with large cache outputs warning", async () => {
);
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -306,7 +306,7 @@ test("save with reserve cache failure outputs warning", async () => {
throw error;
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -349,7 +349,7 @@ test("save with server error outputs warning", async () => {
throw new Error("HTTP Error Occurred");
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -392,7 +392,7 @@ test("save with valid inputs uploads a cache", async () => {
return Promise.resolve(cacheId);
});
await run(new StateProvider());
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(

View file

@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, RefKey } from "../src/constants";
import run from "../src/saveOnly";
import { saveOnlyRun } from "../src/saveImpl";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
@ -90,7 +90,7 @@ test("save with valid inputs uploads a cache", async () => {
return Promise.resolve(cacheId);
});
await run();
await saveOnlyRun();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(
@ -122,7 +122,7 @@ test("save failing logs the warning message", async () => {
return Promise.resolve(cacheId);
});
await run();
await saveOnlyRun();
expect(saveCacheMock).toHaveBeenCalledTimes(1);
expect(saveCacheMock).toHaveBeenCalledWith(

View file

@ -34,7 +34,7 @@ outputs:
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
runs:
using: 'node16'
using: 'node20'
main: 'dist/restore/index.js'
post: 'dist/save/index.js'
post-if: "success() || github.event.inputs.save-always"

File diff suppressed because one or more lines are too long

56714
dist/restore/index.js vendored

File diff suppressed because one or more lines are too long

56713
dist/save-only/index.js vendored

File diff suppressed because one or more lines are too long

56686
dist/save/index.js vendored

File diff suppressed because one or more lines are too long

23
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "cache",
"version": "3.3.2",
"version": "4.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "cache",
"version": "3.3.2",
"version": "4.0.0",
"license": "MIT",
"dependencies": {
"@actions/cache": "^3.2.3",
@ -20,7 +20,7 @@
"@types/node": "^16.18.3",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@zeit/ncc": "^0.20.5",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
@ -3135,11 +3135,10 @@
"url": "https://opencollective.com/typescript-eslint"
}
},
"node_modules/@zeit/ncc": {
"version": "0.20.5",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.20.5.tgz",
"integrity": "sha512-XU6uzwvv95DqxciQx+aOLhbyBx/13ky+RK1y88Age9Du3BlA4mMPCy13BGjayOrrumOzlq1XV3SD/BWiZENXlw==",
"deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.",
"node_modules/@vercel/ncc": {
"version": "0.38.1",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.1.tgz",
"integrity": "sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==",
"dev": true,
"bin": {
"ncc": "dist/ncc/cli.js"
@ -12014,10 +12013,10 @@
"eslint-visitor-keys": "^3.3.0"
}
},
"@zeit/ncc": {
"version": "0.20.5",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.20.5.tgz",
"integrity": "sha512-XU6uzwvv95DqxciQx+aOLhbyBx/13ky+RK1y88Age9Du3BlA4mMPCy13BGjayOrrumOzlq1XV3SD/BWiZENXlw==",
"@vercel/ncc": {
"version": "0.38.1",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.1.tgz",
"integrity": "sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==",
"dev": true
},
"abort-controller": {

View file

@ -1,6 +1,6 @@
{
"name": "cache",
"version": "3.3.3",
"version": "4.0.0",
"private": true,
"description": "Cache dependencies and build outputs",
"main": "dist/restore/index.js",
@ -34,7 +34,7 @@
"@types/node": "^16.18.3",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@zeit/ncc": "^0.20.5",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",

View file

@ -31,7 +31,7 @@ outputs:
cache-matched-key:
description: 'Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys'
runs:
using: 'node16'
using: 'node20'
main: '../dist/restore-only/index.js'
branding:
icon: 'archive'

View file

@ -16,7 +16,7 @@ inputs:
default: 'false'
required: false
runs:
using: 'node16'
using: 'node20'
main: '../dist/save-only/index.js'
branding:
icon: 'archive'

View file

@ -1,10 +1,3 @@
import saveImpl from "./saveImpl";
import { StateProvider } from "./stateProvider";
import { saveRun } from "./saveImpl";
async function run(): Promise<void> {
await saveImpl(new StateProvider());
}
run();
export default run;
saveRun(true);

View file

@ -2,7 +2,11 @@ import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, State } from "./constants";
import { IStateProvider } from "./stateProvider";
import {
IStateProvider,
NullStateProvider,
StateProvider
} from "./stateProvider";
import * as utils from "./utils/actionUtils";
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
@ -10,7 +14,9 @@ import * as utils from "./utils/actionUtils";
// throw an uncaught exception. Instead of failing this action, just warn.
process.on("uncaughtException", e => utils.logWarning(e.message));
async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
export async function saveImpl(
stateProvider: IStateProvider
): Promise<number | void> {
let cacheId = -1;
try {
if (!utils.isCacheFeatureAvailable()) {
@ -72,4 +78,47 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
return cacheId;
}
export default saveImpl;
export async function saveOnlyRun(
earlyExit?: boolean | undefined
): Promise<void> {
try {
const cacheId = await saveImpl(new NullStateProvider());
if (cacheId === -1) {
core.warning(`Cache save failed.`);
}
} catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
if (earlyExit) {
process.exit(0);
}
}
export async function saveRun(earlyExit?: boolean | undefined): Promise<void> {
try {
await saveImpl(new StateProvider());
} catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
if (earlyExit) {
process.exit(0);
}
}

View file

@ -1,15 +1,3 @@
import * as core from "@actions/core";
import { saveOnlyRun } from "./saveImpl";
import saveImpl from "./saveImpl";
import { NullStateProvider } from "./stateProvider";
async function run(): Promise<void> {
const cacheId = await saveImpl(new NullStateProvider());
if (cacheId === -1) {
core.warning(`Cache save failed.`);
}
}
run();
export default run;
saveOnlyRun(true);