Skip to content

Commit

Permalink
chore(github-actions) : Fixes notify-failed-actions workflow (#772)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
aialok and benjagm authored Jul 16, 2024
1 parent f88806d commit 523d586
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions .github/workflows/failed-actions-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,30 @@ on:
branches:
- main

permissions:
actions: read

jobs:
notify-slack:
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
if: |
(github.event.workflow_run.conclusion == 'failure' ||
github.event.workflow_run.conclusion == 'timed_out') &&
github.event.workflow_run.name != 'Slack Notifications for Failed GitHub Actions'
timeout-minutes: 10
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Send Slack notification
- name: Send Slack Notification
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ github.event.workflow_run.conclusion }}
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>"
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}}>"
footer: "Linked Repo <${{github.server_url}}/${{github.repository}}|${{github.repository}}> | <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|View Failure>"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_WORKFLOW_NOTIF }}

- name: Check Slack Notification Status
if: failure()
run: |
const fetch = require('node-fetch');
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;
const context = JSON.parse(process.env.GITHUB_CONTEXT);
const slackMessage = {
channel: '#github',
issue: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
status: context.jobStatus,
text: `GitHub Actions workflow failed: ${context.workflow}`
};
await fetch(SLACK_WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(slackMessage),
});
env:
SLACK_WEBHOOK_URL: ${{ vars.SLACK_WEBHOOK_FAIL_ACTIONS }}
GITHUB_CONTEXT: ${{ toJson(github) }}
echo "Failed to send Slack notification"
echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"

0 comments on commit 523d586

Please sign in to comment.