Compare commits

...

6 commits

Author SHA1 Message Date
Andreas Abel 0f52366f0f
Merge 6710a4f1f6 into 0c45773b62 2024-03-19 20:15:21 +01:00
Bethany 0c45773b62
Merge pull request #1327 from cdce8p/fix-fail-on-cache-miss
Fix `fail-on-cache-miss` not working
2024-03-19 09:31:49 -04:00
Marc Mueller 8a55f839aa Add test case for process exit
Co-authored-by: Bethany <bethanyj28@users.noreply.github.com>
2024-03-19 09:28:12 +01:00
Marc Mueller 3884cace14 Bump version 2024-03-01 07:28:18 +01:00
Marc Mueller e29dad3e36 Fix fail-on-cache-miss not working 2024-03-01 07:28:18 +01:00
Andreas Abel 6710a4f1f6 README: clarify that cache-hit returns a string and not a boolean
Rationale: if `cache-hit` was a boolean, then `!` could be used to get the opposite.
However, it is really a string, and this should be pointed out clearly in the documentation.
Because both `!'true'` and `!'false'` are `false`, so customers can shoot themselves in the foot here.

Closes #1262.
2023-10-17 22:36:00 +02:00
9 changed files with 43 additions and 36 deletions

View file

@ -65,9 +65,9 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir
### Outputs
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
* `cache-hit` - A string `'true'` or `'false'` indicating whether an exact match was found for the key.
> **Note** `cache-hit` will only be set to `true` when a cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
> **Note** `cache-hit` will only be set to `'true'` when a cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `'false'`.
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output

View file

@ -1,5 +1,9 @@
# Releases
### 4.0.2
- Fixed restore `fail-on-cache-miss` not working.
### 4.0.1
- Updated `isGhes` check

View file

@ -449,3 +449,19 @@ test("restore with lookup-only set", async () => {
);
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);
});

View file

@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186));
const constants_1 = __nccwpck_require__(9042);
const stateProvider_1 = __nccwpck_require__(1527);
const utils = __importStar(__nccwpck_require__(6850));
function restoreImpl(stateProvider) {
function restoreImpl(stateProvider, earlyExit) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!utils.isCacheFeatureAvailable()) {
@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) {
}
catch (error) {
core.setFailed(error.message);
if (earlyExit) {
process.exit(1);
}
}
});
}
exports.restoreImpl = restoreImpl;
function run(stateProvider, earlyExit) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield restoreImpl(stateProvider);
}
catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
yield restoreImpl(stateProvider, earlyExit);
// 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

15
dist/restore/index.js vendored
View file

@ -59392,7 +59392,7 @@ const core = __importStar(__nccwpck_require__(2186));
const constants_1 = __nccwpck_require__(9042);
const stateProvider_1 = __nccwpck_require__(1527);
const utils = __importStar(__nccwpck_require__(6850));
function restoreImpl(stateProvider) {
function restoreImpl(stateProvider, earlyExit) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!utils.isCacheFeatureAvailable()) {
@ -59438,21 +59438,16 @@ function restoreImpl(stateProvider) {
}
catch (error) {
core.setFailed(error.message);
if (earlyExit) {
process.exit(1);
}
}
});
}
exports.restoreImpl = restoreImpl;
function run(stateProvider, earlyExit) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield restoreImpl(stateProvider);
}
catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
yield restoreImpl(stateProvider, earlyExit);
// 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

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "cache",
"version": "4.0.1",
"version": "4.0.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "cache",
"version": "4.0.1",
"version": "4.0.2",
"license": "MIT",
"dependencies": {
"@actions/cache": "^3.2.3",

View file

@ -1,6 +1,6 @@
{
"name": "cache",
"version": "4.0.1",
"version": "4.0.2",
"private": true,
"description": "Cache dependencies and build outputs",
"main": "dist/restore/index.js",

View file

@ -14,12 +14,12 @@ The restore action restores a cache. It works similarly to the `cache` action ex
### Outputs
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
* `cache-hit` - A string `'true'` or `'false'` to indicate whether an exact match was found for the key.
* `cache-primary-key` - Cache primary key passed in the input to use in subsequent steps of the workflow.
* `cache-matched-key` - 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.
> **Note**
`cache-hit` will be set to `true` only when cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
`cache-hit` will be set to `'true'` only when cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `'false'`.
### Environment Variables

View file

@ -10,7 +10,8 @@ import {
import * as utils from "./utils/actionUtils";
export async function restoreImpl(
stateProvider: IStateProvider
stateProvider: IStateProvider,
earlyExit?: boolean | undefined
): Promise<string | undefined> {
try {
if (!utils.isCacheFeatureAvailable()) {
@ -83,6 +84,9 @@ export async function restoreImpl(
return cacheKey;
} catch (error: unknown) {
core.setFailed((error as Error).message);
if (earlyExit) {
process.exit(1);
}
}
}
@ -90,14 +94,7 @@ async function run(
stateProvider: IStateProvider,
earlyExit: boolean | undefined
): Promise<void> {
try {
await restoreImpl(stateProvider);
} catch (err) {
console.error(err);
if (earlyExit) {
process.exit(1);
}
}
await restoreImpl(stateProvider, earlyExit);
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling