-
-
Notifications
You must be signed in to change notification settings - Fork 395
38 lines (36 loc) · 1.69 KB
/
Copy pathdiscord-notification.yml
File metadata and controls
38 lines (36 loc) · 1.69 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
name: Discord Notification
on:
workflow_run:
workflows: ['CI']
types: [completed]
jobs:
send-discord-message:
# 'skipped' means the `if: ` condition wasn't fulfilled
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
runs-on: ubuntu-latest
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
steps:
- name: Push the notification using Discord webhook
# Skip pull requests. (This condition cannot be moved to the `if:` above because the secret isn't available there.)
if: env.DISCORD_WEBHOOK != ''
env:
# 🟢 has poor compatibility: https://www.unicompat.com/1F7E2
CI_STATUS: ${{ github.event.workflow_run.conclusion == 'success' && '✅' || github.event.workflow_run.conclusion == 'failure' && '🔴' || github.event.workflow_run.conclusion }}
REPO_NAME: ${{ github.event.repository.name }}
GIT_BRANCH: ${{ github.event.workflow_run.head_branch }}
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
WORKFLOW_URL: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.html_url || '' }}
# Playground: https://gist.github.com/brillout/da1ab713bda6e3c0d2ad909c1a4e80f2
run: |
curl \
-i \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST \
--data "{\"content\":\"$CI_STATUS $REPO_NAME $WORKFLOW_NAME $GIT_BRANCH $WORKFLOW_URL\",\"username\":\"GitHub\",\"avatar_url\":\"https://i.imgur.com/OOtUMJD.png\"}" \
$DISCORD_WEBHOOK
- name: Debug/inspect
env:
EVENT: ${{ toJSON( github.event ) }}
run: echo $EVENT