mirror of
https://github.com/actions/cache.git
synced 2025-05-23 01:11:47 +00:00
When `read-only` is `true`, the cache is only restored and not saved. This allows for sharing the cache with multiple steps even if these steps may change them, and speeds them up regardless.
34 lines
1.0 KiB
TypeScript
34 lines
1.0 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[];
|
|
readOnly?: 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"));
|
|
setInput(Inputs.ReadOnly, input.readOnly ? "true" : "false");
|
|
}
|
|
|
|
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.ReadOnly)];
|
|
}
|