mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-05-14 04:49:54 +02:00
Add skip-save feature
The skip-save option allows users to force the cache to skip saving the cache. skip-save can be set to a constant or to an expression that will be evaluated at the end of the CI job, such as an environment variable. This is for #498
This commit is contained in:
parent
3a696372f2
commit
ffdb03bc68
8 changed files with 8110 additions and 3 deletions
|
@ -2,7 +2,8 @@ export enum Inputs {
|
|||
Key = "key",
|
||||
Path = "path",
|
||||
RestoreKeys = "restore-keys",
|
||||
UploadChunkSize = "upload-chunk-size"
|
||||
UploadChunkSize = "upload-chunk-size",
|
||||
SkipSave = "skip-save"
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
|
@ -29,6 +29,13 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
const skipSave = ["true", "yes"].includes(
|
||||
core.getInput(Inputs.SkipSave).toLowerCase()
|
||||
);
|
||||
if (skipSave) {
|
||||
core.info(`Cache saving was disabled by setting skip-save.`);
|
||||
return;
|
||||
}
|
||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
|
|
|
@ -13,11 +13,13 @@ interface CacheInput {
|
|||
path: string;
|
||||
key: string;
|
||||
restoreKeys?: string[];
|
||||
skipSave?: string;
|
||||
}
|
||||
|
||||
export function setInputs(input: CacheInput): void {
|
||||
setInput(Inputs.Path, input.path);
|
||||
setInput(Inputs.Key, input.key);
|
||||
input.skipSave && setInput(Inputs.SkipSave, input.skipSave);
|
||||
input.restoreKeys &&
|
||||
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
||||
}
|
||||
|
@ -25,6 +27,7 @@ export function setInputs(input: CacheInput): void {
|
|||
export function clearInputs(): void {
|
||||
delete process.env[getInputName(Inputs.Path)];
|
||||
delete process.env[getInputName(Inputs.Key)];
|
||||
delete process.env[getInputName(Inputs.SkipSave)];
|
||||
delete process.env[getInputName(Inputs.RestoreKeys)];
|
||||
delete process.env[getInputName(Inputs.UploadChunkSize)];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue