Skip to content

Commit 0505361

Browse files
committed
More Better
1 parent 0a32cde commit 0505361

File tree

2 files changed

+97
-37
lines changed

2 files changed

+97
-37
lines changed

.github/actions/slack-workflow-notification/action.yml

+14-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
slack_channel:
99
description: 'Slack channel'
1010
required: true
11+
emoji:
12+
description: The emoji to use in the message
13+
required: false
14+
default: ":white_check_mark:"
1115
actor:
1216
description: The user who triggered the workflow
1317
required: true
@@ -23,9 +27,15 @@ inputs:
2327
ref:
2428
description: The artifact reference (commit, tag, etc) of the workflow
2529
required: true
30+
ref_link:
31+
description: The link to the artifact reference (commit, tag, etc) of the workflow
32+
required: true
2633
workflow_id:
2734
description: The ID of the workflow that is being notified about
2835
required: true
36+
workflow_url:
37+
description: The URL of the workflow that is being notified about
38+
required: true
2939

3040

3141
runs:
@@ -35,23 +45,17 @@ runs:
3545
id: context
3646
shell: bash
3747
run: |
48+
emoji="${{ inputs.emoji }}"
3849
actor="${{ inputs.actor }}"
3950
event="${{ inputs.event }}"
4051
conclusion="${{ inputs.conclusion }}"
4152
env="${{ inputs.env }}"
4253
ref="${{ inputs.ref }}"
43-
44-
if [[ "$conclusion" == "success" ]]; then
45-
emoji=":white_check_mark:"
46-
else
47-
emoji=":x:"
48-
fi
49-
54+
ref_link="${{ inputs.ref_link }}"
5055
workflow_id="${{ inputs.workflow_id }}"
51-
repo_url="${{ github.server_url }}/${{ github.repository }}"
52-
workflow_url="$repo_url/actions/runs/$workflow_id"
56+
workflow_url="${{ inputs.workflow_url }}"
5357
54-
message="$emoji [$env] $actor *$event* ($ref) completed with *$conclusion* $emoji"
58+
message="${emoji} [*${env}*] _${actor}_ *${event}* <${ref_link}|${ref}> completed with *${conclusion}* (Workflow ID: <${workflow_url}|${workflow_id}>)"
5559
5660
echo "message=${message}" >> $GITHUB_OUTPUT
5761
echo "workflow_id=${workflow_id}" >> $GITHUB_OUTPUT
@@ -71,12 +75,3 @@ runs:
7175
text:
7276
type: mrkdwn
7377
text: "${{ steps.context.outputs.message }}"
74-
- type: actions
75-
elements:
76-
- type: button
77-
text:
78-
type: plain_text
79-
text: "View Workflow (${{ steps.context.outputs.workflow_id }})"
80-
emoji: true
81-
value: workflow_url
82-
url: "${{ steps.context.outputs.workflow_url }}"

.github/workflows/default_completed.yml

+83-18
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,97 @@ jobs:
1010
context:
1111
runs-on: ubuntu-latest
1212

