Last active
March 1, 2024 10:59
-
-
Save r2r-dev/ea8edfe27f9ab1d736edeb76c13d25f4 to your computer and use it in GitHub Desktop.
process_build_events.jq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S jq -n -f | |
# curl --netrc 'https://bes.service/rpc/BuildBuddyService/SearchInvocation' -d '{"query": {"commit_sha": "000d8878ada519b9bc8ae453736c1931"}}' -H 'Content-Type: application/json' -H 'x-buildbuddy-api-key: 00000000000' | |
# curl --netrc 'https://bes.service/rpc/BuildBuddyService/GetInvocation' -d '{"lookup": {"invocation_id": "00000000-0000-0000-0000-00000000"}}' -H 'Content-Type: application/json' | ./process_build_events.jq | |
[inputs | .invocation[0].event[].buildEvent | |
| select(.id != null) | |
| if .id.targetCompleted != null then | |
if .aborted != null then { | |
"type": "aborted", | |
"label": .id.targetCompleted.label | |
} | |
elif .completed.success == null then { | |
"type": "failed", | |
"label": .id.targetCompleted.label | |
} | |
else { | |
"type": "succeeded", | |
"label": .id.targetCompleted.label | |
} | |
end | |
else empty | |
end | |
] as $events | |
# Counting and listing | |
| reduce $events[] as $event ( | |
{ | |
targets: 0, | |
succeeded_count: 0, | |
failed_count: 0, | |
aborted_count: 0, | |
succeeded: [], | |
failed: [], | |
aborted: [] | |
}; | |
if $event.type == "succeeded" then | |
.targets += 1 | .succeeded_count += 1 | .succeeded += [$event.label] | |
elif $event.type == "failed" then | |
.targets += 1 | .failed_count += 1 | .failed += [$event.label] | |
elif $event.type == "aborted" then | |
.targets += 1 | .aborted_count += 1 | .aborted += [$event.label] | |
else | |
. | |
end | |
) | |
# Calculating percentage and formatting output | |
| { | |
PERCENTAGE: ((.succeeded_count / .targets * 100) | tonumber), | |
TOTAL: .targets, | |
SUCCEEDED_COUNT: .succeeded_count, | |
FAILED_COUNT: .failed_count, | |
ABORTED_COUNT: .aborted_count, | |
SUCCEEDED: .succeeded, | |
FAILED: .failed, | |
ABORTED: .aborted | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment