Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 11 additions & 134 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1851,132 +1851,6 @@ module.exports = {
};


/***/ }),

/***/ 9335:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

"use strict";


var childProcess = __nccwpck_require__(2081);
var spawn = childProcess.spawn;
var exec = childProcess.exec;

module.exports = function (pid, signal, callback) {
if (typeof signal === 'function' && callback === undefined) {
callback = signal;
signal = undefined;
}

pid = parseInt(pid);
if (Number.isNaN(pid)) {
if (callback) {
return callback(new Error("pid must be a number"));
} else {
throw new Error("pid must be a number");
}
}

var tree = {};
var pidsToProcess = {};
tree[pid] = [];
pidsToProcess[pid] = 1;

switch (process.platform) {
case 'win32':
exec('taskkill /pid ' + pid + ' /T /F', callback);
break;
case 'darwin':
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
return spawn('pgrep', ['-P', parentPid]);
}, function () {
killAll(tree, signal, callback);
});
break;
// case 'sunos':
// buildProcessTreeSunOS(pid, tree, pidsToProcess, function () {
// killAll(tree, signal, callback);
// });
// break;
default: // Linux
buildProcessTree(pid, tree, pidsToProcess, function (parentPid) {
return spawn('ps', ['-o', 'pid', '--no-headers', '--ppid', parentPid]);
}, function () {
killAll(tree, signal, callback);
});
break;
}
};

function killAll (tree, signal, callback) {
var killed = {};
try {
Object.keys(tree).forEach(function (pid) {
tree[pid].forEach(function (pidpid) {
if (!killed[pidpid]) {
killPid(pidpid, signal);
killed[pidpid] = 1;
}
});
if (!killed[pid]) {
killPid(pid, signal);
killed[pid] = 1;
}
});
} catch (err) {
if (callback) {
return callback(err);
} else {
throw err;
}
}
if (callback) {
return callback();
}
}

function killPid(pid, signal) {
try {
process.kill(parseInt(pid, 10), signal);
}
catch (err) {
if (err.code !== 'ESRCH') throw err;
}
}

function buildProcessTree (parentPid, tree, pidsToProcess, spawnChildProcessesList, cb) {
var ps = spawnChildProcessesList(parentPid);
var allData = '';
ps.stdout.on('data', function (data) {
var data = data.toString('ascii');
allData += data;
});

var onClose = function (code) {
delete pidsToProcess[parentPid];

if (code != 0) {
// no more parent processes
if (Object.keys(pidsToProcess).length == 0) {
cb();
}
return;
}

allData.match(/\d+/g).forEach(function (pid) {
pid = parseInt(pid, 10);
tree[parentPid].push(pid);
tree[pid] = [];
pidsToProcess[pid] = 1;
buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb);
});
};

ps.on('close', onClose);
}


/***/ }),

/***/ 4294:
Expand Down Expand Up @@ -24895,7 +24769,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
var core_1 = __nccwpck_require__(2186);
var child_process_1 = __nccwpck_require__(2081);
var milliseconds_1 = __importDefault(__nccwpck_require__(2318));
var tree_kill_1 = __importDefault(__nccwpck_require__(9335));
var inputs_1 = __nccwpck_require__(7063);
var util_1 = __nccwpck_require__(2629);
var OS = process.platform;
Expand Down Expand Up @@ -25011,20 +24884,24 @@ function runCmd(attempt, inputs) {
if (Date.now() < end_time && !done) return [3 /*break*/, 1];
_c.label = 4;
case 4:
if (!(!done && child.pid)) return [3 /*break*/, 6];
if (!(!done && child.pid)) return [3 /*break*/, 7];
timeout = true;
(0, tree_kill_1.default)(child.pid);
return [4 /*yield*/, (0, util_1.retryWait)(milliseconds_1.default.seconds(inputs.retry_wait_seconds))];
// Note: this assumes a unix environment
return [4 /*yield*/, (0, child_process_1.execSync)("sudo kill -9 -- ".concat(child.pid), { stdio: 'inherit' })];
case 5:
// Note: this assumes a unix environment
_c.sent();
throw new Error("Timeout of ".concat((0, inputs_1.getTimeout)(inputs), "ms hit"));
case 6:
if (!(exit > 0)) return [3 /*break*/, 8];
return [4 /*yield*/, (0, util_1.retryWait)(milliseconds_1.default.seconds(inputs.retry_wait_seconds))];
case 6:
_c.sent();
throw new Error("Timeout of ".concat((0, inputs_1.getTimeout)(inputs), "ms hit"));
case 7:
if (!(exit > 0)) return [3 /*break*/, 9];
return [4 /*yield*/, (0, util_1.retryWait)(milliseconds_1.default.seconds(inputs.retry_wait_seconds))];
case 8:
_c.sent();
throw new Error("Child_process exited with error code ".concat(exit));
case 8: return [2 /*return*/];
case 9: return [2 /*return*/];
}
});
});
Expand Down
11 changes: 1 addition & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"homepage": "https://github.com/nick-fields/retry#readme",
"dependencies": {
"@actions/core": "^1.10.0",
"milliseconds": "^1.0.3",
"tree-kill": "^1.2.2"
"milliseconds": "^1.0.3"
},
"devDependencies": {
"@commitlint/cli": "^16.2.3",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { error, warning, info, debug, setOutput } from '@actions/core';
import { execSync, spawn } from 'child_process';
import ms from 'milliseconds';
import kill from 'tree-kill';

import { getInputs, getTimeout, Inputs, validateInputs } from './inputs';
import { retryWait, wait } from './util';
Expand Down Expand Up @@ -115,7 +114,8 @@ async function runCmd(attempt: number, inputs: Inputs) {

if (!done && child.pid) {
timeout = true;
kill(child.pid);
// Note: this assumes a unix environment
await execSync(`sudo kill -9 -- ${child.pid}`, { stdio: 'inherit' });
await retryWait(ms.seconds(inputs.retry_wait_seconds));
throw new Error(`Timeout of ${getTimeout(inputs)}ms hit`);
} else if (exit > 0) {
Expand Down