@@ -86178,32 +86178,98 @@ const github = __nccwpck_require__(5438);
86178
86178
const fs = __nccwpck_require__(7147);
86179
86179
const os = __nccwpck_require__(2037);
86180
86180
const path = __nccwpck_require__(1017);
86181
+ const { State } = __nccwpck_require__(4438);
86181
86182
86183
+ // Define constants for cache paths and prefix
86182
86184
const HOME = os.homedir();
86183
86185
const PLATFORM = os.platform();
86184
86186
const CACHE_PATHS = [path.join(HOME, ".foundry/cache/rpc")];
86187
+ const CACHE_PREFIX = `${PLATFORM}-foundry-chain-fork-`;
86185
86188
86189
+ /**
86190
+ * Constructs the primary key for the cache using a custom key input.
86191
+ * @param {string} customKeyInput - The custom part of the key provided by the user.
86192
+ * @returns {string} The complete primary key for the cache.
86193
+ */
86194
+ function getPrimaryKey(customKeyInput) {
86195
+ if (!customKeyInput) {
86196
+ return `${CACHE_PREFIX}${github.context.sha}`;
86197
+ }
86198
+ return `${CACHE_PREFIX}${customKeyInput.trim()}`;
86199
+ }
86200
+
86201
+ /**
86202
+ * Constructs an array of restore keys based on user input and a default prefix.
86203
+ * @param {string} customRestoreKeysInput - Newline-separated string of custom restore keys.
86204
+ * @returns {string[]} An array of restore keys for the cache.
86205
+ */
86206
+ function getRestoreKeys(customRestoreKeysInput) {
86207
+ const defaultRestoreKeys = [CACHE_PREFIX];
86208
+ if (!customRestoreKeysInput) {
86209
+ return defaultRestoreKeys;
86210
+ }
86211
+ const restoreKeys = customRestoreKeysInput
86212
+ .split(/[\r\n]/)
86213
+ .map((input) => input.trim())
86214
+ .filter((input) => input !== "")
86215
+ .map((input) => `${CACHE_PREFIX}${input}`);
86216
+ return [...restoreKeys, ...defaultRestoreKeys];
86217
+ }
86218
+
86219
+ /**
86220
+ * Restores the RPC cache using the provided keys.
86221
+ */
86186
86222
async function restoreRPCCache() {
86187
- const primaryKey = PLATFORM + "-foundry-chain-fork-" + github.context.sha;
86188
- const restoreKeys = [PLATFORM + "-foundry-chain-fork-"];
86189
- const cacheKey = await cache.restoreCache(CACHE_PATHS, primaryKey, restoreKeys);
86190
- if (!cacheKey) {
86223
+ const customKeyInput = core.getInput("cache-key");
86224
+ const primaryKey = getPrimaryKey(customKeyInput);
86225
+ core.saveState(State.CachePrimaryKey, primaryKey);
86226
+
86227
+ const customRestoreKeysInput = core.getInput("cache-restore-keys");
86228
+ const restoreKeys = getRestoreKeys(customRestoreKeysInput);
86229
+ const matchedKey = await cache.restoreCache(CACHE_PATHS, primaryKey, restoreKeys);
86230
+
86231
+ if (!matchedKey) {
86191
86232
core.info("Cache not found");
86192
86233
return;
86193
86234
}
86194
- core.info(`Cache restored from key: ${cacheKey}`);
86235
+
86236
+ core.saveState(State.CacheMatchedKey, matchedKey);
86237
+ core.info(`Cache restored from key: ${matchedKey}`);
86195
86238
}
86196
86239
86240
+ /**
86241
+ * Saves the RPC cache using the primary key saved in the state.
86242
+ * If the cache was already saved with the primary key, it will not save it again.
86243
+ */
86197
86244
async function saveCache() {
86198
- const primaryKey = PLATFORM + "-foundry-chain-fork-" + github.context.sha;
86245
+ const primaryKey = core.getState(State.CachePrimaryKey);
86246
+ const matchedKey = core.getState(State.CacheMatchedKey);
86247
+
86248
+ // If the cache path does not exist, do not save the cache
86199
86249
if (!fs.existsSync(CACHE_PATHS[0])) {
86200
- core.info(`Cache path does not exist, not saving cache : ${CACHE_PATHS[0]}`);
86250
+ core.info(`Cache path does not exist, not saving cache: ${CACHE_PATHS[0]}`);
86201
86251
return;
86202
86252
}
86253
+
86254
+ // If the primary key is not generated, do not save the cache
86255
+ if (!primaryKey) {
86256
+ core.info("Primary key was not generated. Please check the log messages above for more errors or information");
86257
+ return;
86258
+ }
86259
+
86260
+ // If the primary key and the matched key are the same, this means the cache was already saved
86261
+ if (primaryKey === matchedKey) {
86262
+ core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
86263
+ return;
86264
+ }
86265
+
86203
86266
const cacheId = await cache.saveCache(CACHE_PATHS, primaryKey);
86267
+
86268
+ // If the cacheId is -1, the saving failed with an error message log. No additional logging is needed.
86204
86269
if (cacheId === -1) {
86205
86270
return;
86206
86271
}
86272
+
86207
86273
core.info(`Cache saved with the key: ${primaryKey}`);
86208
86274
}
86209
86275
@@ -86213,6 +86279,23 @@ module.exports = {
86213
86279
};
86214
86280
86215
86281
86282
+ /***/ }),
86283
+
86284
+ /***/ 4438:
86285
+ /***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
86286
+
86287
+ "use strict";
86288
+ __nccwpck_require__.r(__webpack_exports__);
86289
+ /* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
86290
+ /* harmony export */ "State": () => (/* binding */ State)
86291
+ /* harmony export */ });
86292
+ // Enum for the cache primary key and result key.
86293
+ const State = {
86294
+ CachePrimaryKey: "CACHE_KEY",
86295
+ CacheMatchedKey: "CACHE_RESULT",
86296
+ };
86297
+
86298
+
86216
86299
/***/ }),
86217
86300
86218
86301
/***/ 4351:
@@ -86610,6 +86693,34 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
86610
86693
/******/ }
86611
86694
/******/
86612
86695
/************************************************************************/
86696
+ /******/ /* webpack/runtime/define property getters */
86697
+ /******/ (() => {
86698
+ /******/ // define getter functions for harmony exports
86699
+ /******/ __nccwpck_require__.d = (exports, definition) => {
86700
+ /******/ for(var key in definition) {
86701
+ /******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
86702
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
86703
+ /******/ }
86704
+ /******/ }
86705
+ /******/ };
86706
+ /******/ })();
86707
+ /******/
86708
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
86709
+ /******/ (() => {
86710
+ /******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
86711
+ /******/ })();
86712
+ /******/
86713
+ /******/ /* webpack/runtime/make namespace object */
86714
+ /******/ (() => {
86715
+ /******/ // define __esModule on exports
86716
+ /******/ __nccwpck_require__.r = (exports) => {
86717
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
86718
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
86719
+ /******/ }
86720
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
86721
+ /******/ };
86722
+ /******/ })();
86723
+ /******/
86613
86724
/******/ /* webpack/runtime/compat */
86614
86725
/******/
86615
86726
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
0 commit comments