Code review

This commit is contained in:
Marc Mueller 2023-03-09 11:00:37 +01:00
parent d57039cf5c
commit 84097c0606
7 changed files with 23 additions and 7 deletions

View file

@ -396,6 +396,8 @@ test("restore with lookup-only set", async () => {
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
expect(infoMock).toHaveBeenCalledWith(
`Cache would have been restored from key: ${key}`
);
expect(failedMock).toHaveBeenCalledTimes(0);
});

View file

@ -23,7 +23,7 @@ inputs:
default: 'false'
required: false
lookup-only:
description: 'Skip downloading cache. Only check if cache entry exists'
description: 'Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache'
default: 'false'
required: false
outputs:

View file

@ -50520,7 +50520,12 @@ function restoreImpl(stateProvider) {
stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey);
core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString());
core.info(`Cache restored from key: ${cacheKey}`);
if (lookupOnly) {
core.info(`Cache would have been restored from key: ${cacheKey}`);
}
else {
core.info(`Cache restored from key: ${cacheKey}`);
}
return cacheKey;
}
catch (error) {

View file

@ -50520,7 +50520,12 @@ function restoreImpl(stateProvider) {
stateProvider.setState(constants_1.State.CacheMatchedKey, cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(core.getInput(constants_1.Inputs.Key, { required: true }), cacheKey);
core.setOutput(constants_1.Outputs.CacheHit, isExactKeyMatch.toString());
core.info(`Cache restored from key: ${cacheKey}`);
if (lookupOnly) {
core.info(`Cache would have been restored from key: ${cacheKey}`);
}
else {
core.info(`Cache restored from key: ${cacheKey}`);
}
return cacheKey;
}
catch (error) {

View file

@ -10,7 +10,7 @@ The restore action restores a cache. It works similarly to the `cache` action ex
* `path` - A list of files, directories, and wildcard patterns to restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns.
* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key.
* `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false`
* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: `false`
* `lookup-only` - Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache. Default: `false`
### Outputs

View file

@ -20,7 +20,7 @@ inputs:
default: 'false'
required: false
lookup-only:
description: 'Skip downloading cache. Only check if cache entry exists'
description: 'Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache'
default: 'false'
required: false
outputs:

View file

@ -70,7 +70,11 @@ async function restoreImpl(
);
core.setOutput(Outputs.CacheHit, isExactKeyMatch.toString());
core.info(`Cache restored from key: ${cacheKey}`);
if (lookupOnly) {
core.info(`Cache would have been restored from key: ${cacheKey}`);
} else {
core.info(`Cache restored from key: ${cacheKey}`);
}
return cacheKey;
} catch (error: unknown) {