From f788c67ca0b62be2b5ef69a1a58f6c7368d29fbf Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Mon, 3 Feb 2025 15:21:56 -0600 Subject: [PATCH] Add 'notify on failure' workflow --- .github/workflows/notify-on-failure.yaml | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/notify-on-failure.yaml diff --git a/.github/workflows/notify-on-failure.yaml b/.github/workflows/notify-on-failure.yaml new file mode 100644 index 0000000..0224aa6 --- /dev/null +++ b/.github/workflows/notify-on-failure.yaml @@ -0,0 +1,43 @@ +--- +name: Notify on Failure + +"on": + workflow_run: + workflows: + - Update mise tool versions + types: [completed] + +permissions: {} + +jobs: + notify: + name: Notify on Failure + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + permissions: + actions: read + contents: read + steps: + - name: Format date + run: | + formatted_date=$(date -d "${{ github.event.workflow_run.run_started_at }}" "+%b %d at %I:%M %p") + echo "FORMATTED_DATE=$formatted_date" >> $GITHUB_ENV + + - name: Send Slack notification + uses: 8398a7/action-slack@v3 + with: + status: custom + # https://api.slack.com/reference/messaging/attachments + custom_payload: | + { + attachments: [{ + pretext: ':x: Workflow triggered by ${{ github.actor }} failed', + title: '${{ github.event.workflow_run.display_title }} #${{github.event.workflow_run.run_number}}', + title_link: '${{ github.event.workflow_run.html_url }}', + footer: '${{ github.repository }} | ${{ env.FORMATTED_DATE }} UTC', + footer_icon: 'https://slack-imgs.com/?c=1&o1=wi32.he32.si&url=https%3A%2F%2Fslack.github.com%2Fstatic%2Fimg%2Ffavicon-neutral.png', + color: 'danger', + }] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_GHA_JOB_STATUS }}