CI Failure Alert #296
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| PAYLOAD=$(jq -n \ | |
| --arg repository "$REPOSITORY" \ | |
| --arg workflow "$WORKFLOW_NAME" \ | |
| --arg conclusion "$WORKFLOW_CONCLUSION" \ | |
| --arg url "$WORKFLOW_URL" \ | |
| --arg commit "$COMMIT_MESSAGE" \ | |
| --arg actor "$ACTOR_LOGIN" \ | |
| '{ | |
| content: ( | |
| "⚠️ **CI Failure on main**\n" + | |
| "Repository: `" + $repository + "`\n" + | |
| "Workflow: `" + $workflow + "`\n" + | |
| "Conclusion: `" + $conclusion + "`\n" + | |
| "Run: " + $url + "\n" + | |
| "Commit: `" + $commit + "`\n" + | |
| "Author: " + $actor | |
| ) | |
| }') | |
| curl -fsS -H "Content-Type: application/json" -d "$PAYLOAD" "$DISCORD_WEBHOOK" |