From 7f54b1b0e116b119e4721fe67253c57a740aabc7 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 6 Aug 2024 16:22:27 +0700 Subject: [PATCH] refactor: replace `core.getBooleanInput` with `getInput` --- dist/index.js | 2 +- src/inputs.test.ts | 22 +++++----------------- src/inputs.ts | 4 ++-- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/dist/index.js b/dist/index.js index a059e7a..7f970b3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26774,7 +26774,7 @@ function getInputs() { cxxFlags: (0,core.getMultilineInput)("cxx-flags").join(" "), options: (0,core.getMultilineInput)("options").flatMap((opts) => opts.split(" ")), args: (0,core.getMultilineInput)("args").flatMap((args) => args.split(" ")), - runBuild: (0,core.getBooleanInput)("run-build"), + runBuild: getInput("run-build") == "true", buildArgs: (0,core.getMultilineInput)("build-args").flatMap((args) => args.split(" ")), }; } diff --git a/src/inputs.test.ts b/src/inputs.test.ts index 4d4de7d..6ea7f29 100644 --- a/src/inputs.test.ts +++ b/src/inputs.test.ts @@ -3,7 +3,6 @@ import path from "node:path"; import type { Inputs } from "./inputs.js"; jest.unstable_mockModule("@actions/core", () => ({ - getBooleanInput: jest.fn(), getMultilineInput: jest.fn(), })); @@ -11,7 +10,6 @@ describe("get action inputs", () => { interface TestCase { name: string; env?: Record; - booleanInputs?: Record; multilineInputs?: Record; expectedInputs?: Partial; } @@ -85,8 +83,8 @@ describe("get action inputs", () => { }, { name: "with run build specified", - booleanInputs: { "run-build": false }, - expectedInputs: { runBuild: false }, + env: { "INPUT_RUN-BUILD": "true" }, + expectedInputs: { runBuild: true }, }, { name: "with additional build arguments specified", @@ -95,15 +93,13 @@ describe("get action inputs", () => { }, { name: "with all specified", - booleanInputs: { - "run-build": false, - }, env: { "INPUT_SOURCE-DIR": "project", "INPUT_BUILD-DIR": "output", INPUT_GENERATOR: "Ninja", "INPUT_C-COMPILER": "clang", "INPUT_CXX-COMPILER": "clang++", + "INPUT_RUN-BUILD": "true", }, multilineInputs: { "c-flags": ["-Werror -Wall", "-Wextra"], @@ -122,7 +118,7 @@ describe("get action inputs", () => { cxxFlags: "-Werror -Wall -Wextra -Wpedantic", options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"], args: ["-Wdev", "-Wdeprecated", "--fresh"], - runBuild: false, + runBuild: true, buildArgs: ["--target", "foo", "--parallel", "8"], }, }, @@ -133,14 +129,6 @@ describe("get action inputs", () => { const { getInputs } = await import("./inputs.js"); const core = await import("@actions/core"); - const booleanInputs: Record = { - "run-build": true, - ...testCase.booleanInputs, - }; - jest.mocked(core.getBooleanInput).mockImplementation((name) => { - return booleanInputs[name] ?? false; - }); - const prevEnv = process.env; process.env = { ...process.env, @@ -162,7 +150,7 @@ describe("get action inputs", () => { cxxFlags: "", options: [], args: [], - runBuild: true, + runBuild: false, buildArgs: [], ...testCase.expectedInputs, }); diff --git a/src/inputs.ts b/src/inputs.ts index 0ab9779..39d46c5 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -1,4 +1,4 @@ -import { getBooleanInput, getMultilineInput } from "@actions/core"; +import { getMultilineInput } from "@actions/core"; import path from "node:path"; export interface Inputs { @@ -37,7 +37,7 @@ export function getInputs(): Inputs { cxxFlags: getMultilineInput("cxx-flags").join(" "), options: getMultilineInput("options").flatMap((opts) => opts.split(" ")), args: getMultilineInput("args").flatMap((args) => args.split(" ")), - runBuild: getBooleanInput("run-build"), + runBuild: getInput("run-build") == "true", buildArgs: getMultilineInput("build-args").flatMap((args) => args.split(" "), ),