mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-19 19:46:17 +02:00
add state save logic when selecting reevaluation
* add logic to not save state in restore step when setting `reeval` to true * create infrastructure to set `Inputs.Reeval` input variable within tests * `Inputs.Reeval` set to false for all save & restore tests
This commit is contained in:
parent
856dca34a5
commit
dfd8915e1a
8 changed files with 60 additions and 11 deletions
|
@ -27,11 +27,19 @@ beforeAll(() => {
|
||||||
return actualUtils.getInputAsArray(name, options);
|
return actualUtils.getInputAsArray(name, options);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
jest.spyOn(actionUtils, "getInputAsBoolean").mockImplementation(
|
||||||
|
(name, options) => {
|
||||||
|
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||||
|
return actualUtils.getInputAsBoolean(name, options);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
testUtils.setInput(Inputs.Reeval, "false");
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||||
|
|
|
@ -27,6 +27,13 @@ beforeAll(() => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
jest.spyOn(actionUtils, "getInputAsBoolean").mockImplementation(
|
||||||
|
(name, options) => {
|
||||||
|
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||||
|
return actualUtils.getInputAsBoolean(name, options);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
jest.spyOn(actionUtils, "getInputAsInt").mockImplementation(
|
||||||
(name, options) => {
|
(name, options) => {
|
||||||
return jest
|
return jest
|
||||||
|
@ -52,6 +59,7 @@ beforeAll(() => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env[Events.Key] = Events.Push;
|
process.env[Events.Key] = Events.Push;
|
||||||
process.env[RefKey] = "refs/heads/feature-branch";
|
process.env[RefKey] = "refs/heads/feature-branch";
|
||||||
|
testUtils.setInput(Inputs.Reeval, "false");
|
||||||
|
|
||||||
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
|
||||||
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
|
||||||
|
|
13
dist/restore/index.js
vendored
13
dist/restore/index.js
vendored
|
@ -37588,7 +37588,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.isCacheFeatureAvailable = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
|
exports.isCacheFeatureAvailable = exports.getInputAsInt = exports.getInputAsBoolean = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
|
||||||
const cache = __importStar(__webpack_require__(692));
|
const cache = __importStar(__webpack_require__(692));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const constants_1 = __webpack_require__(196);
|
const constants_1 = __webpack_require__(196);
|
||||||
|
@ -37646,6 +37646,11 @@ function getInputAsArray(name, options) {
|
||||||
.filter(x => x !== "");
|
.filter(x => x !== "");
|
||||||
}
|
}
|
||||||
exports.getInputAsArray = getInputAsArray;
|
exports.getInputAsArray = getInputAsArray;
|
||||||
|
function getInputAsBoolean(name, options) {
|
||||||
|
const value = core.getBooleanInput(name, options);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
exports.getInputAsBoolean = getInputAsBoolean;
|
||||||
function getInputAsInt(name, options) {
|
function getInputAsInt(name, options) {
|
||||||
const value = parseInt(core.getInput(name, options));
|
const value = parseInt(core.getInput(name, options));
|
||||||
if (isNaN(value) || value < 0) {
|
if (isNaN(value) || value < 0) {
|
||||||
|
@ -48993,7 +48998,11 @@ function run() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
||||||
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
// when selecting to reevaluate primary key - state is saved in save step
|
||||||
|
const reeval = utils.getInputAsBoolean(constants_1.Inputs.Reeval);
|
||||||
|
if (!reeval) {
|
||||||
|
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
||||||
|
}
|
||||||
const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys);
|
const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys);
|
||||||
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
|
||||||
required: true
|
required: true
|
||||||
|
|
13
dist/save/index.js
vendored
13
dist/save/index.js
vendored
|
@ -37588,7 +37588,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.isCacheFeatureAvailable = exports.getInputAsInt = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
|
exports.isCacheFeatureAvailable = exports.getInputAsInt = exports.getInputAsBoolean = exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = exports.isGhes = void 0;
|
||||||
const cache = __importStar(__webpack_require__(692));
|
const cache = __importStar(__webpack_require__(692));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const constants_1 = __webpack_require__(196);
|
const constants_1 = __webpack_require__(196);
|
||||||
|
@ -37646,6 +37646,11 @@ function getInputAsArray(name, options) {
|
||||||
.filter(x => x !== "");
|
.filter(x => x !== "");
|
||||||
}
|
}
|
||||||
exports.getInputAsArray = getInputAsArray;
|
exports.getInputAsArray = getInputAsArray;
|
||||||
|
function getInputAsBoolean(name, options) {
|
||||||
|
const value = core.getBooleanInput(name, options);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
exports.getInputAsBoolean = getInputAsBoolean;
|
||||||
function getInputAsInt(name, options) {
|
function getInputAsInt(name, options) {
|
||||||
const value = parseInt(core.getInput(name, options));
|
const value = parseInt(core.getInput(name, options));
|
||||||
if (isNaN(value) || value < 0) {
|
if (isNaN(value) || value < 0) {
|
||||||
|
@ -46782,14 +46787,15 @@ function run() {
|
||||||
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
|
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const state = utils.getCacheState();
|
||||||
let primaryKey = "";
|
let primaryKey = "";
|
||||||
const reeval = core.getBooleanInput(constants_1.Inputs.Reeval);
|
const reeval = utils.getInputAsBoolean(constants_1.Inputs.Reeval);
|
||||||
if (!reeval) {
|
if (!reeval) {
|
||||||
// Inputs are reevaluted before the post action, so we want the original key used for restore
|
// Inputs are reevaluted before the post action, so we want the original key used for restore
|
||||||
primaryKey = core.getState(constants_1.State.CachePrimaryKey);
|
primaryKey = core.getState(constants_1.State.CachePrimaryKey);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// choose to reevaluate primary key - resave state to correctly test cache hit
|
// choose to reevaluate primary key - resave state to correctly test cache hit on next run
|
||||||
primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
primaryKey = core.getInput(constants_1.Inputs.Key, { required: true });
|
||||||
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
||||||
}
|
}
|
||||||
|
@ -46797,7 +46803,6 @@ function run() {
|
||||||
utils.logWarning(`Error retrieving key from state.`);
|
utils.logWarning(`Error retrieving key from state.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const state = utils.getCacheState();
|
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,7 +22,12 @@ async function run(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
const primaryKey = core.getInput(Inputs.Key, { required: true });
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
|
||||||
|
// when selecting to reevaluate primary key - state is saved in save step
|
||||||
|
const reeval = utils.getInputAsBoolean(Inputs.Reeval);
|
||||||
|
if (!reeval) {
|
||||||
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||||
|
}
|
||||||
|
|
||||||
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
|
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
|
||||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||||
|
|
|
@ -26,13 +26,15 @@ async function run(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const state = utils.getCacheState();
|
||||||
|
|
||||||
let primaryKey = "";
|
let primaryKey = "";
|
||||||
const reeval = core.getBooleanInput(Inputs.Reeval);
|
const reeval = utils.getInputAsBoolean(Inputs.Reeval);
|
||||||
if (!reeval) {
|
if (!reeval) {
|
||||||
// Inputs are reevaluted before the post action, so we want the original key used for restore
|
// Inputs are reevaluted before the post action, so we want the original key used for restore
|
||||||
primaryKey = core.getState(State.CachePrimaryKey);
|
primaryKey = core.getState(State.CachePrimaryKey);
|
||||||
} else {
|
} else {
|
||||||
// choose to reevaluate primary key - resave state to correctly test cache hit
|
// choose to reevaluate primary key - resave state to correctly test cache hit on next run
|
||||||
primaryKey = core.getInput(Inputs.Key, { required: true });
|
primaryKey = core.getInput(Inputs.Key, { required: true });
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||||
}
|
}
|
||||||
|
@ -41,8 +43,6 @@ async function run(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = utils.getCacheState();
|
|
||||||
|
|
||||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||||
core.info(
|
core.info(
|
||||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||||
|
|
|
@ -65,6 +65,14 @@ export function getInputAsArray(
|
||||||
.filter(x => x !== "");
|
.filter(x => x !== "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getInputAsBoolean(
|
||||||
|
name: string,
|
||||||
|
options?: core.InputOptions
|
||||||
|
): boolean {
|
||||||
|
const value = core.getBooleanInput(name, options);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
export function getInputAsInt(
|
export function getInputAsInt(
|
||||||
name: string,
|
name: string,
|
||||||
options?: core.InputOptions
|
options?: core.InputOptions
|
||||||
|
|
|
@ -12,12 +12,16 @@ export function setInput(name: string, value: string): void {
|
||||||
interface CacheInput {
|
interface CacheInput {
|
||||||
path: string;
|
path: string;
|
||||||
key: string;
|
key: string;
|
||||||
|
// onlyRestore: string;
|
||||||
|
// reeval: string;
|
||||||
restoreKeys?: string[];
|
restoreKeys?: 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.OnlyRestore, input.onlyRestore);
|
||||||
|
// setInput(Inputs.Reeval, input.reeval);
|
||||||
input.restoreKeys &&
|
input.restoreKeys &&
|
||||||
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
||||||
}
|
}
|
||||||
|
@ -27,4 +31,6 @@ export function clearInputs(): void {
|
||||||
delete process.env[getInputName(Inputs.Key)];
|
delete process.env[getInputName(Inputs.Key)];
|
||||||
delete process.env[getInputName(Inputs.RestoreKeys)];
|
delete process.env[getInputName(Inputs.RestoreKeys)];
|
||||||
delete process.env[getInputName(Inputs.UploadChunkSize)];
|
delete process.env[getInputName(Inputs.UploadChunkSize)];
|
||||||
|
delete process.env[getInputName(Inputs.OnlyRestore)];
|
||||||
|
delete process.env[getInputName(Inputs.Reeval)];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue