Skip to content

Commit 193fe34

Browse files
ci: send slack message when ci fails on main
1 parent 407cf62 commit 193fe34

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Notify Slack on Failure
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
context_title:
7+
required: true
8+
type: string
9+
description: The context title (e.g., "PR #123: Title" or "main branch")
10+
failed_job_name:
11+
required: true
12+
type: string
13+
description: The name of the failed job
14+
secrets:
15+
SLACK_WEBHOOK_URL:
16+
required: true
17+
18+
jobs:
19+
notify-slack:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Send Slack Notification
23+
uses: slackapi/[email protected]
24+
with:
25+
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
26+
webhook-type: incoming-webhook
27+
28+
payload: |
29+
text: "@channel CI failed on ${{ inputs.context_title }}"
30+
blocks:
31+
- type: "section"
32+
text:
33+
type: "mrkdwn"
34+
text: "<!channel> :rotating_light: *CI FAILED on ${{ inputs.context_title }}*"
35+
36+
- type: "section"
37+
fields:
38+
- type: "mrkdwn"
39+
text: "*Workflow:*\n`${{ github.workflow }}`"
40+
- type: "mrkdwn"
41+
text: "*Failed Job:*\n`${{ inputs.failed_job_name }}`"
42+
- type: "mrkdwn"
43+
text: "*Commit:*\n`${{ github.sha }}`"
44+
- type: "mrkdwn"
45+
text: "*Author:*\n`${{ github.actor }}`"
46+
47+
- type: "section"
48+
text:
49+
type: "mrkdwn"
50+
text: "<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|View failed job run>"
51+

.github/workflows/on-merge.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ jobs:
99
test:
1010
uses: ./.github/workflows/test.yaml
1111
secrets: inherit
12+
13+
notify-slack:
14+
needs: test
15+
if: failure()
16+
uses: ./.github/workflows/notify-slack.yaml
17+
with:
18+
context_title: "main branch"
19+
failed_job_name: "test"
20+
secrets: inherit

0 commit comments

Comments
 (0)