refactor: replace core.getBooleanInput with getInput

This commit is contained in:
Alfi Maulana 2024-08-06 16:22:27 +07:00
parent bf49a53fb3
commit 7f54b1b0e1
No known key found for this signature in database
GPG Key ID: 2242A64C2A8DF5A4
3 changed files with 8 additions and 20 deletions

2
dist/index.js generated vendored
View File

@ -26774,7 +26774,7 @@ function getInputs() {
cxxFlags: (0,core.getMultilineInput)("cxx-flags").join(" "), cxxFlags: (0,core.getMultilineInput)("cxx-flags").join(" "),
options: (0,core.getMultilineInput)("options").flatMap((opts) => opts.split(" ")), options: (0,core.getMultilineInput)("options").flatMap((opts) => opts.split(" ")),
args: (0,core.getMultilineInput)("args").flatMap((args) => args.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(" ")), buildArgs: (0,core.getMultilineInput)("build-args").flatMap((args) => args.split(" ")),
}; };
} }

View File

@ -3,7 +3,6 @@ import path from "node:path";
import type { Inputs } from "./inputs.js"; import type { Inputs } from "./inputs.js";
jest.unstable_mockModule("@actions/core", () => ({ jest.unstable_mockModule("@actions/core", () => ({
getBooleanInput: jest.fn(),
getMultilineInput: jest.fn(), getMultilineInput: jest.fn(),
})); }));
@ -11,7 +10,6 @@ describe("get action inputs", () => {
interface TestCase { interface TestCase {
name: string; name: string;
env?: Record<string, string>; env?: Record<string, string>;
booleanInputs?: Record<string, boolean>;
multilineInputs?: Record<string, string[]>; multilineInputs?: Record<string, string[]>;
expectedInputs?: Partial<Inputs>; expectedInputs?: Partial<Inputs>;
} }
@ -85,8 +83,8 @@ describe("get action inputs", () => {
}, },
{ {
name: "with run build specified", name: "with run build specified",
booleanInputs: { "run-build": false }, env: { "INPUT_RUN-BUILD": "true" },
expectedInputs: { runBuild: false }, expectedInputs: { runBuild: true },
}, },
{ {
name: "with additional build arguments specified", name: "with additional build arguments specified",
@ -95,15 +93,13 @@ describe("get action inputs", () => {
}, },
{ {
name: "with all specified", name: "with all specified",
booleanInputs: {
"run-build": false,
},
env: { env: {
"INPUT_SOURCE-DIR": "project", "INPUT_SOURCE-DIR": "project",
"INPUT_BUILD-DIR": "output", "INPUT_BUILD-DIR": "output",
INPUT_GENERATOR: "Ninja", INPUT_GENERATOR: "Ninja",
"INPUT_C-COMPILER": "clang", "INPUT_C-COMPILER": "clang",
"INPUT_CXX-COMPILER": "clang++", "INPUT_CXX-COMPILER": "clang++",
"INPUT_RUN-BUILD": "true",
}, },
multilineInputs: { multilineInputs: {
"c-flags": ["-Werror -Wall", "-Wextra"], "c-flags": ["-Werror -Wall", "-Wextra"],
@ -122,7 +118,7 @@ describe("get action inputs", () => {
cxxFlags: "-Werror -Wall -Wextra -Wpedantic", cxxFlags: "-Werror -Wall -Wextra -Wpedantic",
options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"], options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"],
args: ["-Wdev", "-Wdeprecated", "--fresh"], args: ["-Wdev", "-Wdeprecated", "--fresh"],
runBuild: false, runBuild: true,
buildArgs: ["--target", "foo", "--parallel", "8"], buildArgs: ["--target", "foo", "--parallel", "8"],
}, },
}, },
@ -133,14 +129,6 @@ describe("get action inputs", () => {
const { getInputs } = await import("./inputs.js"); const { getInputs } = await import("./inputs.js");
const core = await import("@actions/core"); const core = await import("@actions/core");
const booleanInputs: Record<string, boolean> = {
"run-build": true,
...testCase.booleanInputs,
};
jest.mocked(core.getBooleanInput).mockImplementation((name) => {
return booleanInputs[name] ?? false;
});
const prevEnv = process.env; const prevEnv = process.env;
process.env = { process.env = {
...process.env, ...process.env,
@ -162,7 +150,7 @@ describe("get action inputs", () => {
cxxFlags: "", cxxFlags: "",
options: [], options: [],
args: [], args: [],
runBuild: true, runBuild: false,
buildArgs: [], buildArgs: [],
...testCase.expectedInputs, ...testCase.expectedInputs,
}); });

View File

@ -1,4 +1,4 @@
import { getBooleanInput, getMultilineInput } from "@actions/core"; import { getMultilineInput } from "@actions/core";
import path from "node:path"; import path from "node:path";
export interface Inputs { export interface Inputs {
@ -37,7 +37,7 @@ export function getInputs(): Inputs {
cxxFlags: getMultilineInput("cxx-flags").join(" "), cxxFlags: getMultilineInput("cxx-flags").join(" "),
options: getMultilineInput("options").flatMap((opts) => opts.split(" ")), options: getMultilineInput("options").flatMap((opts) => opts.split(" ")),
args: getMultilineInput("args").flatMap((args) => args.split(" ")), args: getMultilineInput("args").flatMap((args) => args.split(" ")),
runBuild: getBooleanInput("run-build"), runBuild: getInput("run-build") == "true",
buildArgs: getMultilineInput("build-args").flatMap((args) => buildArgs: getMultilineInput("build-args").flatMap((args) =>
args.split(" "), args.split(" "),
), ),