Skip to content

Commit

Permalink
feat: load inputs in shared constant
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed Aug 24, 2024
1 parent fd52770 commit cbcff9b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
27 changes: 21 additions & 6 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115778,13 +115778,16 @@ __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),
/* harmony export */ "artifactExe": () => (/* binding */ artifactExe),
/* 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);

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down
15 changes: 13 additions & 2 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61389,13 +61389,16 @@ __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),
/* harmony export */ "artifactExe": () => (/* binding */ artifactExe),
/* 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);

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const core = require("@actions/core");

const path = require("path");
const os = require("os");

Expand All @@ -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.
*/
Expand Down
15 changes: 9 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down

0 comments on commit cbcff9b

Please sign in to comment.