Build binary (#18933)

Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
This commit is contained in:
Aswin Ashok
2026-03-03 06:32:19 +05:30
committed by GitHub
parent 46231a1755
commit 0d69f9f7fa
16 changed files with 1881 additions and 30 deletions
+28 -4
View File
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { spawn } from 'node:child_process';
import { spawn, execSync } from 'node:child_process';
import type {
HookConfig,
CommandHookConfig,
@@ -331,12 +331,17 @@ export class HookRunner {
let timedOut = false;
const shellConfig = getShellConfiguration();
const command = this.expandCommand(
let command = this.expandCommand(
hookConfig.command,
input,
shellConfig.shell,
);
if (shellConfig.shell === 'powershell') {
// Append exit code check to ensure the exit code of the command is propagated
command = `${command}; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }`;
}
// Set up environment variables
const env = {
...sanitizeEnvironment(process.env, this.config.sanitizationConfig),
@@ -359,12 +364,31 @@ export class HookRunner {
// Set up timeout
const timeoutHandle = setTimeout(() => {
timedOut = true;
child.kill('SIGTERM');
if (process.platform === 'win32' && child.pid) {
try {
execSync(`taskkill /pid ${child.pid} /f /t`, { timeout: 2000 });
} catch (_e) {
// Ignore errors if process is already dead or access denied
debugLogger.debug(`Taskkill failed: ${_e}`);
}
} else {
child.kill('SIGTERM');
}
// Force kill after 5 seconds
setTimeout(() => {
if (!child.killed) {
child.kill('SIGKILL');
if (process.platform === 'win32' && child.pid) {
try {
execSync(`taskkill /pid ${child.pid} /f /t`, { timeout: 2000 });
} catch (_e) {
// Ignore
debugLogger.debug(`Taskkill failed: ${_e}`);
}
} else {
child.kill('SIGKILL');
}
}
}, 5000);
}, timeout);