-
Notifications
You must be signed in to change notification settings - Fork 3
80 lines (70 loc) · 2.43 KB
/
slack-post-notification.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
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
# **what?**
# Post notification to Slack channel
#
# Inputs:
# status: Workflow status (Expected values: success, failure, cancelled, warnings, skipped)
# notify_when: Specify on which status a slack notification is sent (By default: notification will be sent for all statuses)
# notification_title: Specify on the notification message title (By default: Release Process Status)
#
# **why?**
# Reusable and configured workflow to post notification to Slack
#
# **when?**
# Depends on configuration
name: Post Slack Notification
on:
workflow_call:
inputs:
status:
type: string
required: true
notify_when:
default: "success,failure,cancelled,warnings,skipped"
required: false
type: string
notification_title:
default: "Release Process Status"
required: false
type: string
secrets:
SLACK_WEBHOOK_URL:
description: Slack app webhook url
required: true
permissions:
contents: read
defaults:
run:
shell: bash
env:
NOTIFICATION_PREFIX: "[Slack Notification]"
jobs:
log-inputs:
runs-on: ubuntu-latest
steps:
- name: "[DEBUG] Print Variables"
run: |
# WORKFLOW INPUTS
echo "Status: ${{ inputs.status }}"
echo "Notify when: ${{ inputs.notify_when }}"
echo "Notification title: ${{ inputs.notification_title }}"
# ENVIRONMENT VARIABLES
echo "Notification prefix: ${{ env.NOTIFICATION_PREFIX }}"
slack-post-notification:
runs-on: ubuntu-latest
steps:
- name: "Post Slack Notification"
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ inputs.status }}
token: ${{ secrets.GITHUB_TOKEN }}
notification_title: ${{ inputs.notification_title }}
message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}@{branch}> on <{commit_url}|{commit_sha}>"
footer: "<{run_url}|View Run>"
notify_when: ${{ inputs.notify_when }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: "[Notification] Post Slack Notification"
run: |
title="Notification successfully sent"
message="The '${{ inputs.notification_title }}' notification sent to Slack. Overall workflow status: ${{ inputs.status }}."
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"