Skip to content

Commit 5588a95

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

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,26 @@ jobs:
99
test:
1010
uses: ./.github/workflows/test.yaml
1111
secrets: inherit
12+
13+
determine-failed-job:
14+
needs: test
15+
if: failure()
16+
runs-on: ubuntu-latest
17+
outputs:
18+
job_name: ${{ steps.set-job.outputs.job_name }}
19+
steps:
20+
- name: Determine failed job
21+
id: set-job
22+
run: |
23+
if [ "${{ needs.test.result }}" == "failure" ]; then
24+
echo "job_name=test" >> $GITHUB_OUTPUT
25+
fi
26+
27+
notify-slack:
28+
needs: [test, determine-failed-job]
29+
if: failure()
30+
uses: ./.github/workflows/notify-slack.yaml
31+
with:
32+
context_title: "main branch"
33+
failed_job_name: ${{ needs.determine-failed-job.outputs.job_name }}
34+
secrets: inherit

.github/workflows/on-pull-request.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,28 @@ jobs:
1212

1313
check_formatting:
1414
uses: ./.github/workflows/check_formatting.yaml
15+
16+
determine-failed-job:
17+
needs: [test, check_formatting]
18+
if: failure()
19+
runs-on: ubuntu-latest
20+
outputs:
21+
job_name: ${{ steps.set-job.outputs.job_name }}
22+
steps:
23+
- name: Determine failed job
24+
id: set-job
25+
run: |
26+
if [ "${{ needs.test.result }}" == "failure" ]; then
27+
echo "job_name=test" >> $GITHUB_OUTPUT
28+
elif [ "${{ needs.check_formatting.result }}" == "failure" ]; then
29+
echo "job_name=check_formatting" >> $GITHUB_OUTPUT
30+
fi
31+
32+
notify-slack:
33+
needs: [test, check_formatting, determine-failed-job]
34+
if: failure()
35+
uses: ./.github/workflows/notify-slack.yaml
36+
with:
37+
context_title: "PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}"
38+
failed_job_name: ${{ needs.determine-failed-job.outputs.job_name }}
39+
secrets: inherit

src/flow_test/test.cairo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,3 +3029,8 @@ fn enable_disable_btc_tokens_flow_test() {
30293029
.span();
30303030
assert!(tokens == expected_tokens);
30313031
}
3032+
3033+
#[test]
3034+
fn test_test() {
3035+
panic!("test");
3036+
}

0 commit comments

Comments
 (0)