-
Notifications
You must be signed in to change notification settings - Fork 23
44 lines (39 loc) · 1.94 KB
/
on-workflow-end.yaml
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
name: Notify Slack on workflow completion
on:
workflow_run:
workflows:
- "*"
branches:
- main
types: [completed]
jobs:
notify-slack:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get Slack member IDs
id: get-slack-id
if: github.event.workflow_run.conclusion != 'success'
run: |
SLACK_ID=$(jq -r --arg GITHUB_USER "${{ github.actor }}" '.[$GITHUB_USER] // "Unknown"' .github/slack-users.json)
echo "slack_id=$SLACK_ID" >> $GITHUB_OUTPUT
- name: Set job-specific variables
id: set-variables
run: |
if [[ "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then
echo "status_emoji=:white_check_mark:" >> $GITHUB_OUTPUT
echo "view_text=View Success" >> $GITHUB_OUTPUT
echo "footer=Congratulations! 🎉" >> $GITHUB_OUTPUT
else
echo "status_emoji=:fire:" >> $GITHUB_OUTPUT
echo "view_text=View Failure" >> $GITHUB_OUTPUT
echo "footer=Culprit: <@${{ steps.get-slack-id.outputs.slack_id }}>" >> $GITHUB_OUTPUT
fi
- uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ github.event.workflow_run.conclusion }}
notification_title: "${{github.event.workflow_run.name}} - ${{github.event.workflow_run.conclusion}} on ${{github.event.workflow_run.head_branch}} - <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.event.workflow_run.id}}|${{ steps.set-variables.outputs.view_text }}>"
message_format: "${{ steps.set-variables.outputs.status_emoji }} *${{github.event.workflow_run.name}}* ${{github.event.workflow_run.conclusion}} in <${{github.server_url}}/${{github.repository}}/${{github.event.workflow_run.head_branch}}|${{github.repository}}>"
footer: ${{ steps.set-variables.outputs.footer }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}