-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathaction.yml
More file actions
108 lines (96 loc) · 3.57 KB
/
Copy pathaction.yml
File metadata and controls
108 lines (96 loc) · 3.57 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Slack Workflow Notification
description: Send a message to Slack when a workflow completes
inputs:
slack_token:
description: Slack token
required: true
slack_channel:
description: Slack channel
required: true
conclusion:
description: The conclusion of the workflow
required: true
text:
description: The text to display in the main message
required: true
text_link:
description: Optional link for main text
required: false
default: "null"
dry_run:
description: 'Print message info'
required: false
default: 'false'
context:
description: A list of contextual text blocks (text) to display after the main message
required: false
default: "null"
links:
description: A list of links (text:url) to display after the main message
required: false
default: "null"
separator:
description: Optional override the separator for context/link blocks
required: false
default: '|'
runs:
using: composite
steps:
- name: Context
id: context
shell: bash
env:
conclusion: ${{ inputs.conclusion }}
text_content: ${{ inputs.text }}
text_link: ${{ inputs.text_link }}
context: ${{ inputs.context }}
links: ${{ inputs.links }}
separator: ${{ inputs.separator }}
run: |
emoji=":github-actions-autolink-reference:"
if [[ "${conclusion}" == "success" ]]; then
emoji=":github-actions-success:"
elif [[ "${conclusion}" == "failure" ]]; then
emoji=":github-actions-failure:"
elif [[ "${conclusion}" == "cancelled" ]]; then
emoji=":github-actions-cancelled:"
elif [[ "${conclusion}" == "skipped" ]]; then
emoji=":github-actions-skip:"
fi
if [ "${text_link}" != "null" ]; then
text_content="<${text_link}|${text_content}>"
fi
text="${emoji} ${text_content}"
links_arr="[]"
context_arr="[]"
if [ -n "${links}" ] && [ "${links}" != "null" ]; then
# Convert JSON to array of slack compliant markdown links
links_arr=$(echo "${links}" | jq 'to_entries | map("<\(.value)|\(.key)>")')
fi
if [ -n "${context}" ] && [ "${context}" != "null" ]; then
# Convert JSON to array of slack compliant markdown text
context_arr=$(echo "${context}" | jq 'to_entries | map("*\(.key)*: \(.value)")')
fi
# Combine the two arrays into a separated text list
combined_blocks=$(echo "${context_arr}" "${links_arr}" | jq -rs 'add')
# Join arrays with separator into a single value
blocks=$(echo "${combined_blocks}" | jq -r --arg s "${separator}" 'join(" \($s) ")')
if [ -n "${blocks}" ]; then
text="${text} | ${blocks}"
fi
echo "text=${text}" >> "${GITHUB_OUTPUT}"
cat "${GITHUB_OUTPUT}"
- name: Notify Slack
# This action uses another action defined in the same repository.
# Github action does not support dynamic version selection so we have to pick
# a single version. Pinning to a commit hash is not a great idea because we have to
#manage multiple cascading version updates for the action and this file cannot reference
# it's own git hash.
uses: mozilla/addons/.github/actions/slack@main # zizmor: ignore[unpinned-uses]
with:
slack_token: ${{ inputs.slack_token }}
method: chat.postMessage
payload: |
channel: "${{ inputs.slack_channel }}"
text: ${{ toJSON(steps.context.outputs.text) }}
dry_run: ${{ inputs.dry_run }}