Skip to content

Commit becfb96

Browse files
ryan-williamsclaude
andcommitted
daily: notify #crash-bot-ci on workflow failure
Yesterday's 403 (NJSP feed) and today's GH-API 429 (crash-log walker) both silently failed — there was no whole-pipeline failure notification, only the narrow `summaries.dvc` PDF/XML-mismatch hook from `notify.py`. Both cron-scheduled runs went unnoticed, missing a day of NJSP refresh. Add a final `if: failure()` step that delegates to `.github/scripts/notify-ci-failure.sh`: - Looks up which step failed via `gh run view --json jobs --jq …` - Posts ":x: *Daily pipeline failed* at \`<step>\` (<branch> <sha> <subject>, event=<schedule|workflow_dispatch>)" with a "view run" link - No-op (prints to stdout instead of raising) when `SLACK_CI_CHANNEL_ID` or `SLACK_BOT_TOKEN` isn't set, so dev/test runs stay quiet - Surfaces Slack API failures via `::warning::` annotation rather than blocking — the pipeline already failed; we don't want notification failure to mask the real cause Pure-bash so it still runs even when the failure is in early dependency- install steps (before `.venv/bin` lands on `PATH`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1788863 commit becfb96

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
# Post a CI-failure summary to Slack channel `$SLACK_CI_CHANNEL_ID`.
3+
#
4+
# Wired into `.github/workflows/daily.yml` as the final step under
5+
# `if: failure()`. Pure-bash so it still runs even when the failure is in
6+
# Python / dependency-install steps before `.venv/bin` is on PATH.
7+
#
8+
# Required env (set by the GHA shell automatically unless noted):
9+
# GITHUB_RUN_ID — for `gh run view` lookup of the failed step
10+
# GITHUB_SHA — commit SHA
11+
# GITHUB_REF_NAME — branch
12+
# GITHUB_SERVER_URL — e.g. https://github.com
13+
# GITHUB_REPOSITORY — owner/repo
14+
# GH_TOKEN — must be passed in step env (gh CLI auth)
15+
# EVENT_NAME — caller-set; the workflow's event (schedule / workflow_dispatch / …)
16+
# SLACK_BOT_TOKEN, SLACK_CI_CHANNEL_ID
17+
# — Slack post target; if either is unset the script
18+
# prints the would-be message and exits 0 so the
19+
# underlying CI failure remains the loud signal.
20+
#
21+
# Slack post failures are logged as a `::warning::` GHA annotation rather
22+
# than re-raising — the pipeline already failed and we don't want a notify
23+
# bug to mask the real cause.
24+
25+
set -euo pipefail
26+
27+
run_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
28+
29+
failed_step=$(gh run view "${GITHUB_RUN_ID}" --json jobs \
30+
--jq '.jobs[].steps[] | select(.conclusion == "failure") | .name' \
31+
| head -1)
32+
failed_step="${failed_step:-unknown step}"
33+
short_sha="${GITHUB_SHA:0:7}"
34+
commit_subject=$(git log -1 --format=%s "${GITHUB_SHA}" 2>/dev/null || echo '(unavailable)')
35+
36+
text=":x: *Daily pipeline failed* at \`${failed_step}\` (\`${GITHUB_REF_NAME}\` ${short_sha} _${commit_subject}_, event=${EVENT_NAME:-?})"$'\n'"<${run_url}|view run>"
37+
38+
if [[ -z "${SLACK_CI_CHANNEL_ID:-}" || -z "${SLACK_BOT_TOKEN:-}" ]]; then
39+
echo "SLACK_CI_CHANNEL_ID or SLACK_BOT_TOKEN unset; would-be message:"
40+
printf '%s\n' "$text"
41+
exit 0
42+
fi
43+
44+
payload=$(jq -nc \
45+
--arg channel "${SLACK_CI_CHANNEL_ID}" \
46+
--arg text "$text" \
47+
'{channel: $channel, text: $text, unfurl_links: false, unfurl_media: false}')
48+
49+
resp=$(curl -sS -X POST https://slack.com/api/chat.postMessage \
50+
-H "Authorization: Bearer ${SLACK_BOT_TOKEN}" \
51+
-H 'Content-Type: application/json; charset=utf-8' \
52+
-d "$payload")
53+
echo "Slack response: $resp"
54+
55+
ok=$(printf '%s' "$resp" | jq -r '.ok // false')
56+
if [[ "$ok" != "true" ]]; then
57+
echo "::warning::Slack CI notification failed: $resp"
58+
fi

.github/workflows/daily.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,9 @@ jobs:
151151
- name: Run custom targets
152152
if: ${{ inputs.targets }}
153153
run: $DVX ${{ inputs.targets }}
154+
- name: "Notify #crash-bot-ci on failure"
155+
if: failure()
156+
env:
157+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
158+
EVENT_NAME: ${{ github.event_name }}
159+
run: bash .github/scripts/notify-ci-failure.sh

0 commit comments

Comments
 (0)