Skip to content

Commit 7279543

Browse files
committed
Handle SIGInt
Signed-off-by: Daniel González Lopes <[email protected]>
1 parent a5a9178 commit 7279543

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

dist/index.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -29899,6 +29899,7 @@ const core = __importStar(__nccwpck_require__(2186));
2989929899
const glob = __importStar(__nccwpck_require__(8090));
2990029900
const fs = __importStar(__nccwpck_require__(5630));
2990129901
const child_process_1 = __nccwpck_require__(2081);
29902+
var PIDs = [];
2990229903
run();
2990329904
/**
2990429905
* The main function for the action.
@@ -29923,6 +29924,7 @@ async function run() {
2992329924
commands.forEach(command => {
2992429925
const child = runCommand(command);
2992529926
childProcesses.push(child);
29927+
PIDs.push(child.pid);
2992629928
exitPromises.push(new Promise(resolve => {
2992729929
child.on('exit', (code, signal) => {
2992829930
if (code !== 0) {
@@ -29952,6 +29954,7 @@ async function run() {
2995229954
else {
2995329955
for (const command of commands) {
2995429956
const child = runCommand(command);
29957+
PIDs.push(child.pid);
2995529958
await new Promise(resolve => {
2995629959
child.on('exit', (code, signal) => {
2995729960
if (code !== 0) {
@@ -30009,11 +30012,15 @@ async function run() {
3000930012
}
3001030013
exports.run = run;
3001130014
process.on('SIGINT', () => {
30012-
console.log('🚨 Caught SIGINT. Exiting...');
30013-
process.exit(1);
30014-
});
30015-
process.on('SIGTERM', () => {
30016-
console.log('🚨 Caught SIGTERM. Exiting...');
30015+
console.log('🚨 Caught SIGINT. Stoping all tests');
30016+
PIDs.forEach(pid => {
30017+
try {
30018+
process.kill(pid, 'SIGINT');
30019+
}
30020+
catch (error) {
30021+
console.error(`Failed to kill process with PID ${pid}`);
30022+
}
30023+
});
3001730024
process.exit(1);
3001830025
});
3001930026
async function isCloudIntegrationEnabled() {

src/index.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as glob from '@actions/glob'
33
import * as fs from 'fs-extra'
44
import { spawn } from 'child_process'
55

6+
var PIDs: number[] = [];
7+
68
run()
79

810
/**
@@ -32,6 +34,7 @@ export async function run(): Promise<void> {
3234
commands.forEach(command => {
3335
const child = runCommand(command);
3436
childProcesses.push(child);
37+
PIDs.push(child.pid);
3538
exitPromises.push(new Promise(resolve => {
3639
child.on('exit', (code: number, signal: string) => {
3740
if (code !== 0) {
@@ -59,6 +62,7 @@ export async function run(): Promise<void> {
5962
} else {
6063
for (const command of commands) {
6164
const child = runCommand(command);
65+
PIDs.push(child.pid);
6266
await new Promise<void>(resolve => {
6367
child.on('exit', (code: number, signal: string) => {
6468
if (code !== 0) {
@@ -116,15 +120,17 @@ export async function run(): Promise<void> {
116120
}
117121

118122
process.on('SIGINT', () => {
119-
console.log('🚨 Caught SIGINT. Exiting...');
123+
console.log('🚨 Caught SIGINT. Stoping all tests')
124+
PIDs.forEach(pid => {
125+
try {
126+
process.kill(pid, 'SIGINT');
127+
} catch (error) {
128+
console.error(`Failed to kill process with PID ${pid}`);
129+
}
130+
});
120131
process.exit(1);
121132
});
122133

123-
process.on('SIGTERM', () => {
124-
console.log('🚨 Caught SIGTERM. Exiting...');
125-
process.exit(1);
126-
})
127-
128134
async function isCloudIntegrationEnabled(): Promise<boolean> {
129135
if (process.env.K6_CLOUD_TOKEN === undefined || process.env.K6_CLOUD_TOKEN === '') {
130136
return false

0 commit comments

Comments
 (0)