mirror of
https://github.com/containers/podman.git
synced 2025-06-28 22:53:21 +08:00
GHA: Migrate inline script to file
Inline scripts make github-action workflow YAML harder to read/maintain. Relocate the e-mail formation script to a dedicated file. This also permits better input-validation and re-use of a common `err()` function. Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
@ -5,11 +5,7 @@ set -eo pipefail
|
|||||||
# Intended to be executed from a github action workflow step.
|
# Intended to be executed from a github action workflow step.
|
||||||
# Outputs the Cirrus cron names and IDs of any failed builds
|
# Outputs the Cirrus cron names and IDs of any failed builds
|
||||||
|
|
||||||
err() {
|
source $(dirname "${BASH_SOURCE[0]}")/lib.sh
|
||||||
# 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"
|
_errfmt="Expecting %s value to not be empty"
|
||||||
if [[ -z "$GITHUB_REPOSITORY" ]]; then
|
if [[ -z "$GITHUB_REPOSITORY" ]]; then
|
||||||
@ -118,5 +114,5 @@ cat "$NAME_ID_FILEPATH"
|
|||||||
records=$(wc --words "$NAME_ID_FILEPATH" | cut -d ' ' -f 1)
|
records=$(wc --words "$NAME_ID_FILEPATH" | cut -d ' ' -f 1)
|
||||||
# Always two words per record
|
# Always two words per record
|
||||||
failures=$((records/2))
|
failures=$((records/2))
|
||||||
echo "::set-output name=failures::$failures"
|
echo "failures::$failures" >> $GITHUB_OUTPUT
|
||||||
echo "Total failed Cirrus-CI cron builds: $failures"
|
echo "Total failed Cirrus-CI cron builds: $failures"
|
||||||
|
7
.github/actions/check_cirrus_cron/lib.sh
vendored
Normal file
7
.github/actions/check_cirrus_cron/lib.sh
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
# Must be called from top-level of script, not another function.
|
||||||
|
err() {
|
||||||
|
# Ref: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions
|
||||||
|
echo "::error file=${BASH_SOURCE[1]},line=${BASH_LINENO[1]}::${1:-No error message given}"
|
||||||
|
exit 1
|
||||||
|
}
|
35
.github/actions/check_cirrus_cron/make_email_body.sh
vendored
Executable file
35
.github/actions/check_cirrus_cron/make_email_body.sh
vendored
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
#!/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"
|
||||||
|
if [[ -z "$GITHUB_REPOSITORY" ]]; then
|
||||||
|
err $(printf "$_errfmt" "\$GITHUB_REPOSITORY")
|
||||||
|
elif [[ -z "$GITHUB_WORKFLOW" ]]; then
|
||||||
|
err $(printf "$_errfmt" "\$GITHUB_WORKFLOW")
|
||||||
|
elif [[ ! -r "$NAME_ID_FILEPATH" ]]; then
|
||||||
|
_errfmt="Expecting %s value to be a readable file"
|
||||||
|
err $(printf "$_errfmt" "\$NAME_ID_FILEPATH")
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p artifacts
|
||||||
|
(
|
||||||
|
echo "Detected one or more Cirrus-CI cron-triggered jobs have failed recently:"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
while read -r NAME BID; do
|
||||||
|
echo "Cron build '$NAME' Failed: https://cirrus-ci.com/build/$BID"
|
||||||
|
done < "$NAME_ID_FILEPATH"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "# Source: ${GITHUB_WORKFLOW} workflow on ${GITHUB_REPOSITORY}."
|
||||||
|
# Separate content from sendgrid.com automatic footer.
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
) > ./artifacts/email_body.txt
|
19
.github/workflows/check_cirrus_cron.yml
vendored
19
.github/workflows/check_cirrus_cron.yml
vendored
@ -42,24 +42,7 @@ jobs:
|
|||||||
|
|
||||||
- if: steps.cron.outputs.failures > 0
|
- if: steps.cron.outputs.failures > 0
|
||||||
shell: bash
|
shell: bash
|
||||||
# Must be inline, since context expressions are used.
|
run: './.github/actions/check_cirrus_cron/make_email_body'
|
||||||
# Ref: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions
|
|
||||||
run: |
|
|
||||||
set -eo pipefail
|
|
||||||
(
|
|
||||||
echo "Detected one or more Cirrus-CI cron-triggered jobs have failed recently:"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
while read -r NAME BID; do
|
|
||||||
echo "Cron build '$NAME' Failed: https://cirrus-ci.com/build/$BID"
|
|
||||||
done < "$NAME_ID_FILEPATH"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "# Source: ${{ github.workflow }} workflow on ${{ github.repository }}."
|
|
||||||
# Separate content from sendgrid.com automatic footer.
|
|
||||||
echo ""
|
|
||||||
echo ""
|
|
||||||
) > ./artifacts/email_body.txt
|
|
||||||
|
|
||||||
- if: steps.cron.outputs.failures > 0
|
- if: steps.cron.outputs.failures > 0
|
||||||
name: Send failure notification e-mail
|
name: Send failure notification e-mail
|
||||||
|
Reference in New Issue
Block a user