Skip to content

CI Failure Alert

CI Failure Alert #288

name: CI Failure Alert
on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
jobs:
alert:
if: github.event.workflow_run.conclusion == 'failure'
runs-on: ubuntu-latest
steps:
- name: Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
REPOSITORY: ${{ github.repository }}
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
WORKFLOW_CONCLUSION: ${{ github.event.workflow_run.conclusion }}
WORKFLOW_URL: ${{ github.event.workflow_run.html_url }}
COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }}
ACTOR_LOGIN: ${{ github.event.workflow_run.actor.login }}
run: |
if [ -z "$DISCORD_WEBHOOK" ]; then
echo "DISCORD_WEBHOOK is not configured; skipping CI failure notification."
exit 0
fi
CONTENT=$(cat << EOF
⚠️ **CI Failure on main**
Repository: \`$REPOSITORY\`
Workflow: \`$WORKFLOW_NAME\`
Conclusion: \`$WORKFLOW_CONCLUSION\`
Run: $WORKFLOW_URL
Commit: \`$COMMIT_MESSAGE\`
Author: $ACTOR_LOGIN
EOF
)
PAYLOAD=$(jq -n --arg content "$CONTENT" '{content: $content}'
)
curl -fsS -H "Content-Type: application/json" -d "$PAYLOAD" "$DISCORD_WEBHOOK"