mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-21 19:11:21 +00:00
refactor: replace core.getMultilineInput
with getInput
This commit is contained in:
parent
7f54b1b0e1
commit
350e2b14c1
17
dist/index.js
generated
vendored
17
dist/index.js
generated
vendored
@ -26752,7 +26752,6 @@ const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(impo
|
|||||||
var external_node_path_default = /*#__PURE__*/__nccwpck_require__.n(external_node_path_namespaceObject);
|
var external_node_path_default = /*#__PURE__*/__nccwpck_require__.n(external_node_path_namespaceObject);
|
||||||
;// CONCATENATED MODULE: ./src/inputs.ts
|
;// CONCATENATED MODULE: ./src/inputs.ts
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an action input.
|
* Retrieves an action input.
|
||||||
* @param key - The key of the action input.
|
* @param key - The key of the action input.
|
||||||
@ -26770,12 +26769,18 @@ function getInputs() {
|
|||||||
generator: getInput("generator"),
|
generator: getInput("generator"),
|
||||||
cCompiler: getInput("c-compiler"),
|
cCompiler: getInput("c-compiler"),
|
||||||
cxxCompiler: getInput("cxx-compiler"),
|
cxxCompiler: getInput("cxx-compiler"),
|
||||||
cFlags: (0,core.getMultilineInput)("c-flags").join(" "),
|
cFlags: getInput("c-flags").replaceAll(/\s+/g, " "),
|
||||||
cxxFlags: (0,core.getMultilineInput)("cxx-flags").join(" "),
|
cxxFlags: getInput("cxx-flags").replaceAll(/\s+/g, " "),
|
||||||
options: (0,core.getMultilineInput)("options").flatMap((opts) => opts.split(" ")),
|
options: getInput("options")
|
||||||
args: (0,core.getMultilineInput)("args").flatMap((args) => args.split(" ")),
|
.split(/\s+/)
|
||||||
|
.filter((arg) => arg != ""),
|
||||||
|
args: getInput("args")
|
||||||
|
.split(/\s+/)
|
||||||
|
.filter((arg) => arg != ""),
|
||||||
runBuild: getInput("run-build") == "true",
|
runBuild: getInput("run-build") == "true",
|
||||||
buildArgs: (0,core.getMultilineInput)("build-args").flatMap((args) => args.split(" ")),
|
buildArgs: getInput("build-args")
|
||||||
|
.split(/\s+/)
|
||||||
|
.filter((arg) => arg != ""),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
import { jest } from "@jest/globals";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { Inputs } from "./inputs.js";
|
import { Inputs, getInputs } from "./inputs.js";
|
||||||
|
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
|
||||||
getMultilineInput: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("get action inputs", () => {
|
describe("get action inputs", () => {
|
||||||
interface TestCase {
|
interface TestCase {
|
||||||
name: string;
|
name: string;
|
||||||
env?: Record<string, string>;
|
env?: Record<string, string>;
|
||||||
multilineInputs?: Record<string, string[]>;
|
|
||||||
expectedInputs?: Partial<Inputs>;
|
expectedInputs?: Partial<Inputs>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,18 +53,18 @@ describe("get action inputs", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with C flags specified",
|
name: "with C flags specified",
|
||||||
multilineInputs: { "c-flags": ["-Werror -Wall", "-Wextra"] },
|
env: { "INPUT_C-FLAGS": "-Werror -Wall\n-Wextra" },
|
||||||
expectedInputs: { cFlags: "-Werror -Wall -Wextra" },
|
expectedInputs: { cFlags: "-Werror -Wall -Wextra" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with C++ flags specified",
|
name: "with C++ flags specified",
|
||||||
multilineInputs: { "cxx-flags": ["-Werror -Wall", "-Wextra -Wpedantic"] },
|
env: { "INPUT_CXX-FLAGS": "-Werror -Wall\n-Wextra -Wpedantic" },
|
||||||
expectedInputs: { cxxFlags: "-Werror -Wall -Wextra -Wpedantic" },
|
expectedInputs: { cxxFlags: "-Werror -Wall -Wextra -Wpedantic" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with additional options specified",
|
name: "with additional options specified",
|
||||||
multilineInputs: {
|
env: {
|
||||||
options: ["BUILD_TESTING=ON BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"],
|
INPUT_OPTIONS: "BUILD_TESTING=ON BUILD_EXAMPLES=ON\nBUILD_DOCS=ON",
|
||||||
},
|
},
|
||||||
expectedInputs: {
|
expectedInputs: {
|
||||||
options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"],
|
options: ["BUILD_TESTING=ON", "BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"],
|
||||||
@ -78,7 +72,7 @@ describe("get action inputs", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with additional arguments specified",
|
name: "with additional arguments specified",
|
||||||
multilineInputs: { args: ["-Wdev -Wdeprecated", "--fresh"] },
|
env: { INPUT_ARGS: "-Wdev -Wdeprecated\n--fresh" },
|
||||||
expectedInputs: { args: ["-Wdev", "-Wdeprecated", "--fresh"] },
|
expectedInputs: { args: ["-Wdev", "-Wdeprecated", "--fresh"] },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -88,7 +82,7 @@ describe("get action inputs", () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with additional build arguments specified",
|
name: "with additional build arguments specified",
|
||||||
multilineInputs: { "build-args": ["--target foo", "--parallel 8"] },
|
env: { "INPUT_BUILD-ARGS": "--target foo\n--parallel 8" },
|
||||||
expectedInputs: { buildArgs: ["--target", "foo", "--parallel", "8"] },
|
expectedInputs: { buildArgs: ["--target", "foo", "--parallel", "8"] },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -99,14 +93,12 @@ describe("get action inputs", () => {
|
|||||||
INPUT_GENERATOR: "Ninja",
|
INPUT_GENERATOR: "Ninja",
|
||||||
"INPUT_C-COMPILER": "clang",
|
"INPUT_C-COMPILER": "clang",
|
||||||
"INPUT_CXX-COMPILER": "clang++",
|
"INPUT_CXX-COMPILER": "clang++",
|
||||||
|
"INPUT_C-FLAGS": "-Werror -Wall\n-Wextra",
|
||||||
|
"INPUT_CXX-FLAGS": "-Werror -Wall\n-Wextra -Wpedantic",
|
||||||
|
INPUT_OPTIONS: "BUILD_TESTING=ON BUILD_EXAMPLES=ON\nBUILD_DOCS=ON",
|
||||||
|
INPUT_ARGS: "-Wdev -Wdeprecated\n--fresh",
|
||||||
"INPUT_RUN-BUILD": "true",
|
"INPUT_RUN-BUILD": "true",
|
||||||
},
|
"INPUT_BUILD-ARGS": "--target foo\n--parallel 8",
|
||||||
multilineInputs: {
|
|
||||||
"c-flags": ["-Werror -Wall", "-Wextra"],
|
|
||||||
"cxx-flags": ["-Werror -Wall", "-Wextra -Wpedantic"],
|
|
||||||
options: ["BUILD_TESTING=ON BUILD_EXAMPLES=ON", "BUILD_DOCS=ON"],
|
|
||||||
args: ["-Wdev -Wdeprecated", "--fresh"],
|
|
||||||
"build-args": ["--target foo", "--parallel 8"],
|
|
||||||
},
|
},
|
||||||
expectedInputs: {
|
expectedInputs: {
|
||||||
sourceDir: "project",
|
sourceDir: "project",
|
||||||
@ -126,20 +118,12 @@ describe("get action inputs", () => {
|
|||||||
|
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
it(`should get the action inputs ${testCase.name}`, async () => {
|
it(`should get the action inputs ${testCase.name}`, async () => {
|
||||||
const { getInputs } = await import("./inputs.js");
|
|
||||||
const core = await import("@actions/core");
|
|
||||||
|
|
||||||
const prevEnv = process.env;
|
const prevEnv = process.env;
|
||||||
process.env = {
|
process.env = {
|
||||||
...process.env,
|
...process.env,
|
||||||
...testCase.env,
|
...testCase.env,
|
||||||
};
|
};
|
||||||
|
|
||||||
const multilineInputs = { ...testCase.multilineInputs };
|
|
||||||
jest.mocked(core.getMultilineInput).mockImplementation((name) => {
|
|
||||||
return multilineInputs[name] ?? [];
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(getInputs()).toStrictEqual({
|
expect(getInputs()).toStrictEqual({
|
||||||
sourceDir: "",
|
sourceDir: "",
|
||||||
buildDir: "build",
|
buildDir: "build",
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { getMultilineInput } from "@actions/core";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
@ -33,13 +32,17 @@ export function getInputs(): Inputs {
|
|||||||
generator: getInput("generator"),
|
generator: getInput("generator"),
|
||||||
cCompiler: getInput("c-compiler"),
|
cCompiler: getInput("c-compiler"),
|
||||||
cxxCompiler: getInput("cxx-compiler"),
|
cxxCompiler: getInput("cxx-compiler"),
|
||||||
cFlags: getMultilineInput("c-flags").join(" "),
|
cFlags: getInput("c-flags").replaceAll(/\s+/g, " "),
|
||||||
cxxFlags: getMultilineInput("cxx-flags").join(" "),
|
cxxFlags: getInput("cxx-flags").replaceAll(/\s+/g, " "),
|
||||||
options: getMultilineInput("options").flatMap((opts) => opts.split(" ")),
|
options: getInput("options")
|
||||||
args: getMultilineInput("args").flatMap((args) => args.split(" ")),
|
.split(/\s+/)
|
||||||
|
.filter((arg) => arg != ""),
|
||||||
|
args: getInput("args")
|
||||||
|
.split(/\s+/)
|
||||||
|
.filter((arg) => arg != ""),
|
||||||
runBuild: getInput("run-build") == "true",
|
runBuild: getInput("run-build") == "true",
|
||||||
buildArgs: getMultilineInput("build-args").flatMap((args) =>
|
buildArgs: getInput("build-args")
|
||||||
args.split(" "),
|
.split(/\s+/)
|
||||||
),
|
.filter((arg) => arg != ""),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user