From cbcff9b686bd0ebb6913a681a30b704e64f752cc Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Sat, 24 Aug 2024 15:23:35 -0400 Subject: [PATCH] feat: load inputs in shared constant --- dist/main/index.js | 27 +++++++++++++++++++++------ dist/post/index.js | 15 +++++++++++++-- src/index.js | 11 +++++++++++ src/main.js | 15 +++++++++------ src/post.js | 3 +-- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/dist/main/index.js b/dist/main/index.js index 8c86923..f40bde1 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -115778,6 +115778,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ __nccwpck_require__.d(__webpack_exports__, { /* harmony export */ "ACTION_VERSION": () => (/* binding */ ACTION_VERSION), /* harmony export */ "CARGO_SWEEP_VERSION": () => (/* binding */ CARGO_SWEEP_VERSION), +/* harmony export */ "INPUTS": () => (/* binding */ INPUTS), /* harmony export */ "PARENT_PATH": () => (/* binding */ PARENT_PATH), /* harmony export */ "PATH": () => (/* binding */ PATH), /* harmony export */ "REPO": () => (/* binding */ REPO), @@ -115785,6 +115786,8 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ "artifactName": () => (/* binding */ artifactName), /* harmony export */ "cacheKey": () => (/* binding */ cacheKey) /* harmony export */ }); +const core = __nccwpck_require__(19093); + const path = __nccwpck_require__(71017); const os = __nccwpck_require__(22037); @@ -115798,6 +115801,15 @@ const ACTION_VERSION = "1.3.0"; */ const CARGO_SWEEP_VERSION = "^0.7.0"; +/** + * The values of the inputs specified in `action.yml`. + */ +const INPUTS = { + ghToken: core.getInput("gh-token", { required: false }), + usePrebuilt: core.getBooleanInput("use-prebuilt", { required: true }), + useCache: core.getBooleanInput("use-cache", { required: true }), +}; + /** * The repository to download prebuilt `cargo-sweep` artifacts from. */ @@ -135126,7 +135138,13 @@ async function buildCargoSweep() { } async function downloadCargoSweep() { - const ghToken = core.getInput("gh-token", { required: true }); + const ghToken = shared.INPUTS.ghToken; + + // `ghToken` is only required if `use-prebuilt: true`. + if (ghToken === "") { + throw new Error("Attempted to download prebuilt `cargo-sweep` without `gh-token` specified."); + } + const octokit = github.getOctokit(ghToken); // Find the latest artifact for the given name. @@ -135173,12 +135191,9 @@ async function downloadCargoSweep() { } async function main() { - const useCache = core.getBooleanInput("use-cache", { required: false }); - const usePrebuilt = core.getBooleanInput("use-prebuilt", { required: false }); - let cacheSuccess = undefined; - if (useCache) { + if (shared.INPUTS.useCache) { core.startGroup("Restoring `cargo-sweep` from cache."); cacheSuccess = await cache.restoreCache( @@ -135199,7 +135214,7 @@ async function main() { // If no cache was found or caching is disabled. if (cacheSuccess === undefined) { - if (usePrebuilt) { + if (shared.INPUTS.usePrebuilt) { core.startGroup("Downloading pre-built `cargo-sweep`."); await downloadCargoSweep(); } else { diff --git a/dist/post/index.js b/dist/post/index.js index 386e0a0..ffaaf61 100644 --- a/dist/post/index.js +++ b/dist/post/index.js @@ -61389,6 +61389,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ __nccwpck_require__.d(__webpack_exports__, { /* harmony export */ "ACTION_VERSION": () => (/* binding */ ACTION_VERSION), /* harmony export */ "CARGO_SWEEP_VERSION": () => (/* binding */ CARGO_SWEEP_VERSION), +/* harmony export */ "INPUTS": () => (/* binding */ INPUTS), /* harmony export */ "PARENT_PATH": () => (/* binding */ PARENT_PATH), /* harmony export */ "PATH": () => (/* binding */ PATH), /* harmony export */ "REPO": () => (/* binding */ REPO), @@ -61396,6 +61397,8 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ "artifactName": () => (/* binding */ artifactName), /* harmony export */ "cacheKey": () => (/* binding */ cacheKey) /* harmony export */ }); +const core = __nccwpck_require__(9093); + const path = __nccwpck_require__(1017); const os = __nccwpck_require__(2037); @@ -61409,6 +61412,15 @@ const ACTION_VERSION = "1.3.0"; */ const CARGO_SWEEP_VERSION = "^0.7.0"; +/** + * The values of the inputs specified in `action.yml`. + */ +const INPUTS = { + ghToken: core.getInput("gh-token", { required: false }), + usePrebuilt: core.getBooleanInput("use-prebuilt", { required: true }), + useCache: core.getBooleanInput("use-cache", { required: true }), +}; + /** * The repository to download prebuilt `cargo-sweep` artifacts from. */ @@ -72434,7 +72446,6 @@ const fs = __nccwpck_require__(3292); const shared = __nccwpck_require__(1590); async function main() { - const useCache = core.getBooleanInput("use-cache", { required: false }); const cacheHit = core.getState("cache-hit"); // Recreate `sweep.timestamp` file. @@ -72448,7 +72459,7 @@ async function main() { core.info("Sweeping unused build files."); await exec.exec(`"${shared.PATH}"`, ["sweep", "--file"]); - if (useCache && cacheHit === "false") { + if (shared.INPUTS.useCache && cacheHit === "false") { core.info(`Saving cache with key ${shared.cacheKey()}`); cache.saveCache( diff --git a/src/index.js b/src/index.js index dc599c7..f00eaea 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +const core = require("@actions/core"); + const path = require("path"); const os = require("os"); @@ -11,6 +13,15 @@ export const ACTION_VERSION = "1.3.0"; */ export const CARGO_SWEEP_VERSION = "^0.7.0"; +/** + * The values of the inputs specified in `action.yml`. + */ +export const INPUTS = { + ghToken: core.getInput("gh-token", { required: false }), + usePrebuilt: core.getBooleanInput("use-prebuilt", { required: true }), + useCache: core.getBooleanInput("use-cache", { required: true }), +}; + /** * The repository to download prebuilt `cargo-sweep` artifacts from. */ diff --git a/src/main.js b/src/main.js index 09e0540..11007a7 100644 --- a/src/main.js +++ b/src/main.js @@ -16,7 +16,13 @@ async function buildCargoSweep() { } async function downloadCargoSweep() { - const ghToken = core.getInput("gh-token", { required: true }); + const ghToken = shared.INPUTS.ghToken; + + // `ghToken` is only required if `use-prebuilt: true`. + if (ghToken === "") { + throw new Error("Attempted to download prebuilt `cargo-sweep` without `gh-token` specified."); + } + const octokit = github.getOctokit(ghToken); // Find the latest artifact for the given name. @@ -63,12 +69,9 @@ async function downloadCargoSweep() { } async function main() { - const useCache = core.getBooleanInput("use-cache", { required: false }); - const usePrebuilt = core.getBooleanInput("use-prebuilt", { required: false }); - let cacheSuccess = undefined; - if (useCache) { + if (shared.INPUTS.useCache) { core.startGroup("Restoring `cargo-sweep` from cache."); cacheSuccess = await cache.restoreCache( @@ -89,7 +92,7 @@ async function main() { // If no cache was found or caching is disabled. if (cacheSuccess === undefined) { - if (usePrebuilt) { + if (shared.INPUTS.usePrebuilt) { core.startGroup("Downloading pre-built `cargo-sweep`."); await downloadCargoSweep(); } else { diff --git a/src/post.js b/src/post.js index b3d3645..0adc425 100644 --- a/src/post.js +++ b/src/post.js @@ -8,7 +8,6 @@ const fs = require("fs/promises"); const shared = require("./index"); async function main() { - const useCache = core.getBooleanInput("use-cache", { required: false }); const cacheHit = core.getState("cache-hit"); // Recreate `sweep.timestamp` file. @@ -22,7 +21,7 @@ async function main() { core.info("Sweeping unused build files."); await exec.exec(`"${shared.PATH}"`, ["sweep", "--file"]); - if (useCache && cacheHit === "false") { + if (shared.INPUTS.useCache && cacheHit === "false") { core.info(`Saving cache with key ${shared.cacheKey()}`); cache.saveCache(