Skip to content

Commit 523d586

Browse files
aialokbenjagm
andauthored
chore(github-actions) : Fixes notify-failed-actions workflow (#772)
* chore(github-actions) : Fixes notify-failed-actions workflow * Update failed-actions-notify.yml to change webhook name --------- Co-authored-by: Benjamin Granados <40007659+benjagm@users.noreply.github.com>
1 parent f88806d commit 523d586

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

.github/workflows/failed-actions-notify.yml

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,30 @@ on:
88
branches:
99
- main
1010

11+
permissions:
12+
actions: read
13+
1114
jobs:
12-
notify-slack:
15+
on-failure:
1316
runs-on: ubuntu-latest
14-
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
17+
if: |
18+
(github.event.workflow_run.conclusion == 'failure' ||
19+
github.event.workflow_run.conclusion == 'timed_out') &&
20+
github.event.workflow_run.name != 'Slack Notifications for Failed GitHub Actions'
21+
timeout-minutes: 10
1522
steps:
16-
- name: Check out repository
17-
uses: actions/checkout@v4
18-
19-
- name: Send Slack notification
23+
- name: Send Slack Notification
24+
uses: ravsamhq/notify-slack-action@v2
25+
with:
26+
status: ${{ github.event.workflow_run.conclusion }}
27+
notification_title: " ${{github.event.workflow_run.name}} - ${{github.event.workflow_run.conclusion}} on ${{github.event.workflow_run.head_branch}} - <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|View Failure>"
28+
message_format: ":fire: *${{github.event.workflow_run.name}}* ${{github.event.workflow_run.conclusion}} in <${{github.server_url}}/${{github.repository}}/${{github.event.workflow_run.head_branch}}|${{github.repository}}>"
29+
footer: "Linked Repo <${{github.server_url}}/${{github.repository}}|${{github.repository}}> | <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|View Failure>"
30+
env:
31+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_WORKFLOW_NOTIF }}
32+
33+
- name: Check Slack Notification Status
2034
if: failure()
2135
run: |
22-
const fetch = require('node-fetch');
23-
24-
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
25-
const context = JSON.parse(process.env.GITHUB_CONTEXT);
26-
27-
const slackMessage = {
28-
channel: '#github',
29-
issue: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
30-
status: context.jobStatus,
31-
text: `GitHub Actions workflow failed: ${context.workflow}`
32-
};
33-
34-
await fetch(SLACK_WEBHOOK_URL, {
35-
method: 'POST',
36-
headers: {
37-
'Content-Type': 'application/json',
38-
},
39-
body: JSON.stringify(slackMessage),
40-
});
41-
env:
42-
SLACK_WEBHOOK_URL: ${{ vars.SLACK_WEBHOOK_FAIL_ACTIONS }}
43-
GITHUB_CONTEXT: ${{ toJson(github) }}
36+
echo "Failed to send Slack notification"
37+
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"

0 commit comments

Comments
 (0)