diff options
author | Chris Evich <cevich@redhat.com> | 2022-07-13 14:41:16 -0400 |
---|---|---|
committer | Chris Evich <cevich@redhat.com> | 2022-07-14 14:42:59 -0400 |
commit | d95e79ebe3c620b15834c972c281442cfeb31c5a (patch) | |
tree | 4d0b15c8901df7ac7394a2a971631b3263435520 /.github/actions | |
parent | 3637d55191be2e9a5b9e13f8f62db4c27d188741 (diff) | |
download | podman-d95e79ebe3c620b15834c972c281442cfeb31c5a.tar.gz podman-d95e79ebe3c620b15834c972c281442cfeb31c5a.tar.bz2 podman-d95e79ebe3c620b15834c972c281442cfeb31c5a.zip |
GHA: Fix dumb error check
Previously the reply JSON was examined for the literal presence of the
string 'error'. This was intended to catch server or query errors and
the like. However it's not a sound design as valid/legitimate contents
could potentially contain the string. Fix this by using the `-e` option
to `jq`, with a filter that should always result in a non-empty/null
match. If this fails or returns null for some reason, then it's safe to
throw a real error code & message.
Signed-off-by: Chris Evich <cevich@redhat.com>
Diffstat (limited to '.github/actions')
-rwxr-xr-x | .github/actions/check_cirrus_cron/cron_failures.sh | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/.github/actions/check_cirrus_cron/cron_failures.sh b/.github/actions/check_cirrus_cron/cron_failures.sh index 4fb3af98f..f4dddff8b 100755 --- a/.github/actions/check_cirrus_cron/cron_failures.sh +++ b/.github/actions/check_cirrus_cron/cron_failures.sh @@ -67,11 +67,6 @@ jq --indent 4 --color-output . <./artifacts/reply.json || \ cat ./artifacts/reply.json echo "::endgroup::" -# Desirable to catch non-JSON encoded errors in reply. -if grep -qi 'error' ./artifacts/reply.json; then - err "Found the word 'error' in reply" -fi - # e.x. reply.json # { # "data": { @@ -102,8 +97,19 @@ fi # } # } # } -_filt='.data.ownerRepository.cronSettings | map(select(.lastInvocationBuild.status=="FAILED") | { name:.name, id:.lastInvocationBuild.id} | join(" ")) | join("\n")' -jq --raw-output "$_filt" ./artifacts/reply.json > "$NAME_ID_FILEPATH" + +# This should never ever return an empty-list, unless there are no cirrus-cron +# jobs defined for the repository. In that case, this monitoring script shouldn't +# be running anyway. +filt_head='.data.ownerRepository.cronSettings' +if ! jq -e "$filt_head" ./artifacts/reply.json &> /dev/null +then + # Actual colorized JSON reply was printed above + err "Null/empty result filtering reply with '$filt_head'" +fi + +filt="$filt_head | map(select(.lastInvocationBuild.status==\"FAILED\") | { name:.name, id:.lastInvocationBuild.id} | join(\" \")) | join(\"\n\")" +jq --raw-output "$filt" ./artifacts/reply.json > "$NAME_ID_FILEPATH" echo "<Cron Name> <Failed Build ID>" cat "$NAME_ID_FILEPATH" |