-
Notifications
You must be signed in to change notification settings - Fork 15
73 lines (66 loc) · 2.25 KB
/
Copy pathnotify-discord-on-release.yml
File metadata and controls
73 lines (66 loc) · 2.25 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
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Notify Discord on Release or Tag
on:
release:
types: [published]
push:
tags:
- '*'
jobs:
notify-discord:
runs-on: ubuntu-latest
steps:
- name: Send release/tag info to Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
EVENT_NAME: ${{ github.event_name }}
RELEASE_TITLE: ${{ github.event.release.name }}
RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}
RELEASE_NOTE: ${{ github.event.release.body }}
PUSH_TAG_NAME: ${{ github.ref_name }}
REPO: ${{ github.repository }}
ACTOR: ${{ github.actor }}
run: |
if [ "$EVENT_NAME" = "release" ]; then
TITLE="${RELEASE_TITLE:-No release title}"
TAG="${RELEASE_TAG_NAME:-Unknown tag}"
NOTE="${RELEASE_NOTE}"
EVENT_LABEL="GitHub Release"
else
TITLE="Tag created"
TAG="${PUSH_TAG_NAME:-Unknown tag}"
NOTE="A new tag was pushed without creating a GitHub Release."
EVENT_LABEL="Git Tag"
fi
if [ -z "$NOTE" ]; then
NOTE="(empty)"
fi
if [ ${#NOTE} -gt 1000 ]; then
NOTE="${NOTE:0:1000}..."
fi
jq -n \
--arg event "$EVENT_LABEL" \
--arg title "$TITLE" \
--arg tag "$TAG" \
--arg note "$NOTE" \
--arg repo "$REPO" \
--arg actor "$ACTOR" \
'{
embeds: [
{
title: $event,
fields: [
{ "name": "Repository", "value": $repo, "inline": false },
{ "name": "Triggered By", "value": $actor, "inline": false },
{ "name": "Title", "value": $title, "inline": false },
{ "name": "Tag Name", "value": $tag, "inline": false },
{ "name": "Note", "value": $note, "inline": false }
]
}
]
}' > payload.json
cat payload.json
curl --fail-with-body \
-H "Content-Type: application/json" \
-X POST \
-d @payload.json \
"$DISCORD_WEBHOOK_URL"