From 91f078fe35535a920230420bb9fbaf9626a3ebc4 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 7 Aug 2020 22:16:54 +0100 Subject: workaround incorrect workflow status (#4044) --- test/ufuzz/actions.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/ufuzz/actions.js (limited to 'test/ufuzz/actions.js') diff --git a/test/ufuzz/actions.js b/test/ufuzz/actions.js new file mode 100644 index 00000000..c4438d8d --- /dev/null +++ b/test/ufuzz/actions.js @@ -0,0 +1,50 @@ +require("../../tools/exit"); + +var get = require("https").get; +var parse = require("url").parse; +var base = process.argv[2]; +var token = process.argv[3]; + +function read(url, callback) { + var options = parse(url); + options.headers = { + "Authorization": "Token " + token, + "User-Agent": "UglifyJS", + }; + get(options, function(response) { + var chunks = []; + response.setEncoding("utf8"); + response.on("data", function(chunk) { + chunks.push(chunk); + }).on("end", function() { + callback(JSON.parse(chunks.join(""))); + }); + }); +} + +var in_progress = 0, queued = 0; +process.on("beforeExit", function() { + if (queued > 3) { + process.stdout.write("0"); + } else { + process.stdout.write(Math.min(1000 * 20 / in_progress, 1500).toFixed(0)); + } +}); +read(base + "/actions/workflows/ufuzz.yml/runs", function(reply) { + reply.workflow_runs.filter(function(workflow) { + return /^(in_progress|queued|)$/.test(workflow.status); + }).forEach(function(workflow) { + read(workflow.jobs_url, function(reply) { + reply.jobs.forEach(function(job) { + switch (job.status) { + case "in_progress": + in_progress++; + break; + case "queued": + queued++; + break; + } + }); + }); + }); +}); -- cgit v1.2.3