Files
Chris Evich a7271f9dd7 GHA: Fix bad job-names & links in monitoring emails
Due to a bad file-format design, if a cirrus-cron job happened to have a
name w/ spaces, the generated e-mail text would be broken.  For example:

```
Cron build 'VM' Failed: https://cirrus-ci.com/build/Image Maintenance
5630822628196352
```

Fix this by flipping the field-order in an intermediate file, so the
build ID comes first, then the job name.  This makes it much easier for
`read` to process, since all words will be stored into the final
variable (now the job name).

Also change all variables that reference this intermediate file such
that they continue to reflect the expected field order.  Update script
tests and add a new test to confirm expected file processing and output.

Signed-off-by: Chris Evich <cevich@redhat.com>
2023-06-07 15:22:17 -04:00

41 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -eo pipefail
# Intended to be executed from a github action workflow step.
# Input: File listing space separated failed cron build names and IDs
# Output: $GITHUB_WORKSPACE/artifacts/email_body.txt file
source $(dirname "${BASH_SOURCE[0]}")/lib.sh
_errfmt="Expecting %s value to not be empty"
# ID_NAME_FILEPATH is defined by workflow YAML
# shellcheck disable=SC2154
if [[ -z "$GITHUB_REPOSITORY" ]]; then
err $(printf "$_errfmt" "\$GITHUB_REPOSITORY")
elif [[ ! -r "$ID_NAME_FILEPATH" ]]; then
err "Expecting \$ID_NAME_FILEPATH value ($ID_NAME_FILEPATH) to be a readable file"
fi
confirm_gha_environment
# GITHUB_WORKSPACE confirmed by confirm_gha_environment()
# shellcheck disable=SC2154
mkdir -p "$GITHUB_WORKSPACE/artifacts"
(
echo "Detected one or more Cirrus-CI cron-triggered jobs have failed recently:"
echo ""
while read -r BID NAME; do
echo "Cron build '$NAME' Failed: https://cirrus-ci.com/build/$BID"
done < "$ID_NAME_FILEPATH"
echo ""
# Defined by github-actions
# shellcheck disable=SC2154
echo "# Source: ${GITHUB_WORKFLOW} workflow on ${GITHUB_REPOSITORY}."
# Separate content from sendgrid.com automatic footer.
echo ""
echo ""
) > $GITHUB_WORKSPACE/artifacts/email_body.txt