workflow-failure #1521
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: workflow-failure | |
on: | |
workflow_run: | |
workflows: | |
- automerge-nightly-pr | |
- create-cli-release | |
- create-github-release | |
- make-pr-for-nightly | |
- make-pr-for-release | |
- promote | |
- promote-nightly-to-rc | |
- promote-rc-to-latest | |
- update-docker-node-version | |
- get-signed-installers-from-stampy | |
types: | |
- completed | |
# There seems to be an issue where the workflow_run is sometimes missing from the event | |
# For context: "github.event.workflow_run.conclusion" | |
# Using a workaround that was found here: https://github.com/community/community/discussions/21090#discussioncomment-3226271 | |
jobs: | |
get-workflow-conclusion: | |
name: Lookup conclusion of workflow_run event | |
runs-on: ubuntu-latest | |
outputs: | |
conclusion: ${{ fromJson(steps.get_conclusion.outputs.data).conclusion }} | |
steps: | |
- name: Get Workflow Run | |
uses: octokit/[email protected] | |
id: get_conclusion | |
with: | |
route: GET /repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }} | |
failure-notify: | |
runs-on: ubuntu-latest | |
needs: [get-workflow-conclusion] | |
if: ${{ needs.get-workflow-conclusion.outputs.conclusion == 'failure' }} | |
steps: | |
- name: Announce Failure | |
id: slack | |
uses: slackapi/[email protected] | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.CLI_ALERTS_SLACK_WEBHOOK }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | |
with: | |
# Payload can be visually tested here: https://app.slack.com/block-kit-builder/T01GST6QY0G#%7B%22blocks%22:%5B%5D%7D | |
# Only copy over the "blocks" array to the Block Kit Builder | |
payload: | | |
{ | |
"text": "Workflow \"${{ github.event.workflow_run.name }}\" failed in ${{ github.event.workflow_run.repository.name }}", | |
"blocks": [ | |
{ | |
"type": "header", | |
"text": { | |
"type": "plain_text", | |
"text": ":bh-alert: Workflow \"${{ github.event.workflow_run.name }}\" failed in ${{ github.event.workflow_run.repository.name }} :bh-alert:" | |
} | |
}, | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "*Repo:* ${{ github.event.workflow_run.repository.html_url }}\n*Workflow name:* `${{ github.event.workflow_run.name }}`\n*Job url:* ${{ github.event.workflow_run.html_url }}" | |
} | |
} | |
] | |
} |