-
Notifications
You must be signed in to change notification settings - Fork 15
64 lines (59 loc) · 13.9 KB
/
Copy pathnotify-discord-on-release.yml
File metadata and controls
64 lines (59 loc) · 13.9 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
# .github/workflows/notify-discord-release.yml
name: Notify Discord on Release
on:
release:
types: [published]
jobs:
notify-discord:
runs-on: ubuntu-latest
steps:
- name: Send release info to Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
run: |
# Escape special characters in release notes
SAFE_NOTES="${{ github.event.release.body }}"
SAFE_NOTES="${SAFE_NOTES//\"/\\\"}"
SAFE_NOTES="${SAFE_NOTES//$'\n'/\\n}"
# Create timestamp
CREATED_AT="${{ github.event.release.created_at }}"
CREATED_AT="${CREATED_AT//T/ }"
CREATED_AT="${CREATED_AT//Z/ UTC}"
jq -n \
--arg title "${{ github.event.release.name }}" \
--arg tag "${{ github.event.release.tag_name }}" \
--arg url "${{ github.event.release.html_url }}" \
--arg author "${{ github.actor }}" \
--arg notes "$SAFE_NOTES" \
--arg created "$CREATED_AT" \
--arg repo "${{ github.repository }}" \
'{
username: "GitHub Release Bot",
avatar_url: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
embeds: [
{
title: "🚀 New Release Published",
url: $url,
color: 5793266,
author: {
name: $author,
icon_url: ("https://github.com/" + $author + ".png")
},
fields: [
{name: "Repository", value: $repo, inline: true},
{name: "Tag", value: $tag, inline: true},
{name: "Released at", value: $created, inline: false},
{name: "Release Notes", value: (if $notes == "" then "No description" else $notes end), inline: false}
],
footer: {
text: "GitHub Actions",
icon_url: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
},
timestamp: (now | todate)
}
]
}' > payload.json
curl -H "Content-Type: application/json" \
-X POST \
-d @payload.json \
"$DISCORD_WEBHOOK_URL"