mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +08:00
GHA: Update scripts to pass shellcheck
Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
@ -14,7 +14,9 @@ elif [[ -z "$NAME_ID_FILEPATH" ]]; then # output filepath
|
||||
err $(printf "$_errfmt" "\$NAME_ID_FILEPATH")
|
||||
fi
|
||||
|
||||
mkdir -p artifacts
|
||||
confirm_gha_environment
|
||||
|
||||
mkdir -p ./artifacts
|
||||
cat > ./artifacts/query_raw.json << "EOF"
|
||||
query {
|
||||
ownerRepository(platform: "LINUX", owner: "@@OWNER@@", name: "@@REPO@@") {
|
||||
@ -84,5 +86,6 @@ records=$(wc --words "$NAME_ID_FILEPATH" | cut -d ' ' -f 1)
|
||||
failures=$((records/2))
|
||||
# Set the output of this step.
|
||||
# Ref: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
|
||||
# shellcheck disable=SC2154
|
||||
echo "failures::$failures" >> $GITHUB_OUTPUT
|
||||
echo "Total failed Cirrus-CI cron builds: $failures"
|
||||
|
21
.github/actions/check_cirrus_cron/lib.sh
vendored
21
.github/actions/check_cirrus_cron/lib.sh
vendored
@ -8,10 +8,27 @@ msg() {
|
||||
# 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
|
||||
msg "::error file=${BASH_SOURCE[1]},line=${BASH_LINENO[0]}::$@"
|
||||
msg "::error file=${BASH_SOURCE[1]},line=${BASH_LINENO[0]}::$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
confirm_gha_environment() {
|
||||
_errfmt="I don't seem to be running from a github-actions workflow"
|
||||
# These are all defined by github-actions
|
||||
# shellcheck disable=SC2154
|
||||
if [[ -z "$GITHUB_OUTPUT" ]]; then
|
||||
err "$_errfmt, \$GITHUB_OUTPUT is empty"
|
||||
elif [[ -z "$GITHUB_WORKFLOW" ]]; then
|
||||
err "$_errfmt, \$GITHUB_WORKFLOW is empty"
|
||||
elif [[ ! -d "$GITHUB_WORKSPACE" ]]; then
|
||||
# Defined by github-actions
|
||||
# shellcheck disable=SC2154
|
||||
err "$_errfmt, \$GITHUB_WORKSPACE='$GITHUB_WORKSPACE' isn't a directory"
|
||||
fi
|
||||
|
||||
cd "$GITHUB_WORKSPACE" || false
|
||||
}
|
||||
|
||||
# Using python3 here is a compromise for readability and
|
||||
# properly handling quote, control and unicode character encoding.
|
||||
escape_query() {
|
||||
@ -45,6 +62,8 @@ gql() {
|
||||
msg "::error file=${BASH_SOURCE[1]},line=${BASH_LINENO[0]}::Invalid query JSON: $query"
|
||||
return 1
|
||||
fi
|
||||
# SECRET_CIRRUS_API_KEY is defined github secret
|
||||
# shellcheck disable=SC2154
|
||||
if output=$(curl \
|
||||
--request POST \
|
||||
--silent \
|
||||
|
@ -9,14 +9,16 @@ set -eo pipefail
|
||||
source $(dirname "${BASH_SOURCE[0]}")/lib.sh
|
||||
|
||||
_errfmt="Expecting %s value to not be empty"
|
||||
# NAME_ID_FILEPATH is defined by workflow YAML
|
||||
# shellcheck disable=SC2154
|
||||
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
|
||||
err "Expecting \$NAME_ID_FILEPATH value ($NAME_ID_FILEPATH) to be a readable file"
|
||||
fi
|
||||
|
||||
confirm_gha_environment
|
||||
|
||||
mkdir -p artifacts
|
||||
(
|
||||
echo "Detected one or more Cirrus-CI cron-triggered jobs have failed recently:"
|
||||
@ -27,6 +29,8 @@ mkdir -p artifacts
|
||||
done < "$NAME_ID_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 ""
|
||||
|
@ -25,12 +25,16 @@ set -eo pipefail
|
||||
source $(dirname "${BASH_SOURCE[0]}")/lib.sh
|
||||
|
||||
_errfmt="Expecting %s value to not be empty"
|
||||
# NAME_ID_FILEPATH is defined by workflow YAML
|
||||
# shellcheck disable=SC2154
|
||||
if [[ -z "$SECRET_CIRRUS_API_KEY" ]]; then
|
||||
err $(printf "$_errfmt" "\$SECRET_CIRRUS_API_KEY")
|
||||
elif [[ ! -r "$NAME_ID_FILEPATH" ]]; then # output from cron_failures.sh
|
||||
err $(printf "Expecting %s value to be a readable file" "\$NAME_ID_FILEPATH")
|
||||
fi
|
||||
|
||||
confirm_gha_environment
|
||||
|
||||
mkdir -p artifacts
|
||||
# If there are no tasks, don't fail reading the file
|
||||
truncate -s 0 ./artifacts/rerun_tids.txt
|
||||
@ -92,7 +96,7 @@ cat "$NAME_ID_FILEPATH" | \
|
||||
# Check-value returned if the gql call was successful
|
||||
canary=$(uuidgen)
|
||||
# Ensure the trailing ',' is stripped from the end (would be invalid JSON)
|
||||
task_ids=$(printf '[%s]' $(printf '"%s",' ${rerun_tasks[@]} | head -c -1))
|
||||
task_ids=$(printf '[%s]' $(printf '"%s",' ${rerun_tasks[*]} | head -c -1))
|
||||
rerun_m="
|
||||
mutation {
|
||||
batchReRun(input: {
|
||||
@ -107,6 +111,6 @@ cat "$NAME_ID_FILEPATH" | \
|
||||
filter='.data.batchReRun.clientMutationId'
|
||||
result=$(gql "$rerun_m" "$filter")
|
||||
if [[ $(jq -r -e "$filter"<<<"$result") != "$canary" ]]; then
|
||||
err "Attempt to re-run tasks for build $BID failed: ${rerun_tasks[@]}"
|
||||
err "Attempt to re-run tasks for build $BID failed: ${rerun_tasks[*]}"
|
||||
fi
|
||||
done
|
||||
|
Reference in New Issue
Block a user