Skip to content

Commit

Permalink
chore: update discord hook
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Sep 22, 2024
1 parent 0e6574a commit 8c7112d
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions .github/workflows/discord.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Notify on Workflow Failure
name: Notify on Workflow Failure and Fix

on:
workflow_run:
Expand All @@ -8,19 +8,31 @@ on:

jobs:
notify:
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.head_branch == 'main' }}
runs-on: ubuntu-latest
steps:
- name: Send Discord Notification
- name: Check Previous Run Status
id: previous_run
run: |
echo "Checking previous run status..."
PREVIOUS_STATUS=$(gh run list --limit 2 --branch main --workflow "${{ github.event.workflow_run.name }}" --json conclusion --jq '.[1].conclusion')
echo "previous_status=$PREVIOUS_STATUS" >> $GITHUB_ENV
- name: Send Discord Notification on Failure
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"content": "**:x: Workflow Failure Detected on Main Branch**",
"content": "**Workflow Failure Detected on Main Branch** :x:",
"embeds": [
{
"author": {
"name": "GitHub Actions Bot",
"icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"url": "https://github.com/${{ github.repository }}"
},
"title": "Workflow: '${{ github.event.workflow_run.name }}'",
"description": "The workflow **${{ github.event.workflow_run.name }}** has failed on the main branch.",
"url": "${{ github.event.workflow_run.html_url }}",
Expand All @@ -29,3 +41,28 @@ jobs:
]
}' \
$DISCORD_WEBHOOK_URL
- name: Send Discord Notification on Fix
if: ${{ github.event.workflow_run.conclusion == 'success' && env.previous_status == 'failure' }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"content": "**Workflow Fixed on Main Branch** :white_check_mark:",
"embeds": [
{
"author": {
"name": "GitHub Actions Bot",
"icon_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"url": "https://github.com/${{ github.repository }}"
},
"title": "Workflow: '${{ github.event.workflow_run.name }}' Fixed",
"description": "The workflow **${{ github.event.workflow_run.name }}** has been fixed on the main branch.",
"url": "${{ github.event.workflow_run.html_url }}",
"color": 3066993
}
]
}' \
$DISCORD_WEBHOOK_URL

0 comments on commit 8c7112d

Please sign in to comment.