-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (70 loc) · 2.5 KB
/
notify-slack-end.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Release
on:
workflow_call:
inputs:
message:
required: false
type: string
channel:
required: true
type: string
time:
required: true
type: string
notifyOnlyOnFailure:
required: true
type: boolean
result:
required: true
type: string
secrets:
slackToken:
description: 'A slack bot token, used for sending messages'
required: true
jobs:
notify-start:
name: Notify release end
if: ${{ inputs.notifyOnlyOnFailure == false || inputs.result != 'success' }}
runs-on: ubuntu-latest
steps:
- name: Set environment variables
run: |
echo "time_seconds=$(( $(date +%s) - ${{ inputs.time }} ))" >> "$GITHUB_ENV"
echo "cut_sha=$(cut -c 1-7 <<< ${{ github.sha }})" >> "$GITHUB_ENV"
- name: Parse time
run: |
echo "parsed_time=`printf '%d min and %d sec \n' $(( ${{ env.time_seconds }}%3600/60 )) $((${{ env.time_seconds }}%60))`" >> "$GITHUB_ENV"
- name: Post to a Slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ inputs.channel}}
payload: |
{
"attachments": [
{
"color": "${{ inputs.result == 'success' && '#36a64f' || '#FF0000' }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${{ inputs.message && inputs.message || github.event.repository.name }} - ${{ github.workflow }}* \n <${{ github.event.repository.html_url }}/commit/${{ github.sha }} | ${{ env.cut_sha }}> (<${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} | open>)"
}
},
{
"type": "context",
"elements": [
{
"type": "plain_text",
"text": "${{ inputs.result == 'success' && 'Success' || inputs.result == 'cancelled' && 'Cancelled' || 'Failure' }} after ${{ env.parsed_time }}",
"emoji": true
}
]
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.slackToken }}