Skip to content

Slack CI Failure Alerts #2238

Slack CI Failure Alerts

Slack CI Failure Alerts #2238

name: Slack CI Failure Alerts
on:
workflow_run:
workflows:
- Graphs CI
- Response Time CI
- Setup CI
- Static Site CI
- Summary CI
- Updates CI
- Update Template CI
- Uptime CI
types: [completed]
jobs:
notify:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'failure'
permissions:
actions: read
steps:
# Upptime calls the GitHub API before probing any endpoint, so a GitHub 5xx fails
# the run with no bearing on CoW uptime. Flag it so the alert says so.
- name: Was this a GitHub API outage?
id: triage
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
REPO: ${{ github.repository }}
run: |
logs=$(gh run view "$RUN_ID" --repo "$REPO" --log-failed 2>/dev/null || true)
if grep -qE "RequestError \[HttpError\]" <<<"$logs" && grep -qE "status: 5[0-9][0-9]," <<<"$logs"; then
echo "github_fault=true" >> "$GITHUB_OUTPUT"
else
echo "github_fault=false" >> "$GITHUB_OUTPUT"
fi
- name: Notify Slack
run: |
if [ "$GITHUB_FAULT" = "true" ]; then
text="⚠️ GitHub API is unreachable, so *$WORKFLOW* could not run — can't assert CoW services uptime right now. <$URL|See run>."
else
text="❌ $WORKFLOW failed on \`$BRANCH\`. <$URL|See run>."
fi
payload=$(jq -n --arg text "$text" '{text: $text}')
curl -X POST -H "Content-type: application/json" --data "$payload" "$SLACK_WEBHOOK_URL"
env:
SLACK_WEBHOOK_URL: ${{ secrets.NOTIFICATION_SLACK_WEBHOOK_URL }}
WORKFLOW: ${{ github.event.workflow_run.name }}
BRANCH: ${{ github.event.workflow_run.head_branch }}
URL: ${{ github.event.workflow_run.html_url }}
GITHUB_FAULT: ${{ steps.triage.outputs.github_fault }}