From bd9baf3f1ee244f61cb034d8719a44924f3b4044 Mon Sep 17 00:00:00 2001 From: Alok Gupta Date: Fri, 28 Jun 2024 12:05:45 +0530 Subject: [PATCH 1/2] chore(github-actions) : Fixes notify-failed-actions workflow --- .github/workflows/failed-actions-notify.yml | 50 +++++++++------------ 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/.github/workflows/failed-actions-notify.yml b/.github/workflows/failed-actions-notify.yml index 36751a1f..db2e559e 100644 --- a/.github/workflows/failed-actions-notify.yml +++ b/.github/workflows/failed-actions-notify.yml @@ -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_REMINDER }} + + - 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 }}" \ No newline at end of file From 61c99db69ea670e1d420e3c3a513e3f5770a7685 Mon Sep 17 00:00:00 2001 From: Benjamin Granados <40007659+benjagm@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:18:47 +0200 Subject: [PATCH 2/2] Update failed-actions-notify.yml to change webhook name --- .github/workflows/failed-actions-notify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/failed-actions-notify.yml b/.github/workflows/failed-actions-notify.yml index db2e559e..54ab2644 100644 --- a/.github/workflows/failed-actions-notify.yml +++ b/.github/workflows/failed-actions-notify.yml @@ -28,10 +28,10 @@ jobs: 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_REMINDER }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_WORKFLOW_NOTIF }} - name: Check Slack Notification Status if: failure() run: | echo "Failed to send Slack notification" - echo "Workflow Run ID: ${{ github.event.workflow_run.id }}" \ No newline at end of file + echo "Workflow Run ID: ${{ github.event.workflow_run.id }}"