From c4c6f27a5bbbd8d0ded1c40e9545c5a504a3c7ad Mon Sep 17 00:00:00 2001 From: Gitea Actions Date: Wed, 30 Apr 2025 10:27:02 +0000 Subject: [PATCH] Deploy version 2.0.0 --- action.yml | 6 +-- dist/index.js | 120 ++++++++++++++++++++++++-------------------------- 2 files changed, 60 insertions(+), 66 deletions(-) diff --git a/action.yml b/action.yml index a8a25fe..23d6f05 100644 --- a/action.yml +++ b/action.yml @@ -1,13 +1,13 @@ name: "MinIO Cache" -description: "Save and restore caches via MinIO/S3." +description: "Save and restore caches, inkl. restore-keys Support." author: "0xMax42" branding: icon: "archive" color: "blue" inputs: - key: - description: "Unique cache key to identify the cache" + keys: + description: "List of cache keys, first is primary key, others are fallbacks" required: true paths: description: "List of paths to cache" diff --git a/dist/index.js b/dist/index.js index bf9ac39..e771e5f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -19680,7 +19680,7 @@ var require_core = __commonJS({ process.env["PATH"] = `${inputPath}${path9.delimiter}${process.env["PATH"]}`; } exports2.addPath = addPath; - function getInput2(name2, options) { + function getInput(name2, options) { const val = process.env[`INPUT_${name2.replace(/ /g, "_").toUpperCase()}`] || ""; if (options && options.required && !val) { throw new Error(`Input required and not supplied: ${name2}`); @@ -19690,9 +19690,9 @@ var require_core = __commonJS({ } return val.trim(); } - exports2.getInput = getInput2; + exports2.getInput = getInput; function getMultilineInput2(name2, options) { - const inputs = getInput2(name2, options).split("\n").filter((x2) => x2 !== ""); + const inputs = getInput(name2, options).split("\n").filter((x2) => x2 !== ""); if (options && options.trimWhitespace === false) { return inputs; } @@ -19702,7 +19702,7 @@ var require_core = __commonJS({ function getBooleanInput(name2, options) { const trueValue = ["true", "True", "TRUE"]; const falseValue = ["false", "False", "FALSE"]; - const val = getInput2(name2, options); + const val = getInput(name2, options); if (trueValue.includes(val)) return true; if (falseValue.includes(val)) @@ -34053,51 +34053,41 @@ var fs14 = __toESM(require("fs")); var import_child_process2 = require("child_process"); var import_util3 = require("util"); var execFileAsync2 = (0, import_util3.promisify)(import_child_process2.execFile); -async function restoreCache(key) { - const zstPath = `/tmp/${key}.tar.zst`; - const tarPath = `/tmp/${key}.tar`; - core2.info(`Downloading cache for key ${key}...`); - let startTime = Date.now(); +async function restoreCache(keys) { const { owner, repo } = getRepoInfo(); - const downloaded = await downloadCache( - { serverUrl: getServerUrl(), token: getToken() }, - owner, - repo, - key, - zstPath - ); - if (!downloaded) { - core2.warning("Cache archive not found, skipping restore."); - return false; + const serverUrl = getServerUrl(); + const token = getToken(); + for (const key of keys) { + const zstPath = `/tmp/${key}.tar.zst`; + const tarPath = `/tmp/${key}.tar`; + core2.info(`\u{1F50D} Probiere Cache-Key: ${key}`); + const downloaded = await downloadCache( + { serverUrl, token }, + owner, + repo, + key, + zstPath + ); + if (!downloaded) { + core2.info(`\u274C Kein Treffer f\xFCr: ${key}`); + continue; + } + const zstSize = fs14.statSync(zstPath).size; + core2.info(`\u2705 Gefunden: ${key} (${formatSize(zstSize)})`); + core2.info("\u{1F4E6} Entpacke Zstandard-Archiv..."); + const startDecompress = Date.now(); + await execFileAsync2("zstd", ["-d", "-o", tarPath, zstPath]); + const decompressTime = ((Date.now() - startDecompress) / 1e3).toFixed(2); + const tarSize = fs14.statSync(tarPath).size; + core2.info(`\u{1F4C2} Extrahiere Tar (${formatSize(tarSize)})...`); + const startExtract = Date.now(); + await execFileAsync2("tar", ["-xf", tarPath, "-C", "/"]); + const extractTime = ((Date.now() - startExtract) / 1e3).toFixed(2); + core2.info(`\u2705 Wiederhergestellt in ${decompressTime}s + ${extractTime}s`); + return key; } - let endTime = Date.now(); - let duration = endTime - startTime; - let durationInSeconds = (duration / 1e3).toFixed(2); - const zstSize = fs14.statSync(zstPath).size; - core2.info( - `Download completed in ${durationInSeconds} seconds (${formatSize(zstSize)})` - ); - core2.info("Decompressing zstd archive..."); - startTime = Date.now(); - await execFileAsync2("zstd", ["-d", "-o", tarPath, zstPath]); - endTime = Date.now(); - duration = endTime - startTime; - durationInSeconds = (duration / 1e3).toFixed(2); - const tarSize = fs14.statSync(tarPath).size; - core2.info( - `Decompression completed in ${durationInSeconds} seconds (${formatSize(zstSize)} -> ${formatSize(tarSize)})` - ); - core2.info("Extracting tar archive with system tar..."); - startTime = Date.now(); - await execFileAsync2("tar", ["-xf", tarPath, "-C", "/"]); - endTime = Date.now(); - duration = endTime - startTime; - durationInSeconds = (duration / 1e3).toFixed(2); - core2.info( - `Extraction completed in ${durationInSeconds} seconds (${formatSize(tarSize)})` - ); - core2.info("Cache successfully restored!"); - return true; + core2.warning("\u{1F7E1} Kein Cache gefunden."); + return null; } // src/index.ts @@ -34105,33 +34095,37 @@ async function run() { try { if (core3.getState("isPost") === "true") { core3.info("Post-job: Saving cache..."); - const key = core3.getState("key"); + const keys = JSON.parse(core3.getState("keys") || "[]"); + const key = keys[0]; const paths = JSON.parse(core3.getState("paths") || "[]"); - if (!key) { - throw new Error("State 'key' not found during Post-Job."); - } + if (!key) throw new Error("State 'key' not found during Post-Job."); if (paths.length === 0) { - throw new Error("State 'paths' not found or empty during Post-Job."); + throw new Error("State 'paths' is empty during Post-Job."); } + core3.info(`Saving cache using primary key: ${key}`); await saveCache(key, paths); } else { core3.info("Pre-job: Restoring cache..."); - const key = core3.getInput("key", { required: true }); - const paths = core3.getMultilineInput("paths", { required: true }).filter( - (p) => p.trim() !== "" + const keys = core3.getMultilineInput("keys", { required: true }).filter( + Boolean ); + const paths = core3.getMultilineInput("paths", { required: true }).filter( + Boolean + ); + if (keys.length === 0) { + throw new Error("At least one cache key must be provided."); + } core3.saveState("isPost", "true"); - core3.saveState("key", key); + core3.saveState("keys", JSON.stringify(keys)); core3.saveState("paths", JSON.stringify(paths)); - const restored = await restoreCache(key); - core3.setOutput("cache-hit", restored ? "true" : "false"); + const restoredKey = await restoreCache(keys); + core3.setOutput("cache-hit", restoredKey ? "true" : "false"); + if (restoredKey) { + core3.setOutput("restored-key", restoredKey); + } } } catch (error) { - if (error instanceof Error) { - core3.setFailed(error.message); - } else { - core3.setFailed(String(error)); - } + core3.setFailed(error instanceof Error ? error.message : String(error)); } } run();