2026-10-28 09:21:58 +01:00
|
|
|
name: CI notify
|
|
|
|
|
description: >
|
|
|
|
|
Send one ntfy notification for a whole workflow run: a failure whenever a job
|
|
|
|
|
failed, and a success when every job passed on a branch that ships.
|
|
|
|
|
|
|
|
|
|
inputs:
|
|
|
|
|
needs:
|
|
|
|
|
description: The jobs to report on, as ${{ toJSON(needs) }}
|
|
|
|
|
required: true
|
|
|
|
|
success_branches:
|
|
|
|
|
description: Branches whose successful runs are announced, separated by spaces
|
|
|
|
|
default: master
|
|
|
|
|
ntfy_url:
|
|
|
|
|
description: ntfy server URL
|
|
|
|
|
default: https://ntfy.zlymeda.dynu.net
|
|
|
|
|
ntfy_topic:
|
2026-10-28 09:41:23 +01:00
|
|
|
description: ntfy topic
|
2026-10-28 09:21:58 +01:00
|
|
|
default: gitea-releases
|
|
|
|
|
ntfy_token:
|
2026-10-28 09:41:23 +01:00
|
|
|
description: ntfy token (secrets.NTFY_TOKEN)
|
2026-10-28 09:21:58 +01:00
|
|
|
default: ''
|
|
|
|
|
|
|
|
|
|
runs:
|
|
|
|
|
using: composite
|
|
|
|
|
steps:
|
|
|
|
|
- name: Notify
|
|
|
|
|
shell: bash
|
|
|
|
|
env:
|
|
|
|
|
NEEDS: ${{ inputs.needs }}
|
|
|
|
|
SUCCESS_BRANCHES: ${{ inputs.success_branches }}
|
|
|
|
|
NTFY_URL: ${{ inputs.ntfy_url }}
|
|
|
|
|
NTFY_TOPIC: ${{ inputs.ntfy_topic }}
|
|
|
|
|
NTFY_TOKEN: ${{ inputs.ntfy_token }}
|
|
|
|
|
REPO: ${{ github.repository }}
|
|
|
|
|
BRANCH: ${{ github.ref_name }}
|
|
|
|
|
SHA: ${{ github.sha }}
|
|
|
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
# toJSON(needs) is pretty printed: a job name at two spaces, its "result" below it.
|
|
|
|
|
results=$(printf '%s\n' "$NEEDS" | awk '
|
|
|
|
|
/^ "[^"]+": *\{/ { match($0, /"[^"]+"/); job = substr($0, RSTART + 1, RLENGTH - 2) }
|
|
|
|
|
/"result": *"/ { match($0, /"result": *"[^"]+"/); r = substr($0, RSTART, RLENGTH); sub(/.*"result": *"/, "", r); sub(/"$/, "", r); print job, r }')
|
|
|
|
|
[ -n "$results" ] || { echo "no job results in needs: $NEEDS"; exit 1; }
|
|
|
|
|
echo "$results"
|
|
|
|
|
failed=$(awk '$2 == "failure" { printf "%s%s", sep, $1; sep = ", " }' <<<"$results")
|
|
|
|
|
cancelled=$(awk '$2 == "cancelled" { print $1 }' <<<"$results")
|
|
|
|
|
passed=$(awk '$2 == "success" { printf "%s%s", sep, $1; sep = ", " }' <<<"$results")
|
|
|
|
|
|
2026-10-28 09:41:23 +01:00
|
|
|
send() { # priority tags message
|
2026-10-28 09:21:58 +01:00
|
|
|
auth=()
|
2026-10-28 09:41:23 +01:00
|
|
|
[ -n "$NTFY_TOKEN" ] && auth=(-H "Authorization: Bearer $NTFY_TOKEN")
|
|
|
|
|
curl -sSf -H "Title: $REPO ($BRANCH)" -H "Priority: $1" -H "Tags: $2" -H "Click: $RUN_URL" \
|
|
|
|
|
"${auth[@]}" -d "$3" "$NTFY_URL/$NTFY_TOPIC" >/dev/null
|
2026-10-28 09:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ -n "$failed" ]; then
|
2026-10-28 09:41:23 +01:00
|
|
|
send 5 "rotating_light,warning" "Failed: $failed (${SHA:0:7})"
|
2026-10-28 09:21:58 +01:00
|
|
|
elif [ -n "$cancelled" ]; then
|
|
|
|
|
echo "cancelled, nothing to announce"
|
|
|
|
|
elif [ -n "$passed" ] && [[ " $SUCCESS_BRANCHES " == *" $BRANCH "* ]]; then
|
2026-10-28 09:41:23 +01:00
|
|
|
send 3 "rocket,white_check_mark" "Passed: $passed (${SHA:0:7})"
|
2026-10-28 09:21:58 +01:00
|
|
|
else
|
|
|
|
|
echo "$BRANCH is not announced on success"
|
|
|
|
|
fi
|