diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-08-07 22:16:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-08 05:16:54 +0800 |
commit | 91f078fe35535a920230420bb9fbaf9626a3ebc4 (patch) | |
tree | 1db8767e2c5575df52ec60a4fe1d8e71e339fc15 | |
parent | a546cb881d70546e743d77933d6d73f9c39493da (diff) | |
download | tracifyjs-91f078fe35535a920230420bb9fbaf9626a3ebc4.tar.gz tracifyjs-91f078fe35535a920230420bb9fbaf9626a3ebc4.zip |
workaround incorrect workflow status (#4044)
-rw-r--r-- | .github/workflows/ufuzz.yml | 22 | ||||
-rw-r--r-- | test/ufuzz/actions.js | 50 |
2 files changed, 61 insertions, 11 deletions
diff --git a/.github/workflows/ufuzz.yml b/.github/workflows/ufuzz.yml index fa95c7ab..4dd9de2e 100644 --- a/.github/workflows/ufuzz.yml +++ b/.github/workflows/ufuzz.yml @@ -4,8 +4,9 @@ on: schedule: - cron: "*/5 * * * *" env: + BASE_URL: https://api.github.com/repos/${{ github.repository }} CAUSE: ${{ github.event_name }} - DATA_URL: https://api.github.com/repos/${{ github.repository }}/actions/workflows/ufuzz.yml/runs?status= + TOKEN: ${{ github.token }} jobs: ufuzz: strategy: @@ -19,15 +20,6 @@ jobs: - name: Perform fuzzing shell: bash run: | - if [[ $CAUSE != "schedule" ]]; then - PERIOD=1800000 - elif (( `curl -s ${DATA_URL}queued | tr -d '\040\011\012\015' | awk -F"queued" '{print NF-1}'` > 3 )); then - echo "too many jobs in queue - exiting..." - exit - else - RUNNING=`curl -s ${DATA_URL}in_progress | tr -d '\040\011\012\015' | awk -F"in_progress" '{print NF-1}'` - PERIOD=$(( 3600000 * 10 / (RUNNING > 5 ? RUNNING : 5) )) - fi git clone --branch v1.5.4 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add 8 && nvs use 8'; do cd ~/.nvs @@ -44,4 +36,12 @@ jobs: npm config set update-notifier false npm --version while !(npm install); do echo "'npm install' failed - retrying..."; done - node test/ufuzz/job $PERIOD + PERIOD=1800000 + if [[ $CAUSE == "schedule" ]]; then + PERIOD=$(( 3600 * `node test/ufuzz/actions $BASE_URL $TOKEN` )) + fi + if (( $PERIOD == 0 )); then + echo "too many jobs in queue - exiting..." + else + node test/ufuzz/job $PERIOD + fi 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; + } + }); + }); + }); +}); |