Repository navigation
60 lines (56 loc) · 1.77 KB
/
Copy pathnotify-discord.yml
File metadata and controls
60 lines (56 loc) · 1.77 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
# Discord webhook notification structure (https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html)
# To get the webhook url: On A channel> 'Edit Channel' > 'Integrations' > 'Webhooks' > 'New Webhook' > 'Copy Webhook Url'
name: Notify on Discord
on:
workflow_call:
inputs:
bot-username:
required: false
type: string
default: 'CI Bot'
notification-content:
required: false
type: string
default: 'Some content. Required. Up to 2000 characters'
embed-title:
required: false
type: string
default: 'A workflow needs your attention !'
embed-url:
required: false
type: string
default: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
secrets:
DISCORD_WEBHOOK:
required: true
jobs:
notify-discord:
runs-on: ubuntu-latest
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
steps:
- name: Has webhook url
run: |
echo "has_webhook_url=${DISCORD_WEBHOOK:+true}" >> $GITHUB_ENV
echo ${{ env.has_webhook_url }}
- name: Prepare payload
if: env.has_webhook_url == 'true'
run: >-
(jq -r '.' <<< '
{
"username": "${{ inputs.bot-username }}",
"content": "${{ inputs.notification-content }}",
"embeds": [{
"title": "${{ inputs.embed-title }}",
"url": "${{ inputs.embed-url }}"
}]
}'
) > payload
- name: Send notification
if: env.has_webhook_url == 'true'
run: >-
curl
--header "Content-Type:application/json"
--request POST
--data @payload
${{ secrets.DISCORD_WEBHOOK }}