Skip to content

Commit acffae5

Browse files
committed
More Better
1 parent 0a32cde commit acffae5

File tree

2 files changed

+93
-28
lines changed

2 files changed

+93
-28
lines changed

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

+15-11
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]($ref_link) completed with *$conclusion*"
5559
5660
echo "message=${message}" >> $GITHUB_OUTPUT
5761
echo "workflow_id=${workflow_id}" >> $GITHUB_OUTPUT
@@ -76,7 +80,7 @@ runs:
7680
- type: button
7781
text:
7882
type: plain_text
79-
text: "View Workflow (${{ steps.context.outputs.workflow_id }})"
83+
text: "Workflow - ${{ steps.context.outputs.workflow_id }}"
8084
emoji: true
8185
value: workflow_url
8286
url: "${{ steps.context.outputs.workflow_url }}"

.github/workflows/default_completed.yml

+78-17
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,96 @@ 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+
html_url="${{ github.event.workflow_run.html_url}}"
34+
actor="${{ github.event.workflow_run.triggering_actor.login }}"
35+
conclusion="${{ github.event.workflow_run.conclusion }}"
36+
37+
commit_short=$(echo "$sha" | cut -c1-7)
38+
39+
ref="$branch ($commit_short) $title"
40+
event="${{ github.event.workflow_run.event}}"
41+
repo_url="${{ github.server_url }}/${{ github.repository }}"
42+
43+
if [[ "$event" == "push" ]]; then
44+
env="dev"
45+
ref_link="$repo_url/commit/$commit_long"
46+
elif [[ "$event" == "release" ]]; then
47+
env="production"
48+
ref_link="$repo_url/releases/tag/$head_branch"
49+
fi
50+
51+
if [[ "$conclusion" == "success" ]]; then
52+
emoji=":white_check_mark:"
53+
else
54+
emoji=":x:"
55+
fi
56+
57+
echo "emoji=$emoji" >> $GITHUB_OUTPUT
58+
echo "actor=$actor" >> $GITHUB_OUTPUT
59+
echo "event=$event" >> $GITHUB_OUTPUT
60+
echo "conclusion=$conclusion" >> $GITHUB_OUTPUT
61+
echo "env=$env" >> $GITHUB_OUTPUT
62+
echo "ref=$ref" >> $GITHUB_OUTPUT
63+
echo "ref_link=$ref_link" >> $GITHUB_OUTPUT
64+
echo "workflow_id=$workflow_id" >> $GITHUB_OUTPUT
65+
echo "workflow_url=$workflow_url" >> $GITHUB_OUTPUT
66+
cat $GITHUB_OUTPUT
1667
1768
slack_notification:
1869
needs: context
1970
strategy:
2071
matrix:
2172
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 }}
73+
# The real message based on the context of the workflow
74+
- emoji: ${{ needs.context.outputs.emoji }}
75+
actor: ${{ needs.context.outputs.actor }}
76+
event: ${{ needs.context.outputs.event }}
77+
conclusion: ${{ needs.context.outputs.conclusion }}
78+
env: ${{ needs.context.outputs.env }}
79+
ref: ${{ needs.context.outputs.ref }}
80+
ref_link: ${{ needs.context.outputs.ref_link }}
81+
workflow_id: ${{ github.event.workflow_run.id }}
82+
workflow_url: ${{ github.event.workflow_run.html_url }}
83+
# No Emoji
84+
- emoji: ''
85+
actor: ${{ needs.context.outputs.actor }}
86+
event: ${{ needs.context.outputs.event }}
87+
conclusion: ${{ needs.context.outputs.conclusion }}
88+
env: ${{ needs.context.outputs.env }}
89+
ref: ${{ needs.context.outputs.ref }}
90+
ref_link: ${{ needs.context.outputs.ref_link }}
91+
workflow_id: ${{ github.event.workflow_run.id }}
92+
workflow_url: ${{ github.event.workflow_run.html_url }}
93+
# Custom Emoji and ref
94+
- emoji: ':party_blob:'
95+
actor: ${{ github.event.workflow_run.actor.login }}
2896
event: 'push'
2997
conclusion: 'failure'
3098
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
99+
ref: 'It is time to party!'
100+
ref_link: ${{ needs.context.outputs.ref_link }}
101+
workflow_id: ${{ github.event.workflow_run.id }}
102+
workflow_url: ${{ github.event.workflow_run.html_url }}
42103

43104
runs-on: ubuntu-latest
44105
steps:

0 commit comments

Comments
 (0)