mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-09 18:51:21 +00:00
refactor: add buildProject
function from lines in main
function
This commit is contained in:
parent
d5238b21ac
commit
81c5bdcff9
11
dist/index.js
generated
vendored
11
dist/index.js
generated
vendored
@ -27726,6 +27726,14 @@ async function configureProject(inputs) {
|
||||
configureArgs.push(...inputs.args);
|
||||
await (0,exec.exec)("cmake", configureArgs);
|
||||
}
|
||||
/**
|
||||
* Build a CMake project.
|
||||
*
|
||||
* @param inputs - The action inputs.
|
||||
*/
|
||||
async function buildProject(inputs) {
|
||||
await (0,exec.exec)("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/inputs.ts
|
||||
|
||||
@ -27749,13 +27757,12 @@ function getInputs() {
|
||||
|
||||
|
||||
|
||||
|
||||
async function main() {
|
||||
const inputs = getInputs();
|
||||
await configureProject(inputs);
|
||||
core.setOutput("build-dir", inputs.buildDir);
|
||||
if (inputs.runBuild) {
|
||||
await (0,exec.exec)("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
|
||||
await buildProject(inputs);
|
||||
}
|
||||
}
|
||||
main().catch((err) => core.setFailed(err));
|
||||
|
@ -1,31 +1,31 @@
|
||||
import { jest } from "@jest/globals";
|
||||
import type { Inputs } from "./inputs.js";
|
||||
|
||||
interface TestCase {
|
||||
name: string;
|
||||
inputs: Inputs;
|
||||
expectedArgs: string[];
|
||||
}
|
||||
|
||||
const defaultInputs: Inputs = {
|
||||
sourceDir: ".",
|
||||
buildDir: "build",
|
||||
generator: "",
|
||||
cCompiler: "",
|
||||
cxxCompiler: "",
|
||||
cFlags: "",
|
||||
cxxFlags: "",
|
||||
options: [],
|
||||
args: [],
|
||||
runBuild: true,
|
||||
buildArgs: [],
|
||||
};
|
||||
|
||||
jest.unstable_mockModule("@actions/exec", () => ({
|
||||
exec: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("configure a CMake project", () => {
|
||||
const defaultInputs: Inputs = {
|
||||
sourceDir: ".",
|
||||
buildDir: "build",
|
||||
generator: "",
|
||||
cCompiler: "",
|
||||
cxxCompiler: "",
|
||||
cFlags: "",
|
||||
cxxFlags: "",
|
||||
options: [],
|
||||
args: [],
|
||||
runBuild: true,
|
||||
buildArgs: [],
|
||||
};
|
||||
|
||||
interface TestCase {
|
||||
name: string;
|
||||
inputs: Inputs;
|
||||
expectedArgs: string[];
|
||||
}
|
||||
|
||||
const testCases: TestCase[] = [
|
||||
{
|
||||
name: "with nothing specified",
|
||||
@ -161,3 +161,52 @@ describe("configure a CMake project", () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("build a CMake project", () => {
|
||||
const testCases: TestCase[] = [
|
||||
{
|
||||
name: "with nothing specified",
|
||||
inputs: defaultInputs,
|
||||
expectedArgs: ["--build", "build"],
|
||||
},
|
||||
{
|
||||
name: "with build directory specified",
|
||||
inputs: {
|
||||
...defaultInputs,
|
||||
buildDir: "output",
|
||||
},
|
||||
expectedArgs: ["--build", "output"],
|
||||
},
|
||||
{
|
||||
name: "with additional arguments specified",
|
||||
inputs: {
|
||||
...defaultInputs,
|
||||
buildArgs: ["--target", "foo"],
|
||||
},
|
||||
expectedArgs: ["--build", "build", "--target", "foo"],
|
||||
},
|
||||
{
|
||||
name: "with all specified",
|
||||
inputs: {
|
||||
...defaultInputs,
|
||||
buildDir: "output",
|
||||
buildArgs: ["--target", "foo"],
|
||||
},
|
||||
expectedArgs: ["--build", "output", "--target", "foo"],
|
||||
},
|
||||
];
|
||||
|
||||
for (const { name, inputs, expectedArgs } of testCases) {
|
||||
it(`should execute the correct command ${name}`, async () => {
|
||||
const { buildProject } = await import("./cmake.js");
|
||||
const { exec } = await import("@actions/exec");
|
||||
|
||||
jest.mocked(exec).mockReset();
|
||||
|
||||
await expect(buildProject(inputs)).resolves.toBeUndefined();
|
||||
|
||||
expect(exec).toHaveBeenCalledTimes(1);
|
||||
expect(exec).toHaveBeenLastCalledWith("cmake", expectedArgs);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -34,3 +34,12 @@ export async function configureProject(inputs: Inputs): Promise<void> {
|
||||
|
||||
await exec("cmake", configureArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a CMake project.
|
||||
*
|
||||
* @param inputs - The action inputs.
|
||||
*/
|
||||
export async function buildProject(inputs: Inputs): Promise<void> {
|
||||
await exec("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import * as core from "@actions/core";
|
||||
import { exec } from "@actions/exec";
|
||||
import { configureProject } from "./cmake.js";
|
||||
import { buildProject, configureProject } from "./cmake.js";
|
||||
import { getInputs } from "./inputs.js";
|
||||
|
||||
async function main() {
|
||||
@ -11,7 +10,7 @@ async function main() {
|
||||
core.setOutput("build-dir", inputs.buildDir);
|
||||
|
||||
if (inputs.runBuild) {
|
||||
await exec("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
|
||||
await buildProject(inputs);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user