Skip to content

Send Error to Slack #95

Send Error to Slack

Send Error to Slack #95

Workflow file for this run

name: Send Error to Slack
on:
workflow_run:
workflows: [ Test Pipeline for Merged PR ]
types:
- completed
jobs:
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- uses: actions/checkout@v3
- name: Get error log
id: error_log
run: |
ERROR_LOG="$(gh run view ${{ github.event.workflow_run.id }} --log-failed | tail -n 7 | rev | cut -f 1 | rev | sed -r 's/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g' | sed -z 's/\n/\\n/g' | sed 's/\t/ /g')"
echo "ERROR_LOG=$ERROR_LOG" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify error to slack
uses: slackapi/[email protected]
with:
payload: |
{
"text": "${{ github.event.workflow.name }} failed",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":rotating_light:PIPELINE FAILED",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ github.event.workflow.name }} failed"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Error log*\n```${{ steps.error_log.outputs.ERROR_LOG }}```\nCheck full logs in ${{ github.event.workflow_run.html_url }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK