diff options
author | Chris Evich <cevich@redhat.com> | 2020-10-07 16:43:36 -0400 |
---|---|---|
committer | Chris Evich <cevich@redhat.com> | 2020-11-18 15:34:01 -0500 |
commit | 887f88c490a63e759a34eaf642a4eb47e8087512 (patch) | |
tree | 615ca61a428cae6deade313ced9b46a471538827 /.github/actions | |
parent | 4434bd797842c3015c0e6132eaf2509fed370c26 (diff) | |
download | podman-887f88c490a63e759a34eaf642a4eb47e8087512.tar.gz podman-887f88c490a63e759a34eaf642a4eb47e8087512.tar.bz2 podman-887f88c490a63e759a34eaf642a4eb47e8087512.zip |
Github-Actions: Send e-mail on Cirrus cron failure
This repository has a number of automaticly triggered branch-level
testing enabled. However, other than remembering to go look at a
specific WebUI, there is no way for anybody to notice if/when these jobs
fail.
This commit introduces a github-action workflow which runs periodically,
checking for failed cron-triggered Cirrus-CI jobs. When it finds any, it
formats a simple report for e-mail delivery. The list of destination
addresses is configurable at any time by merging changes to a
simple CSV file.
Signed-off-by: Chris Evich <cevich@redhat.com>
Diffstat (limited to '.github/actions')
-rwxr-xr-x | .github/actions/check_cirrus_cron/cron_failures.sh | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/.github/actions/check_cirrus_cron/cron_failures.sh b/.github/actions/check_cirrus_cron/cron_failures.sh new file mode 100755 index 000000000..2693df417 --- /dev/null +++ b/.github/actions/check_cirrus_cron/cron_failures.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +set -eo pipefail + +# Intended to be executed from a github action workflow step. +# Outputs the Cirrus cron names and IDs of any failed builds + +err() { + # Ref: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions + echo "::error file=${BASH_SOURCE[0]},line=${BASH_LINENO[0]}::${1:-No error message given}" + exit 1 +} + +_errfmt="Expecting %s value to not be empty" +if [[ -z "$GITHUB_REPOSITORY" ]]; then + err $(printf "$_errfmt" "\$GITHUB_REPOSITORY") +elif [[ -z "$NAME_ID_FILEPATH" ]]; then + err $(printf "$_errfmt" "\$NAME_ID_FILEPATH") +fi + +mkdir -p artifacts +cat > ./artifacts/query_raw.json << "EOF" +{"query":" + query CronNameStatus($owner: String!, $repo: String!) { + githubRepository(owner: $owner, name: $repo) { + cronSettings { + name + lastInvocationBuild { + id + status + } + } + } + } +", +"variables":"{ + \"owner\": \"@@OWNER@@\", + \"repo\": \"@@REPO@@\" +}"} +EOF +# Makes for easier copy/pasting query to/from +# https://cirrus-ci.com/explorer +owner=$(cut -d '/' -f 1 <<<"$GITHUB_REPOSITORY") +repo=$(cut -d '/' -f 2 <<<"$GITHUB_REPOSITORY") +sed -i -r -e "s/@@OWNER@@/$owner/g" -e "s/@@REPO@@/$repo/g" ./artifacts/query_raw.json + +echo "::group::Posting GraphQL Query" +# Easier to debug in error-reply when query is compacted +tr -d '\n' < ./artifacts/query_raw.json | tr -s ' ' | tee ./artifacts/query.json | \ + jq --indent 4 --color-output . + +if grep -q '@@' ./artifacts/query.json; then + err "Found unreplaced substitution token in raw query JSON" +fi +curl \ + --request POST \ + --silent \ + --location \ + --header 'content-type: application/json' \ + --url 'https://api.cirrus-ci.com/graphql' \ + --data @./artifacts/query.json \ + --output ./artifacts/reply.json +echo "::endgroup::" + +echo "::group::Received GraphQL Reply" +jq --indent 4 --color-output . <./artifacts/reply.json || \ + cat ./artifacts/reply.json +echo "::endgroup::" + +# Desireable 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": { +# "githubRepository": { +# "cronSettings": [ +# { +# "name": "Keepalive_v2.0", +# "lastInvocationBuild": { +# "id": "5776050544181248", +# "status": "EXECUTING" +# } +# }, +# { +# "name": "Keepalive_v1.9", +# "lastInvocationBuild": { +# "id": "5962921081569280", +# "status": "COMPLETED" +# } +# }, +# { +# "name": "Keepalive_v2.0.5-rhel", +# "lastInvocationBuild": { +# "id": "5003065549914112", +# "status": "FAILED" +# } +# } +# ] +# } +# } +# } +_filt='.data.githubRepository.cronSettings | 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" + +# Don't rely on a newline present for zero/one output line, always count words +records=$(wc --words "$NAME_ID_FILEPATH" | cut -d ' ' -f 1) +# Always two words per record +failures=$((records/2)) +echo "::set-output name=failures::$failures" +echo "Total failed Cirrus-CI cron builds: $failures" |