diff --git a/.github/workflows/discord.yml b/.github/workflows/discord.yml index 05d708a51f..c09eb7677f 100644 --- a/.github/workflows/discord.yml +++ b/.github/workflows/discord.yml @@ -1,4 +1,4 @@ -name: Notify on Workflow Failure +name: Notify on Workflow Failure and Fix on: workflow_run: @@ -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 }}", @@ -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