2019-11-06 18:41:45 +00:00
|
|
|
import { Inputs } from "../constants";
|
|
|
|
|
|
|
|
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
|
2019-10-30 18:48:49 +00:00
|
|
|
function getInputName(name: string): string {
|
|
|
|
return `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
|
|
|
|
}
|
|
|
|
|
2019-11-12 21:48:02 +00:00
|
|
|
export function setInput(name: string, value: string): void {
|
2019-10-30 18:48:49 +00:00
|
|
|
process.env[getInputName(name)] = value;
|
|
|
|
}
|
2019-11-06 18:41:45 +00:00
|
|
|
|
|
|
|
interface CacheInput {
|
|
|
|
path: string;
|
|
|
|
key: string;
|
|
|
|
restoreKeys?: string[];
|
|
|
|
}
|
|
|
|
|
2019-11-12 21:48:02 +00:00
|
|
|
export function setInputs(input: CacheInput): void {
|
2019-11-06 18:41:45 +00:00
|
|
|
setInput(Inputs.Path, input.path);
|
|
|
|
setInput(Inputs.Key, input.key);
|
|
|
|
input.restoreKeys &&
|
|
|
|
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
|
|
|
}
|
|
|
|
|
2019-11-12 21:48:02 +00:00
|
|
|
export function clearInputs(): void {
|
2019-11-06 18:41:45 +00:00
|
|
|
delete process.env[getInputName(Inputs.Path)];
|
|
|
|
delete process.env[getInputName(Inputs.Key)];
|
|
|
|
delete process.env[getInputName(Inputs.RestoreKeys)];
|
|
|
|
}
|