mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-11-27 22:49:17 +01:00
940f3d7cf1
* Add new actions/cache version (with dryRun support) * Add dry-run option * Changes after rebase * Update readme * Rename option to lookup-only * Update test name * Update package.json + changelog * Update README * Update custom package version * Update custom package version * Update @actions/cache to 3.2.0 * Code review * Update log statement * Move test case --------- Co-authored-by: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com>
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { Inputs } from "../constants";
|
|
|
|
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
|
|
function getInputName(name: string): string {
|
|
return `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
|
|
}
|
|
|
|
export function setInput(name: string, value: string): void {
|
|
process.env[getInputName(name)] = value;
|
|
}
|
|
|
|
interface CacheInput {
|
|
path: string;
|
|
key: string;
|
|
restoreKeys?: string[];
|
|
enableCrossOsArchive?: boolean;
|
|
failOnCacheMiss?: boolean;
|
|
lookupOnly?: boolean;
|
|
}
|
|
|
|
export function setInputs(input: CacheInput): void {
|
|
setInput(Inputs.Path, input.path);
|
|
setInput(Inputs.Key, input.key);
|
|
input.restoreKeys &&
|
|
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
|
input.enableCrossOsArchive !== undefined &&
|
|
setInput(
|
|
Inputs.EnableCrossOsArchive,
|
|
input.enableCrossOsArchive.toString()
|
|
);
|
|
input.failOnCacheMiss !== undefined &&
|
|
setInput(Inputs.FailOnCacheMiss, input.failOnCacheMiss.toString());
|
|
input.lookupOnly !== undefined &&
|
|
setInput(Inputs.LookupOnly, input.lookupOnly.toString());
|
|
}
|
|
|
|
export function clearInputs(): void {
|
|
delete process.env[getInputName(Inputs.Path)];
|
|
delete process.env[getInputName(Inputs.Key)];
|
|
delete process.env[getInputName(Inputs.RestoreKeys)];
|
|
delete process.env[getInputName(Inputs.UploadChunkSize)];
|
|
delete process.env[getInputName(Inputs.EnableCrossOsArchive)];
|
|
delete process.env[getInputName(Inputs.FailOnCacheMiss)];
|
|
delete process.env[getInputName(Inputs.LookupOnly)];
|
|
}
|