mirror of
				https://github.com/threeal/cmake-action.git
				synced 2025-11-04 13:53:41 +00:00 
			
		
		
		
	feat: utilize GitHub Actions Utilities package
This commit is contained in:
		
							parent
							
								
									d1c539d005
								
							
						
					
					
						commit
						d7b762efbe
					
				
							
								
								
									
										44
									
								
								dist/index.mjs
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										44
									
								
								dist/index.mjs
									
									
									
										generated
									
									
										vendored
									
									
								
							@ -3,7 +3,34 @@ import os from 'node:os';
 | 
				
			|||||||
import { execFileSync } from 'node:child_process';
 | 
					import { execFileSync } from 'node:child_process';
 | 
				
			||||||
import path from 'node:path';
 | 
					import path from 'node:path';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function r(r){return function(r){if("object"==typeof(e=r)&&null!==e&&"message"in e&&"string"==typeof e.message)return r;var e;try{return new Error(JSON.stringify(r))}catch(e){return new Error(String(r))}}(r).message}
 | 
					/**
 | 
				
			||||||
 | 
					 * Retrieves the value of a GitHub Actions input.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param name - The name of the GitHub Actions input.
 | 
				
			||||||
 | 
					 * @returns The value of the GitHub Actions input, or an empty string if not found.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function getInput(name) {
 | 
				
			||||||
 | 
					    const value = process.env[`INPUT_${name.toUpperCase()}`] || "";
 | 
				
			||||||
 | 
					    return value.trim();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Sets the value of a GitHub Actions output.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param name - The name of the GitHub Actions output.
 | 
				
			||||||
 | 
					 * @param value - The value of the GitHub Actions output
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function setOutput(name, value) {
 | 
				
			||||||
 | 
					    fs.appendFileSync(process.env["GITHUB_OUTPUT"], `${name}=${value}${os.EOL}`);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Logs an error message on GitHub Actions.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param err - The error, which can be of any type.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function error(err) {
 | 
				
			||||||
 | 
					    const message = err instanceof Error ? err.message : String(err);
 | 
				
			||||||
 | 
					    process.stdout.write(`::error::${message}${os.EOL}`);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Configures the build system of a CMake project.
 | 
					 * Configures the build system of a CMake project.
 | 
				
			||||||
@ -34,15 +61,6 @@ function buildProject(context) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Retrieves an action input.
 | 
					 | 
				
			||||||
 * @param key - The key of the action input.
 | 
					 | 
				
			||||||
 * @returns The action input value as a string.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function getInput(key) {
 | 
					 | 
				
			||||||
    const value = process.env[`INPUT_${key.toUpperCase()}`] || "";
 | 
					 | 
				
			||||||
    return value.trim();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
function getContext() {
 | 
					function getContext() {
 | 
				
			||||||
    const sourceDir = getInput("source-dir");
 | 
					    const sourceDir = getInput("source-dir");
 | 
				
			||||||
    const options = [];
 | 
					    const options = [];
 | 
				
			||||||
@ -91,12 +109,12 @@ function getContext() {
 | 
				
			|||||||
try {
 | 
					try {
 | 
				
			||||||
    const context = getContext();
 | 
					    const context = getContext();
 | 
				
			||||||
    configureProject(context);
 | 
					    configureProject(context);
 | 
				
			||||||
    fs.appendFileSync(process.env["GITHUB_OUTPUT"], `build-dir=${context.buildDir}${os.EOL}`);
 | 
					    setOutput("build-dir", context.buildDir);
 | 
				
			||||||
    if (context.build.enabled) {
 | 
					    if (context.build.enabled) {
 | 
				
			||||||
        buildProject(context);
 | 
					        buildProject(context);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
catch (err) {
 | 
					catch (err) {
 | 
				
			||||||
    process.exitCode = 1;
 | 
					    error(err);
 | 
				
			||||||
    process.stdout.write(`::error::${r(err)}${os.EOL}`);
 | 
					    process.exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@
 | 
				
			|||||||
    "test": "jest"
 | 
					    "test": "jest"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "catched-error-message": "^0.0.1"
 | 
					    "gha-utils": "^0.1.0"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@eslint/js": "^9.8.0",
 | 
					    "@eslint/js": "^9.8.0",
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import { getInput } from "gha-utils";
 | 
				
			||||||
import path from "node:path";
 | 
					import path from "node:path";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface Context {
 | 
					export interface Context {
 | 
				
			||||||
@ -14,16 +15,6 @@ export interface Context {
 | 
				
			|||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Retrieves an action input.
 | 
					 | 
				
			||||||
 * @param key - The key of the action input.
 | 
					 | 
				
			||||||
 * @returns The action input value as a string.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function getInput(key: string): string {
 | 
					 | 
				
			||||||
  const value = process.env[`INPUT_${key.toUpperCase()}`] || "";
 | 
					 | 
				
			||||||
  return value.trim();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export function getContext(): Context {
 | 
					export function getContext(): Context {
 | 
				
			||||||
  const sourceDir = getInput("source-dir");
 | 
					  const sourceDir = getInput("source-dir");
 | 
				
			||||||
  const options: string[] = [];
 | 
					  const options: string[] = [];
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/index.ts
									
									
									
									
									
								
							@ -1,6 +1,4 @@
 | 
				
			|||||||
import { getErrorMessage } from "catched-error-message";
 | 
					import { error, setOutput } from "gha-utils";
 | 
				
			||||||
import fs from "node:fs";
 | 
					 | 
				
			||||||
import os from "node:os";
 | 
					 | 
				
			||||||
import { buildProject, configureProject } from "./cmake.js";
 | 
					import { buildProject, configureProject } from "./cmake.js";
 | 
				
			||||||
import { getContext } from "./context.js";
 | 
					import { getContext } from "./context.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -9,15 +7,12 @@ try {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  configureProject(context);
 | 
					  configureProject(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fs.appendFileSync(
 | 
					  setOutput("build-dir", context.buildDir);
 | 
				
			||||||
    process.env["GITHUB_OUTPUT"] as string,
 | 
					 | 
				
			||||||
    `build-dir=${context.buildDir}${os.EOL}`,
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (context.build.enabled) {
 | 
					  if (context.build.enabled) {
 | 
				
			||||||
    buildProject(context);
 | 
					    buildProject(context);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
} catch (err) {
 | 
					} catch (err) {
 | 
				
			||||||
  process.exitCode = 1;
 | 
					  error(err);
 | 
				
			||||||
  process.stdout.write(`::error::${getErrorMessage(err)}${os.EOL}`);
 | 
					  process.exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								yarn.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										16
									
								
								yarn.lock
									
									
									
										generated
									
									
									
								
							@ -1670,13 +1670,6 @@ __metadata:
 | 
				
			|||||||
  languageName: node
 | 
					  languageName: node
 | 
				
			||||||
  linkType: hard
 | 
					  linkType: hard
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"catched-error-message@npm:^0.0.1":
 | 
					 | 
				
			||||||
  version: 0.0.1
 | 
					 | 
				
			||||||
  resolution: "catched-error-message@npm:0.0.1"
 | 
					 | 
				
			||||||
  checksum: 10c0/1f10cd4323a73bec7a57b7495730e5dad9995120b04e85b5f654f7b40dc6a36320d95cc55e49cdf78753158e18790ef725e2ec7309ebced3acd6c9a557ac075b
 | 
					 | 
				
			||||||
  languageName: node
 | 
					 | 
				
			||||||
  linkType: hard
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
"chalk@npm:^2.4.2":
 | 
					"chalk@npm:^2.4.2":
 | 
				
			||||||
  version: 2.4.2
 | 
					  version: 2.4.2
 | 
				
			||||||
  resolution: "chalk@npm:2.4.2"
 | 
					  resolution: "chalk@npm:2.4.2"
 | 
				
			||||||
@ -2387,6 +2380,13 @@ __metadata:
 | 
				
			|||||||
  languageName: node
 | 
					  languageName: node
 | 
				
			||||||
  linkType: hard
 | 
					  linkType: hard
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"gha-utils@npm:^0.1.0":
 | 
				
			||||||
 | 
					  version: 0.1.0
 | 
				
			||||||
 | 
					  resolution: "gha-utils@npm:0.1.0"
 | 
				
			||||||
 | 
					  checksum: 10c0/8c1cc68e89434a8af8a64d71a2dae9a9248ce581b522718ba51f78b5447cad9c16b8d70097a885f797d547bbafdb7bc481d9d41ac1ce0b2db084d500ebfbc838
 | 
				
			||||||
 | 
					  languageName: node
 | 
				
			||||||
 | 
					  linkType: hard
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"glob-parent@npm:^5.1.2":
 | 
					"glob-parent@npm:^5.1.2":
 | 
				
			||||||
  version: 5.1.2
 | 
					  version: 5.1.2
 | 
				
			||||||
  resolution: "glob-parent@npm:5.1.2"
 | 
					  resolution: "glob-parent@npm:5.1.2"
 | 
				
			||||||
@ -4132,8 +4132,8 @@ __metadata:
 | 
				
			|||||||
    "@rollup/plugin-typescript": "npm:^11.1.6"
 | 
					    "@rollup/plugin-typescript": "npm:^11.1.6"
 | 
				
			||||||
    "@types/jest": "npm:^29.5.12"
 | 
					    "@types/jest": "npm:^29.5.12"
 | 
				
			||||||
    "@types/node": "npm:^22.1.0"
 | 
					    "@types/node": "npm:^22.1.0"
 | 
				
			||||||
    catched-error-message: "npm:^0.0.1"
 | 
					 | 
				
			||||||
    eslint: "npm:^9.8.0"
 | 
					    eslint: "npm:^9.8.0"
 | 
				
			||||||
 | 
					    gha-utils: "npm:^0.1.0"
 | 
				
			||||||
    jest: "npm:^29.7.0"
 | 
					    jest: "npm:^29.7.0"
 | 
				
			||||||
    prettier: "npm:^3.3.3"
 | 
					    prettier: "npm:^3.3.3"
 | 
				
			||||||
    rollup: "npm:^4.20.0"
 | 
					    rollup: "npm:^4.20.0"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user