workaround quirks from GitHub Actions (#5630)

This commit is contained in:
Alex Lam S.L
2022-08-25 19:35:53 +01:00
committed by GitHub
parent 9cdc1ef6c2
commit 41a7000745
2 changed files with 21 additions and 10 deletions

View File

@@ -9,8 +9,7 @@ exports.init = function(url, auth, num) {
};
exports.should_stop = function(callback) {
read(base + "/actions/runs?per_page=100", function(reply) {
if (!reply || !Array.isArray(reply.workflow_runs)) return;
var runs = reply.workflow_runs.sort(function(a, b) {
var runs = verify(reply, "workflow_runs").sort(function(a, b) {
return b.run_number - a.run_number;
});
var found = false, remaining = 20;
@@ -22,8 +21,7 @@ exports.should_stop = function(callback) {
if (is_cron(workflow) && workflow.run_number == run_number) found = true;
} while (!found && workflow.status == "completed");
read(workflow.jobs_url, function(reply) {
if (!reply || !Array.isArray(reply.jobs)) return;
if (!reply.jobs.every(function(job) {
if (!verify(reply, "jobs").every(function(job) {
if (job.status == "completed") return true;
remaining--;
return found || !is_cron(workflow);
@@ -70,3 +68,12 @@ function read(url, callback) {
done();
});
}
function verify(reply, field) {
if (!reply) return [];
var values = reply[field];
if (!Array.isArray(values)) return [];
return values.filter(function(value) {
return value;
});
}

View File

@@ -20,13 +20,9 @@ switch (process.argv.length) {
var tasks = [ run(), run() ];
if (iterations) return;
var alive = setInterval(function() {
actions.should_stop(function() {
clearInterval(alive);
tasks.forEach(function(kill) {
kill();
});
});
actions.should_stop(stop);
}, 8 * 60 * 1000);
var deadline = setTimeout(stop, (5 * 60 + 55) * 60 * 1000);
function run() {
var child, stdout, stderr, log;
@@ -76,3 +72,11 @@ function run() {
}
}
}
function stop() {
clearInterval(alive);
clearInterval(deadline);
tasks.forEach(function(kill) {
kill();
});
}