Skip to content

Commit

Permalink
Merge branch 'main' into 32-alternative-cache-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Apr 30, 2024
2 parents f1d5864 + 2ba0df0 commit ae16263
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 46 deletions.
28 changes: 14 additions & 14 deletions dist/restore-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94277,7 +94277,7 @@ var Inputs;
Inputs["PrimaryKey"] = "primary-key";
Inputs["RestorePrefixesFirstMatch"] = "restore-prefixes-first-match";
Inputs["RestorePrefixesAllMatches"] = "restore-prefixes-all-matches";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-primary-key-hit";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-hit-primary-key";
Inputs["FailOn"] = "fail-on";
Inputs["Nix"] = "nix";
Inputs["Save"] = "save";
Expand Down Expand Up @@ -94498,7 +94498,7 @@ function restoreImpl(stateProvider, earlyExit) {
}
yield install.installSQLite3();
let restoredKey;
let lookedUpKey;
let lookedUpPrimaryKey;
const restoredKeys = [];
const errorNot = (message) => new Error(`
No cache with the given key ${message}.
Expand All @@ -94510,12 +94510,12 @@ function restoreImpl(stateProvider, earlyExit) {
const primaryKey = inputs.primaryKey;
stateProvider.setState(constants_1.State.CachePrimaryKey, primaryKey);
utils.info(`Searching for a cache with the key "${primaryKey}".`);
lookedUpKey = yield utils.restoreCache({
lookedUpPrimaryKey = yield utils.restoreCache({
primaryKey,
restoreKeys: [],
lookupOnly: true
});
if (!lookedUpKey) {
if (!lookedUpPrimaryKey) {
if (((_a = inputs.failOn) === null || _a === void 0 ? void 0 : _a.keyType) == "primary" &&
((_b = inputs.failOn) === null || _b === void 0 ? void 0 : _b.result) == "miss") {
throw errorNotFound;
Expand All @@ -94524,7 +94524,7 @@ function restoreImpl(stateProvider, earlyExit) {
utils.info(`Could not find a cache.`);
}
}
else if (utils.isExactKeyMatch(primaryKey, lookedUpKey)) {
else if (utils.isExactKeyMatch(primaryKey, lookedUpPrimaryKey)) {
utils.info(`Found a cache with the given "${constants_1.Inputs.PrimaryKey}".`);
core.setOutput(constants_1.Outputs.HitPrimaryKey, true);
if (!inputs.skipRestoreOnHitPrimaryKey) {
Expand All @@ -94541,17 +94541,17 @@ function restoreImpl(stateProvider, earlyExit) {
}
if (inputs.restorePrefixesFirstMatch.length > 0 &&
!restoredKey &&
!(inputs.skipRestoreOnHitPrimaryKey && lookedUpKey)) {
!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
utils.info(`
Searching for a cache using the "${constants_1.Inputs.RestorePrefixesFirstMatch}":
${JSON.stringify(inputs.restorePrefixesFirstMatch)}
`);
const foundKey = yield utils.restoreCache({
const lookedUpRestorePrefixesFirstMatchKey = yield utils.restoreCache({
primaryKey: "",
restoreKeys: inputs.restorePrefixesFirstMatch,
lookupOnly: true
});
if (!foundKey) {
if (!lookedUpRestorePrefixesFirstMatchKey) {
if (((_e = inputs.failOn) === null || _e === void 0 ? void 0 : _e.keyType) == "first-match" &&
inputs.failOn.result == "miss") {
throw errorNotFound;
Expand All @@ -94563,7 +94563,7 @@ function restoreImpl(stateProvider, earlyExit) {
else {
utils.info(`Found a cache using the "${constants_1.Inputs.RestorePrefixesFirstMatch}".`);
core.setOutput(constants_1.Outputs.HitFirstMatch, true);
restoredKey = yield restore.restoreCache(foundKey);
restoredKey = yield restore.restoreCache(lookedUpRestorePrefixesFirstMatchKey);
if (restoredKey) {
restoredKeys.push(...[restoredKey]);
}
Expand All @@ -94573,8 +94573,8 @@ function restoreImpl(stateProvider, earlyExit) {
}
}
}
if (!(inputs.skipRestoreOnHitPrimaryKey && lookedUpKey)) {
restoredKeys.push(...(yield restore.restoreCaches()));
if (!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
restoredKeys.push(...(yield restore.restoreAllMatches()));
}
restoredKey || (restoredKey = "");
// Store the matched cache key in states
Expand Down Expand Up @@ -95399,7 +95399,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.restoreCaches = exports.restoreCache = void 0;
exports.restoreAllMatches = exports.restoreCache = void 0;
const fs_1 = __nccwpck_require__(7147);
const constants_1 = __nccwpck_require__(9042);
const inputs = __importStar(__nccwpck_require__(7063));
Expand Down Expand Up @@ -95443,7 +95443,7 @@ function restoreCache(key, ref) {
});
}
exports.restoreCache = restoreCache;
function restoreCaches() {
function restoreAllMatches() {
return __awaiter(this, void 0, void 0, function* () {
const restoredCaches = [];
if (inputs.restorePrefixesAllMatches.length == 0) {
Expand Down Expand Up @@ -95477,7 +95477,7 @@ function restoreCaches() {
return restoredCaches;
});
}
exports.restoreCaches = restoreCaches;
exports.restoreAllMatches = restoreAllMatches;


/***/ }),
Expand Down
28 changes: 14 additions & 14 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94277,7 +94277,7 @@ var Inputs;
Inputs["PrimaryKey"] = "primary-key";
Inputs["RestorePrefixesFirstMatch"] = "restore-prefixes-first-match";
Inputs["RestorePrefixesAllMatches"] = "restore-prefixes-all-matches";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-primary-key-hit";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-hit-primary-key";
Inputs["FailOn"] = "fail-on";
Inputs["Nix"] = "nix";
Inputs["Save"] = "save";
Expand Down Expand Up @@ -94498,7 +94498,7 @@ function restoreImpl(stateProvider, earlyExit) {
}
yield install.installSQLite3();
let restoredKey;
let lookedUpKey;
let lookedUpPrimaryKey;
const restoredKeys = [];
const errorNot = (message) => new Error(`
No cache with the given key ${message}.
Expand All @@ -94510,12 +94510,12 @@ function restoreImpl(stateProvider, earlyExit) {
const primaryKey = inputs.primaryKey;
stateProvider.setState(constants_1.State.CachePrimaryKey, primaryKey);
utils.info(`Searching for a cache with the key "${primaryKey}".`);
lookedUpKey = yield utils.restoreCache({
lookedUpPrimaryKey = yield utils.restoreCache({
primaryKey,
restoreKeys: [],
lookupOnly: true
});
if (!lookedUpKey) {
if (!lookedUpPrimaryKey) {
if (((_a = inputs.failOn) === null || _a === void 0 ? void 0 : _a.keyType) == "primary" &&
((_b = inputs.failOn) === null || _b === void 0 ? void 0 : _b.result) == "miss") {
throw errorNotFound;
Expand All @@ -94524,7 +94524,7 @@ function restoreImpl(stateProvider, earlyExit) {
utils.info(`Could not find a cache.`);
}
}
else if (utils.isExactKeyMatch(primaryKey, lookedUpKey)) {
else if (utils.isExactKeyMatch(primaryKey, lookedUpPrimaryKey)) {
utils.info(`Found a cache with the given "${constants_1.Inputs.PrimaryKey}".`);
core.setOutput(constants_1.Outputs.HitPrimaryKey, true);
if (!inputs.skipRestoreOnHitPrimaryKey) {
Expand All @@ -94541,17 +94541,17 @@ function restoreImpl(stateProvider, earlyExit) {
}
if (inputs.restorePrefixesFirstMatch.length > 0 &&
!restoredKey &&
!(inputs.skipRestoreOnHitPrimaryKey && lookedUpKey)) {
!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
utils.info(`
Searching for a cache using the "${constants_1.Inputs.RestorePrefixesFirstMatch}":
${JSON.stringify(inputs.restorePrefixesFirstMatch)}
`);
const foundKey = yield utils.restoreCache({
const lookedUpRestorePrefixesFirstMatchKey = yield utils.restoreCache({
primaryKey: "",
restoreKeys: inputs.restorePrefixesFirstMatch,
lookupOnly: true
});
if (!foundKey) {
if (!lookedUpRestorePrefixesFirstMatchKey) {
if (((_e = inputs.failOn) === null || _e === void 0 ? void 0 : _e.keyType) == "first-match" &&
inputs.failOn.result == "miss") {
throw errorNotFound;
Expand All @@ -94563,7 +94563,7 @@ function restoreImpl(stateProvider, earlyExit) {
else {
utils.info(`Found a cache using the "${constants_1.Inputs.RestorePrefixesFirstMatch}".`);
core.setOutput(constants_1.Outputs.HitFirstMatch, true);
restoredKey = yield restore.restoreCache(foundKey);
restoredKey = yield restore.restoreCache(lookedUpRestorePrefixesFirstMatchKey);
if (restoredKey) {
restoredKeys.push(...[restoredKey]);
}
Expand All @@ -94573,8 +94573,8 @@ function restoreImpl(stateProvider, earlyExit) {
}
}
}
if (!(inputs.skipRestoreOnHitPrimaryKey && lookedUpKey)) {
restoredKeys.push(...(yield restore.restoreCaches()));
if (!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
restoredKeys.push(...(yield restore.restoreAllMatches()));
}
restoredKey || (restoredKey = "");
// Store the matched cache key in states
Expand Down Expand Up @@ -95399,7 +95399,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.restoreCaches = exports.restoreCache = void 0;
exports.restoreAllMatches = exports.restoreCache = void 0;
const fs_1 = __nccwpck_require__(7147);
const constants_1 = __nccwpck_require__(9042);
const inputs = __importStar(__nccwpck_require__(7063));
Expand Down Expand Up @@ -95443,7 +95443,7 @@ function restoreCache(key, ref) {
});
}
exports.restoreCache = restoreCache;
function restoreCaches() {
function restoreAllMatches() {
return __awaiter(this, void 0, void 0, function* () {
const restoredCaches = [];
if (inputs.restorePrefixesAllMatches.length == 0) {
Expand Down Expand Up @@ -95477,7 +95477,7 @@ function restoreCaches() {
return restoredCaches;
});
}
exports.restoreCaches = restoreCaches;
exports.restoreAllMatches = restoreAllMatches;


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/save-only/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85893,7 +85893,7 @@ var Inputs;
Inputs["PrimaryKey"] = "primary-key";
Inputs["RestorePrefixesFirstMatch"] = "restore-prefixes-first-match";
Inputs["RestorePrefixesAllMatches"] = "restore-prefixes-all-matches";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-primary-key-hit";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-hit-primary-key";
Inputs["FailOn"] = "fail-on";
Inputs["Nix"] = "nix";
Inputs["Save"] = "save";
Expand Down
2 changes: 1 addition & 1 deletion dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85893,7 +85893,7 @@ var Inputs;
Inputs["PrimaryKey"] = "primary-key";
Inputs["RestorePrefixesFirstMatch"] = "restore-prefixes-first-match";
Inputs["RestorePrefixesAllMatches"] = "restore-prefixes-all-matches";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-primary-key-hit";
Inputs["SkipRestoreOnHitPrimaryKey"] = "skip-restore-on-hit-primary-key";
Inputs["FailOn"] = "fail-on";
Inputs["Nix"] = "nix";
Inputs["Save"] = "save";
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export enum Inputs {
RestorePrefixesFirstMatch = "restore-prefixes-first-match", // Input for cache, restore actions
RestorePrefixesAllMatches = "restore-prefixes-all-matches", // Input for cache, restore actions

SkipRestoreOnHitPrimaryKey = "skip-restore-on-primary-key-hit", // Input for cache, restore, actions
SkipRestoreOnHitPrimaryKey = "skip-restore-on-hit-primary-key", // Input for cache, restore, actions

FailOn = "fail-on", // Input for cache, restore actions

Expand Down
31 changes: 17 additions & 14 deletions src/restoreImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function restoreImpl(
await install.installSQLite3();

let restoredKey: string | undefined;
let lookedUpKey: string | undefined;
let lookedUpPrimaryKey: string | undefined;
const restoredKeys: string[] = [];

const errorNot = (message: string) =>
Expand All @@ -57,13 +57,13 @@ export async function restoreImpl(
stateProvider.setState(State.CachePrimaryKey, primaryKey);

utils.info(`Searching for a cache with the key "${primaryKey}".`);
lookedUpKey = await utils.restoreCache({
lookedUpPrimaryKey = await utils.restoreCache({
primaryKey,
restoreKeys: [],
lookupOnly: true
});

if (!lookedUpKey) {
if (!lookedUpPrimaryKey) {
if (
inputs.failOn?.keyType == "primary" &&
inputs.failOn?.result == "miss"
Expand All @@ -72,7 +72,7 @@ export async function restoreImpl(
} else {
utils.info(`Could not find a cache.`);
}
} else if (utils.isExactKeyMatch(primaryKey, lookedUpKey)) {
} else if (utils.isExactKeyMatch(primaryKey, lookedUpPrimaryKey)) {
utils.info(
`Found a cache with the given "${Inputs.PrimaryKey}".`
);
Expand All @@ -95,7 +95,7 @@ export async function restoreImpl(
if (
inputs.restorePrefixesFirstMatch.length > 0 &&
!restoredKey &&
!(inputs.skipRestoreOnHitPrimaryKey && lookedUpKey)
!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)
) {
utils.info(
`
Expand All @@ -106,13 +106,14 @@ export async function restoreImpl(
`
);

const foundKey = await utils.restoreCache({
primaryKey: "",
restoreKeys: inputs.restorePrefixesFirstMatch,
lookupOnly: true
});
const lookedUpRestorePrefixesFirstMatchKey =
await utils.restoreCache({
primaryKey: "",
restoreKeys: inputs.restorePrefixesFirstMatch,
lookupOnly: true
});

if (!foundKey) {
if (!lookedUpRestorePrefixesFirstMatchKey) {
if (
inputs.failOn?.keyType == "first-match" &&
inputs.failOn.result == "miss"
Expand All @@ -127,7 +128,9 @@ export async function restoreImpl(
);
core.setOutput(Outputs.HitFirstMatch, true);

restoredKey = await restore.restoreCache(foundKey);
restoredKey = await restore.restoreCache(
lookedUpRestorePrefixesFirstMatchKey
);
if (restoredKey) {
restoredKeys.push(...[restoredKey]);
} else if (
Expand All @@ -139,8 +142,8 @@ export async function restoreImpl(
}
}

if (!(inputs.skipRestoreOnHitPrimaryKey && lookedUpKey)) {
restoredKeys.push(...(await restore.restoreCaches()));
if (!(lookedUpPrimaryKey && inputs.skipRestoreOnHitPrimaryKey)) {
restoredKeys.push(...(await restore.restoreAllMatches()));
}

restoredKey ||= "";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function restoreCache(key: string, ref?: string) {
}
}

export async function restoreCaches() {
export async function restoreAllMatches() {
const restoredCaches: string[] = [];

if (inputs.restorePrefixesAllMatches.length == 0) {
Expand Down

0 comments on commit ae16263

Please sign in to comment.