Skip to content

Instantly share code, notes, and snippets.

@r2r-dev
Last active March 1, 2024 10:59
Show Gist options
  • Save r2r-dev/ea8edfe27f9ab1d736edeb76c13d25f4 to your computer and use it in GitHub Desktop.
Save r2r-dev/ea8edfe27f9ab1d736edeb76c13d25f4 to your computer and use it in GitHub Desktop.
process_build_events.jq
#!/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