mirror of
https://github.com/actions/cache.git
synced 2026-07-03 02:52:03 +00:00
Compare commits
6 Commits
42beebeff7
...
1f33cad54a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f33cad54a | ||
|
|
0c45773b62 | ||
|
|
8a55f839aa | ||
|
|
3884cace14 | ||
|
|
e29dad3e36 | ||
|
|
7dd9af18b0 |
@ -14,6 +14,10 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
|||||||
|
|
||||||
## What's New
|
## What's New
|
||||||
|
|
||||||
|
### Unreleased
|
||||||
|
|
||||||
|
* Added the `force-overwrite` flag to force overwrite any existing cache for incremental caching
|
||||||
|
|
||||||
### v4
|
### v4
|
||||||
|
|
||||||
* Updated to node 20
|
* Updated to node 20
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
# Releases
|
# Releases
|
||||||
|
|
||||||
|
### 4.0.2
|
||||||
|
|
||||||
|
- Fixed restore `fail-on-cache-miss` not working.
|
||||||
|
|
||||||
### 4.0.1
|
### 4.0.1
|
||||||
|
|
||||||
- Updated `isGhes` check
|
- Updated `isGhes` check
|
||||||
|
|||||||
@ -449,3 +449,19 @@ test("restore with lookup-only set", async () => {
|
|||||||
);
|
);
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("restore failure with earlyExit should call process exit", async () => {
|
||||||
|
testUtils.setInput(Inputs.Path, "node_modules");
|
||||||
|
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(restoreCacheMock).toHaveBeenCalledTimes(0);
|
||||||
|
expect(failedMock).toHaveBeenCalledWith(
|
||||||
|
"Input required and not supplied: key"
|
||||||
|
);
|
||||||
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
||||||
|
});
|
||||||
|
|||||||
@ -30,6 +30,10 @@ inputs:
|
|||||||
description: 'Run the post step to save the cache even if another step before fails'
|
description: 'Run the post step to save the cache even if another step before fails'
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
|
force-overwrite:
|
||||||
|
description: 'Delete any previous (incremental) cache before pushing a new cache even if a cache for the primary cache key exists'
|
||||||
|
default: 'false'
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||||
|
|||||||
15
dist/restore-only/index.js
vendored
15
dist/restore-only/index.js
vendored
@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const constants_1 = __nccwpck_require__(9042);
|
const constants_1 = __nccwpck_require__(9042);
|
||||||
const stateProvider_1 = __nccwpck_require__(1527);
|
const stateProvider_1 = __nccwpck_require__(1527);
|
||||||
const utils = __importStar(__nccwpck_require__(6850));
|
const utils = __importStar(__nccwpck_require__(6850));
|
||||||
function restoreImpl(stateProvider) {
|
function restoreImpl(stateProvider, earlyExit) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
if (!utils.isCacheFeatureAvailable()) {
|
if (!utils.isCacheFeatureAvailable()) {
|
||||||
@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) {
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
if (earlyExit) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.restoreImpl = restoreImpl;
|
exports.restoreImpl = restoreImpl;
|
||||||
function run(stateProvider, earlyExit) {
|
function run(stateProvider, earlyExit) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
yield restoreImpl(stateProvider, earlyExit);
|
||||||
yield restoreImpl(stateProvider);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
if (earlyExit) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// node will stay alive if any promises are not resolved,
|
// node will stay alive if any promises are not resolved,
|
||||||
// which is a possibility if HTTP requests are dangling
|
// which is a possibility if HTTP requests are dangling
|
||||||
// due to retries or timeouts. We know that if we got here
|
// due to retries or timeouts. We know that if we got here
|
||||||
|
|||||||
15
dist/restore/index.js
vendored
15
dist/restore/index.js
vendored
@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const constants_1 = __nccwpck_require__(9042);
|
const constants_1 = __nccwpck_require__(9042);
|
||||||
const stateProvider_1 = __nccwpck_require__(1527);
|
const stateProvider_1 = __nccwpck_require__(1527);
|
||||||
const utils = __importStar(__nccwpck_require__(6850));
|
const utils = __importStar(__nccwpck_require__(6850));
|
||||||
function restoreImpl(stateProvider) {
|
function restoreImpl(stateProvider, earlyExit) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
if (!utils.isCacheFeatureAvailable()) {
|
if (!utils.isCacheFeatureAvailable()) {
|
||||||
@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) {
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
if (earlyExit) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.restoreImpl = restoreImpl;
|
exports.restoreImpl = restoreImpl;
|
||||||
function run(stateProvider, earlyExit) {
|
function run(stateProvider, earlyExit) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
yield restoreImpl(stateProvider, earlyExit);
|
||||||
yield restoreImpl(stateProvider);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
if (earlyExit) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// node will stay alive if any promises are not resolved,
|
// node will stay alive if any promises are not resolved,
|
||||||
// which is a possibility if HTTP requests are dangling
|
// which is a possibility if HTTP requests are dangling
|
||||||
// due to retries or timeouts. We know that if we got here
|
// due to retries or timeouts. We know that if we got here
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "4.0.1",
|
"version": "4.0.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "4.0.1",
|
"version": "4.0.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.2.3",
|
"@actions/cache": "^3.2.3",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "4.0.1",
|
"version": "4.0.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Cache dependencies and build outputs",
|
"description": "Cache dependencies and build outputs",
|
||||||
"main": "dist/restore/index.js",
|
"main": "dist/restore/index.js",
|
||||||
|
|||||||
@ -5,7 +5,8 @@ export enum Inputs {
|
|||||||
UploadChunkSize = "upload-chunk-size", // Input for cache, save action
|
UploadChunkSize = "upload-chunk-size", // Input for cache, save action
|
||||||
EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action
|
EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action
|
||||||
FailOnCacheMiss = "fail-on-cache-miss", // Input for cache, restore action
|
FailOnCacheMiss = "fail-on-cache-miss", // Input for cache, restore action
|
||||||
LookupOnly = "lookup-only" // Input for cache, restore action
|
LookupOnly = "lookup-only", // Input for cache, restore action
|
||||||
|
ForceOverwrite = "force-overwrite" // Input for cache action
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Outputs {
|
export enum Outputs {
|
||||||
|
|||||||
@ -10,7 +10,8 @@ import {
|
|||||||
import * as utils from "./utils/actionUtils";
|
import * as utils from "./utils/actionUtils";
|
||||||
|
|
||||||
export async function restoreImpl(
|
export async function restoreImpl(
|
||||||
stateProvider: IStateProvider
|
stateProvider: IStateProvider,
|
||||||
|
earlyExit?: boolean | undefined
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
if (!utils.isCacheFeatureAvailable()) {
|
if (!utils.isCacheFeatureAvailable()) {
|
||||||
@ -83,6 +84,9 @@ export async function restoreImpl(
|
|||||||
return cacheKey;
|
return cacheKey;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
core.setFailed((error as Error).message);
|
core.setFailed((error as Error).message);
|
||||||
|
if (earlyExit) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,14 +94,7 @@ async function run(
|
|||||||
stateProvider: IStateProvider,
|
stateProvider: IStateProvider,
|
||||||
earlyExit: boolean | undefined
|
earlyExit: boolean | undefined
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
await restoreImpl(stateProvider, earlyExit);
|
||||||
await restoreImpl(stateProvider);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
if (earlyExit) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// node will stay alive if any promises are not resolved,
|
// node will stay alive if any promises are not resolved,
|
||||||
// which is a possibility if HTTP requests are dangling
|
// which is a possibility if HTTP requests are dangling
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import {
|
|||||||
StateProvider
|
StateProvider
|
||||||
} from "./stateProvider";
|
} from "./stateProvider";
|
||||||
import * as utils from "./utils/actionUtils";
|
import * as utils from "./utils/actionUtils";
|
||||||
|
import { issueCommand } from "@actions/core/lib/command";
|
||||||
|
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
||||||
@ -47,13 +48,18 @@ export async function saveImpl(
|
|||||||
// NO-OP in case of SaveOnly action
|
// NO-OP in case of SaveOnly action
|
||||||
const restoredKey = stateProvider.getCacheState();
|
const restoredKey = stateProvider.getCacheState();
|
||||||
|
|
||||||
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
|
const forceOverwrite = utils.getInputAsBool(Inputs.ForceOverwrite);
|
||||||
|
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
|
||||||
core.info(
|
core.info(
|
||||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
`Cache hit occurred on the primary key ${primaryKey} and force-overwrite is disabled, not saving cache.`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (utils.isExactKeyMatch(primaryKey, restoredKey) && forceOverwrite) {
|
||||||
|
await issueCommand('actions-cache delete', {}, primaryKey);
|
||||||
|
}
|
||||||
|
|
||||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||||
required: true
|
required: true
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user