forked from exohood/exohood-slack-notify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
59 lines (51 loc) · 1.47 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# action.yml
name: 'Notify slack'
description: 'Notify slack from github action'
inputs:
text:
description: 'Message to send'
required: true
default: 'Ping'
channel:
description: 'Channel to notify, e.g. #my-channel'
required: true
token:
description: 'Slack API token'
required: true
default: 'NO_TOKEN'
outputs:
success:
description: 'Whether request was successful'
value: ${{ steps.notify.outputs.success }}
runs:
using: "composite"
steps:
- id: install
shell: bash
run: sudo apt-get install -y jq
- id: notify
shell: bash
env:
TOKEN: ${{ inputs.token }}
TEXT: ${{ inputs.text }}
run: |
echo "Notifying ${{ inputs.channel }} via Slack..."
echo "TEXT is:"
echo $TEXT
JSON='{
"text": ":github: ${{ inputs.text }}",
"channel": "${{ inputs.channel }}",
"as_user": "True"
}'
RESULT=$( curl --location --request POST 'https://slack.com/api/chat.postMessage' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TOKEN" \
--data-raw "${JSON}" )
SUCCESS=$( echo $RESULT | jq -r '.ok' )
echo "::set-output name=success::$(echo $SUCCESS)"
if [ $SUCCESS != 'true' ]; then
echo "Error when making request"
echo $RESULT
exit 1
fi
echo "Notified successfully"