-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
49 lines (49 loc) · 1.84 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
name: 'Slack Post Message Action'
description: 'GitHub Action that posts a message to a Slack channel'
inputs:
token:
description: "The Slack auth token. This is only required if environment variable SLACK_BOT_TOKEN is not set."
required: false
channel:
description: "The channel name to post to"
required: true
thread_ts:
description: "The timestamp ID of the parent message to reply to"
required: false
text:
description: "The message text to post"
required: true
unfurl_links:
description: "Whether links in the message should be unfurled"
type: boolean
default: true
outputs:
ts:
description: "The timestamp ID of the message that was just posted"
value: ${{steps.slack-post-message.outputs.ts}}
branding:
icon: 'tag'
color: 'blue'
runs:
using: 'composite'
steps:
- name: Validate required inputs
shell: bash
run: |
[[ "${{ inputs.channel }}" ]] || { echo "required input 'channel' not specified" ; exit 1; }
[[ "${{ inputs.text }}" ]] || { echo "required input 'text' not specified" ; exit 1; }
- name: POST to chat.postMessage API
id: slack-post-message
shell: bash
run: |
response=$(curl --fail-with-body --silent --show-error \
--request POST \
--header "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN || inputs.token }}" \
--header "Content-Type: application/json; charset=utf-8" \
--url https://slack.com/api/chat.postMessage \
--data $'{"channel": "${{ inputs.channel }}", "thread_ts": "${{ inputs.thread_ts }}", "unfurl_links": ${{ inputs.unfurl_links }}, "text": "${{ inputs.text }}"}' \
)
echo "Slack message API response:\n$response"
ts=$(echo "$response" | jq --raw-output '.ts')
echo "Setting ts output to $ts"
echo "ts=$ts" >> $GITHUB_OUTPUT