From 702cc56cdb9cfe49d182a5618bba036d37a8b97b Mon Sep 17 00:00:00 2001 From: Fin Christensen Date: Tue, 20 Aug 2019 15:24:50 +0200 Subject: [PATCH] Add jq script for CI --- scripts/shields-from-tests.jq | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/shields-from-tests.jq diff --git a/scripts/shields-from-tests.jq b/scripts/shields-from-tests.jq new file mode 100644 index 0000000..ca7a3e9 --- /dev/null +++ b/scripts/shields-from-tests.jq @@ -0,0 +1,27 @@ +{ + # filter for "passed" and "test_count" in input objects with `"type": "suite"` + # and accumulate stats from all tests + "passed": map(select(.type == "suite" and has("passed")) | .passed) | add, + "total": map(select(.type == "suite" and has("test_count")) | .test_count) | add +} | . + { + # calculate ratio of passed tests + "factor": (.passed / .total) +} | { + # calculate color from test factor + "color": ( + if .factor < 0.33 then + "red" + elif .factor < 0.66 then + "orange" + elif .factor < 1.0 then + "yellow" + else + "brightgreen" + end + ), + "isError": true, + "label": "cargo test", + # interpolate the shield label + "message": "\(.passed) / \(.total) tests", + "schemaVersion": 1 +}