13+
outputs:
14+
emoji: ${{ steps.ref.outputs.emoji }}
15+
actor: ${{ steps.ref.outputs.actor }}
16+
event: ${{ steps.ref.outputs.event }}
17+
env: ${{ steps.ref.outputs.env }}
18+
conclusion: ${{ steps.ref.outputs.conclusion }}
19+
ref: ${{ steps.ref.outputs.ref }}
20+
ref_link: ${{ steps.ref.outputs.ref_link }}
21+
workflow_id: ${{ steps.ref.outputs.workflow_id }}
22+
workflow_url: ${{ steps.ref.outputs.workflow_url }}
23+
1324
steps:
1425
- uses: actions/checkout@v4
1526
- uses: ./.github/actions/context
27+
- id: ref
28+
shell: bash
29+
run: |
30+
branch="${{ github.event.workflow_run.head_branch }}"
31+
title="${{ github.event.workflow_run.display_title }}"
32+
sha="${{ github.event.workflow_run.head_sha }}"
33+
workflow_id="${{ github.event.workflow_run.id }}"
34+
workflow_url="${{ github.event.workflow_run.html_url}}"
35+
actor="${{ github.event.workflow_run.triggering_actor.login }}"
36+
conclusion="${{ github.event.workflow_run.conclusion }}"
37+
38+
commit_short=$(echo "$sha" | cut -c1-7)
39+
40+
ref="$branch ($commit_short) $title"
41+
event="${{ github.event.workflow_run.event}}"
42+
repo_url="${{ github.server_url }}/${{ github.repository }}"
43+
44+
if [[ "$event" == "push" ]]; then
45+
env="dev"
46+
ref_link="$repo_url/commit/$sha"
47+
elif [[ "$event" == "release" ]]; then
48+
env="production"
49+
ref_link="$repo_url/releases/tag/$head_branch"
50+
fi
51+
52+
if [[ "$conclusion" == "success" ]]; then
53+
emoji=":white_check_mark:"
54+
else
55+
emoji=":x:"
56+
fi
57+
58+
echo "emoji=$emoji" >> $GITHUB_OUTPUT
59+
echo "actor=$actor" >> $GITHUB_OUTPUT
60+
echo "event=$event" >> $GITHUB_OUTPUT
61+
echo "conclusion=$conclusion" >> $GITHUB_OUTPUT
62+
echo "env=$env" >> $GITHUB_OUTPUT
63+
echo "ref=$ref" >> $GITHUB_OUTPUT
64+
echo "ref_link=$ref_link" >> $GITHUB_OUTPUT
65+
echo "workflow_id=$workflow_id" >> $GITHUB_OUTPUT
66+
echo "workflow_url=$workflow_url" >> $GITHUB_OUTPUT
67+
cat $GITHUB_OUTPUT
1668
1769
slack_notification:
1870
needs: context
1971
strategy:
2072
matrix:
2173
include:
22-
- actor: ${{ github.event.workflow_run.actor.login }}
23-
event: 'push'
24-
conclusion: 'success'
25-
env: 'dev'
26-
ref: ${{ github.event.workflow_run.head_commit.id }}
27-
- actor: ${{ github.event.workflow_run.actor.login }}
74+
# The real message based on the context of the workflow
75+
- emoji: ${{ needs.context.outputs.emoji }}
76+
actor: ${{ needs.context.outputs.actor }}
77+
event: ${{ needs.context.outputs.event }}
78+
conclusion: ${{ needs.context.outputs.conclusion }}
79+
env: ${{ needs.context.outputs.env }}
80+
ref: ${{ needs.context.outputs.ref }}
81+
ref_link: ${{ needs.context.outputs.ref_link }}
82+
workflow_id: ${{ needs.context.outputs.workflow_id }}
83+
workflow_url: ${{ needs.context.outputs.workflow_url }}
84+
# No Emoji
85+
- emoji: ''
86+
actor: ${{ needs.context.outputs.actor }}
87+
event: ${{ needs.context.outputs.event }}
88+
conclusion: ${{ needs.context.outputs.conclusion }}
89+
env: ${{ needs.context.outputs.env }}
90+
ref: ${{ needs.context.outputs.ref }}
91+
ref_link: ${{ needs.context.outputs.ref_link }}
92+
workflow_id: ${{ needs.context.outputs.workflow_id }}
93+
workflow_url: ${{ needs.context.outputs.workflow_url }}
94+
# Custom Emoji and ref
95+
- emoji: ':party_blob:'
96+
actor: ${{ github.event.workflow_run.actor.login }}
2897
event: 'push'
2998
conclusion: 'failure'
3099
env: 'dev'
31-
ref: ${{ github.event.workflow_run.head_commit.id }}
32-
- actor: ${{ github.event.workflow_run.actor.login }}
33-
event: 'release'
34-
conclusion: 'success'
35-
env: 'production'
36-
ref: 2025.01.01
37-
- actor: ${{ github.event.workflow_run.actor.login }}
38-
event: 'release'
39-
conclusion: 'failure'
40-
env: 'production'
41-
ref: 2025.01.01
100+
ref: 'It is time to party!'
101+
ref_link: ${{ needs.context.outputs.ref_link }}
102+
workflow_id: ${{ needs.context.outputs.workflow_id }}
103+
workflow_url: ${{ needs.context.outputs.workflow_url }}
42104

43105
runs-on: ubuntu-latest
44106
steps:
@@ -47,9 +109,12 @@ jobs:
47109
with:
48110
slack_token: ${{ secrets.SLACK_TOKEN }}
49111
slack_channel: ${{ secrets.SLACK_ADDONS_PRODUCTION_CHANNEL }}
112+
emoji: ${{ matrix.emoji }}
50113
actor: ${{ matrix.actor }}
51114
event: ${{ matrix.event }}
52115
conclusion: ${{ matrix.conclusion }}
53116
env: ${{ matrix.env }}
54117
ref: ${{ matrix.ref }}
55-
workflow_id: ${{ github.event.workflow_run.id }}
118+
ref_link: ${{ matrix.ref_link }}
119+
workflow_id: ${{ matrix.workflow_id }}
120+
workflow_url: ${{ matrix.workflow_url }}

0 commit comments

Comments
 (0)