mirror of
				https://github.com/threeal/cmake-action.git
				synced 2025-11-04 05:43:42 +00:00 
			
		
		
		
	feat: use execFileSync from node:child_process package
				
					
				
			This commit is contained in:
		
							parent
							
								
									f0425ca4df
								
							
						
					
					
						commit
						ca58db1467
					
				
							
								
								
									
										1265
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										1265
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -9,8 +9,7 @@
 | 
			
		||||
    "test": "jest"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@actions/core": "^1.10.1",
 | 
			
		||||
    "@actions/exec": "^1.1.1"
 | 
			
		||||
    "@actions/core": "^1.10.1"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@eslint/js": "^9.8.0",
 | 
			
		||||
 | 
			
		||||
@ -21,8 +21,8 @@ const defaultInputs: Inputs = {
 | 
			
		||||
  buildArgs: [],
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
jest.unstable_mockModule("@actions/exec", () => ({
 | 
			
		||||
  exec: jest.fn(),
 | 
			
		||||
jest.unstable_mockModule("node:child_process", () => ({
 | 
			
		||||
  execFileSync: jest.fn(),
 | 
			
		||||
}));
 | 
			
		||||
 | 
			
		||||
describe("configure a CMake project", () => {
 | 
			
		||||
@ -115,15 +115,18 @@ describe("configure a CMake project", () => {
 | 
			
		||||
  for (const testCase of testCases) {
 | 
			
		||||
    it(`should execute the correct command ${testCase.name}`, async () => {
 | 
			
		||||
      const { configureProject } = await import("./cmake.js");
 | 
			
		||||
      const { exec } = await import("@actions/exec");
 | 
			
		||||
      const { execFileSync } = await import("node:child_process");
 | 
			
		||||
 | 
			
		||||
      jest.mocked(exec).mockReset();
 | 
			
		||||
      jest.mocked(execFileSync).mockReset();
 | 
			
		||||
 | 
			
		||||
      const prom = configureProject({ ...defaultInputs, ...testCase.inputs });
 | 
			
		||||
      await expect(prom).resolves.toBeUndefined();
 | 
			
		||||
 | 
			
		||||
      expect(exec).toHaveBeenCalledTimes(1);
 | 
			
		||||
      expect(exec).toHaveBeenLastCalledWith("cmake", testCase.expectedArgs);
 | 
			
		||||
      expect(execFileSync).toHaveBeenCalledTimes(1);
 | 
			
		||||
      expect(execFileSync).toHaveBeenLastCalledWith(
 | 
			
		||||
        "cmake",
 | 
			
		||||
        testCase.expectedArgs,
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
@ -157,15 +160,18 @@ describe("build a CMake project", () => {
 | 
			
		||||
  for (const testCase of testCases) {
 | 
			
		||||
    it(`should execute the correct command ${testCase.name}`, async () => {
 | 
			
		||||
      const { buildProject } = await import("./cmake.js");
 | 
			
		||||
      const { exec } = await import("@actions/exec");
 | 
			
		||||
      const { execFileSync } = await import("node:child_process");
 | 
			
		||||
 | 
			
		||||
      jest.mocked(exec).mockReset();
 | 
			
		||||
      jest.mocked(execFileSync).mockReset();
 | 
			
		||||
 | 
			
		||||
      const prom = buildProject({ ...defaultInputs, ...testCase.inputs });
 | 
			
		||||
      await expect(prom).resolves.toBeUndefined();
 | 
			
		||||
 | 
			
		||||
      expect(exec).toHaveBeenCalledTimes(1);
 | 
			
		||||
      expect(exec).toHaveBeenLastCalledWith("cmake", testCase.expectedArgs);
 | 
			
		||||
      expect(execFileSync).toHaveBeenCalledTimes(1);
 | 
			
		||||
      expect(execFileSync).toHaveBeenLastCalledWith(
 | 
			
		||||
        "cmake",
 | 
			
		||||
        testCase.expectedArgs,
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
import { exec } from "@actions/exec";
 | 
			
		||||
import { execFileSync } from "node:child_process";
 | 
			
		||||
import type { Inputs } from "./inputs.js";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -38,7 +38,7 @@ export async function configureProject(inputs: Inputs): Promise<void> {
 | 
			
		||||
  configureArgs.push(...inputs.options.map((opt) => "-D" + opt));
 | 
			
		||||
  configureArgs.push(...inputs.args);
 | 
			
		||||
 | 
			
		||||
  await exec("cmake", configureArgs);
 | 
			
		||||
  execFileSync("cmake", configureArgs);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -47,5 +47,5 @@ export async function configureProject(inputs: Inputs): Promise<void> {
 | 
			
		||||
 * @param inputs - The action inputs.
 | 
			
		||||
 */
 | 
			
		||||
export async function buildProject(inputs: Inputs): Promise<void> {
 | 
			
		||||
  await exec("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
 | 
			
		||||
  execFileSync("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								yarn.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										17
									
								
								yarn.lock
									
									
									
										generated
									
									
									
								
							@ -22,15 +22,6 @@ __metadata:
 | 
			
		||||
  languageName: node
 | 
			
		||||
  linkType: hard
 | 
			
		||||
 | 
			
		||||
"@actions/exec@npm:^1.1.1":
 | 
			
		||||
  version: 1.1.1
 | 
			
		||||
  resolution: "@actions/exec@npm:1.1.1"
 | 
			
		||||
  dependencies:
 | 
			
		||||
    "@actions/io": "npm:^1.0.1"
 | 
			
		||||
  checksum: 10c0/4a09f6bdbe50ce68b5cf8a7254d176230d6a74bccf6ecc3857feee209a8c950ba9adec87cc5ecceb04110182d1c17117234e45557d72fde6229b7fd3a395322a
 | 
			
		||||
  languageName: node
 | 
			
		||||
  linkType: hard
 | 
			
		||||
 | 
			
		||||
"@actions/http-client@npm:^2.0.1":
 | 
			
		||||
  version: 2.2.0
 | 
			
		||||
  resolution: "@actions/http-client@npm:2.2.0"
 | 
			
		||||
@ -41,13 +32,6 @@ __metadata:
 | 
			
		||||
  languageName: node
 | 
			
		||||
  linkType: hard
 | 
			
		||||
 | 
			
		||||
"@actions/io@npm:^1.0.1":
 | 
			
		||||
  version: 1.1.3
 | 
			
		||||
  resolution: "@actions/io@npm:1.1.3"
 | 
			
		||||
  checksum: 10c0/5b8751918e5bf0bebd923ba917fb1c0e294401e7ff0037f32c92a4efa4215550df1f6633c63fd4efb2bdaae8711e69b9e36925857db1f38935ff62a5c92ec29e
 | 
			
		||||
  languageName: node
 | 
			
		||||
  linkType: hard
 | 
			
		||||
 | 
			
		||||
"@ampproject/remapping@npm:^2.2.0":
 | 
			
		||||
  version: 2.3.0
 | 
			
		||||
  resolution: "@ampproject/remapping@npm:2.3.0"
 | 
			
		||||
@ -3901,7 +3885,6 @@ __metadata:
 | 
			
		||||
  resolution: "root@workspace:."
 | 
			
		||||
  dependencies:
 | 
			
		||||
    "@actions/core": "npm:^1.10.1"
 | 
			
		||||
    "@actions/exec": "npm:^1.1.1"
 | 
			
		||||
    "@eslint/js": "npm:^9.8.0"
 | 
			
		||||
    "@jest/globals": "npm:^29.7.0"
 | 
			
		||||
    "@types/jest": "npm:^29.5.12"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user