From 82bd44ab08f40ead824f70686d05e77b05016c35 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 4 Mar 2024 21:49:28 +0700 Subject: [PATCH] feat: specify default input value in `getInputs` function --- dist/index.js | 20 ++++++-------------- src/index.ts | 16 ++++------------ src/inputs.ts | 4 ++-- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/dist/index.js b/dist/index.js index ee29e4c..1b955ef 100644 --- a/dist/index.js +++ b/dist/index.js @@ -27704,8 +27704,8 @@ var io = __nccwpck_require__(1793); function getInputs() { return { - sourceDir: (0,core.getInput)("source-dir"), - buildDir: (0,core.getInput)("build-dir"), + sourceDir: (0,core.getInput)("source-dir") || ".", + buildDir: (0,core.getInput)("build-dir") || "build", generator: (0,core.getInput)("generator"), cCompiler: (0,core.getInput)("c-compiler"), cxxCompiler: (0,core.getInput)("cxx-compiler"), @@ -27727,11 +27727,7 @@ function getInputs() { async function main() { const inputs = getInputs(); - const configureArgs = [ - inputs.sourceDir || ".", - "-B", - inputs.buildDir || "build", - ]; + const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; if (inputs.generator) { configureArgs.push(...["-G", inputs.generator]); } @@ -27763,18 +27759,14 @@ async function main() { configureArgs.push(...inputs.options.map((opt) => "-D" + opt)); configureArgs.push(...inputs.args); await (0,exec.exec)("cmake", configureArgs); - core.setOutput("build-dir", inputs.buildDir || "build"); + core.setOutput("build-dir", inputs.buildDir); if (inputs.runBuild || inputs.runTest) { - await (0,exec.exec)("cmake", [ - "--build", - inputs.buildDir || "build", - ...inputs.buildArgs, - ]); + await (0,exec.exec)("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]); } if (inputs.runTest) { await (0,exec.exec)("ctest", [ "--test-dir", - inputs.buildDir || "build", + inputs.buildDir, "--output-on-failure", "--no-tests=error", ...inputs.testArgs, diff --git a/src/index.ts b/src/index.ts index a1b7d52..e9866d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,11 +6,7 @@ import { getInputs } from "./inputs.js"; async function main() { const inputs = getInputs(); - const configureArgs = [ - inputs.sourceDir || ".", - "-B", - inputs.buildDir || "build", - ]; + const configureArgs = [inputs.sourceDir, "-B", inputs.buildDir]; if (inputs.generator) { configureArgs.push(...["-G", inputs.generator]); @@ -50,20 +46,16 @@ async function main() { configureArgs.push(...inputs.args); await exec("cmake", configureArgs); - core.setOutput("build-dir", inputs.buildDir || "build"); + core.setOutput("build-dir", inputs.buildDir); if (inputs.runBuild || inputs.runTest) { - await exec("cmake", [ - "--build", - inputs.buildDir || "build", - ...inputs.buildArgs, - ]); + await exec("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]); } if (inputs.runTest) { await exec("ctest", [ "--test-dir", - inputs.buildDir || "build", + inputs.buildDir, "--output-on-failure", "--no-tests=error", ...inputs.testArgs, diff --git a/src/inputs.ts b/src/inputs.ts index d0815a1..ab54ed9 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -18,8 +18,8 @@ export interface Inputs { export function getInputs(): Inputs { return { - sourceDir: getInput("source-dir"), - buildDir: getInput("build-dir"), + sourceDir: getInput("source-dir") || ".", + buildDir: getInput("build-dir") || "build", generator: getInput("generator"), cCompiler: getInput("c-compiler"), cxxCompiler: getInput("cxx-compiler"),