commit
d5f1550948
|
@ -194,13 +194,3 @@ test("getInputAsArray handles empty lines correctly", () => {
|
||||||
testUtils.setInput("foo", "\n\nbar\n\nbaz\n\n");
|
testUtils.setInput("foo", "\n\nbar\n\nbaz\n\n");
|
||||||
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
|
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("getInputAsBoolean returns true if the value is set to 'true'", () => {
|
|
||||||
testUtils.setInput("foo", "true");
|
|
||||||
expect(actionUtils.getInputAsBoolean("foo")).toEqual(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("getInputAsBoolean returns false if the value is set to anything else", () => {
|
|
||||||
testUtils.setInput("foo", "false");
|
|
||||||
expect(actionUtils.getInputAsBoolean("foo")).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
|
@ -118,7 +118,8 @@ test("save with exact match returns early", async () => {
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("save with exact match updates when configured", async () => {
|
test("save with exact match and updates enabled updates the cache", async () => {
|
||||||
|
const infoMock = jest.spyOn(core, "info");
|
||||||
const failedMock = jest.spyOn(core, "setFailed");
|
const failedMock = jest.spyOn(core, "setFailed");
|
||||||
|
|
||||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||||
|
@ -147,9 +148,11 @@ test("save with exact match updates when configured", async () => {
|
||||||
|
|
||||||
await run();
|
await run();
|
||||||
|
|
||||||
|
expect(infoMock).toHaveBeenCalledWith(
|
||||||
|
`Cache hit occurred on the primary key ${primaryKey}, but updates were enabled, so updating cache.`
|
||||||
|
);
|
||||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||||
expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey);
|
expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6717,6 +6717,7 @@ var Inputs;
|
||||||
Inputs["Key"] = "key";
|
Inputs["Key"] = "key";
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
|
Inputs["Update"] = "update";
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var Outputs;
|
var Outputs;
|
||||||
(function (Outputs) {
|
(function (Outputs) {
|
||||||
|
|
|
@ -6605,8 +6605,13 @@ function run() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
if (core.getInput(constants_1.Inputs.Update) === "true") {
|
||||||
return;
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, but updates were enabled, so updating cache.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
||||||
required: true
|
required: true
|
||||||
|
@ -6802,6 +6807,7 @@ var Inputs;
|
||||||
Inputs["Key"] = "key";
|
Inputs["Key"] = "key";
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["RestoreKeys"] = "restore-keys";
|
Inputs["RestoreKeys"] = "restore-keys";
|
||||||
|
Inputs["Update"] = "update";
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var Outputs;
|
var Outputs;
|
||||||
(function (Outputs) {
|
(function (Outputs) {
|
||||||
|
|
22
src/save.ts
22
src/save.ts
|
@ -16,21 +16,25 @@ async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = utils.getCacheState();
|
const state = utils.getCacheState();
|
||||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
|
||||||
|
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||||
const primaryKey = core.getState(State.CachePrimaryKey);
|
const primaryKey = core.getState(State.CachePrimaryKey);
|
||||||
if (!primaryKey) {
|
if (!primaryKey) {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
utils.logWarning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||||
utils.isExactKeyMatch(primaryKey, state) &&
|
if (core.getInput(Inputs.Update) === "true") {
|
||||||
!utils.getInputAsBoolean(Inputs.Update)
|
core.info(
|
||||||
) {
|
`Cache hit occurred on the primary key ${primaryKey}, but updates were enabled, so updating cache.`
|
||||||
core.info(
|
);
|
||||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
} else {
|
||||||
);
|
core.info(
|
||||||
return;
|
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||||
|
|
|
@ -56,10 +56,3 @@ export function getInputAsArray(
|
||||||
.map(s => s.trim())
|
.map(s => s.trim())
|
||||||
.filter(x => x !== "");
|
.filter(x => x !== "");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInputAsBoolean(
|
|
||||||
name: string,
|
|
||||||
options?: core.InputOptions
|
|
||||||
): boolean {
|
|
||||||
return core.getInput(name, options) === "true";
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,11 +13,13 @@ interface CacheInput {
|
||||||
path: string;
|
path: string;
|
||||||
key: string;
|
key: string;
|
||||||
restoreKeys?: string[];
|
restoreKeys?: string[];
|
||||||
|
update: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setInputs(input: CacheInput): void {
|
export function setInputs(input: CacheInput): void {
|
||||||
setInput(Inputs.Path, input.path);
|
setInput(Inputs.Path, input.path);
|
||||||
setInput(Inputs.Key, input.key);
|
setInput(Inputs.Key, input.key);
|
||||||
|
setInput(Inputs.Update, input.update);
|
||||||
input.restoreKeys &&
|
input.restoreKeys &&
|
||||||
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
||||||
}
|
}
|
||||||
|
@ -25,5 +27,6 @@ export function setInputs(input: CacheInput): void {
|
||||||
export function clearInputs(): void {
|
export function clearInputs(): void {
|
||||||
delete process.env[getInputName(Inputs.Path)];
|
delete process.env[getInputName(Inputs.Path)];
|
||||||
delete process.env[getInputName(Inputs.Key)];
|
delete process.env[getInputName(Inputs.Key)];
|
||||||
|
delete process.env[getInputName(Inputs.Update)];
|
||||||
delete process.env[getInputName(Inputs.RestoreKeys)];
|
delete process.env[getInputName(Inputs.RestoreKeys)];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue