-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
41 lines (41 loc) · 2.05 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: "Notify on failure"
description: "Send a message to Slack when a job fails"
inputs:
SLACK_WEBHOOK_URL:
description: "url that tells Slack which channel should receive this notification."
required: true
runs:
using: "composite"
steps:
- name: Get commit or title and url
## Full commit message (title and body) create an invalid JSON payload
run: |
echo "commit_title=$(git show -s --format=%s)" | tr -d '\t"\' >> "$GITHUB_ENV"
echo "commit_sha=$(git show -s --format=%H)" >> "$GITHUB_ENV"
shell: bash
- name: Send failure to Slack
# Third-party action, pin to commit SHA!
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions
uses: slackapi/slack-github-action@37ebaef184d7626c5f204ab8d3baff4262dd30f0
env:
SLACK_WEBHOOK_URL: ${{ inputs.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"text": "<!here> <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.job }}> run failed for \"<${{ format('{0}/{1}/commit/{2}', github.server_url, github.repository, env.commit_sha) }}|${{ env.commit_title }}>\" on <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.repository }}> :fire:",
"attachments": [
{
"color": "#ff0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Workflow*: ${{ github.workflow }}\n*Failed job*: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.job }}>\n*Commit:* <${{ format('{0}/{1}/commit/{2}', github.server_url, github.repository, env.commit_sha) }}|${{ env.commit_title }}>\n*Branch:* ${{ github.ref }}\n*Author:* ${{ github.triggering_actor }}"
}
}
]
}
]
}