-
Notifications
You must be signed in to change notification settings - Fork 54
68 lines (60 loc) · 2.09 KB
/
release-discord.yaml
File metadata and controls
68 lines (60 loc) · 2.09 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
name: Announce release to Discord
on:
release:
types: [published]
permissions:
contents: read
jobs:
notify-discord:
runs-on: ubuntu-latest
steps:
- name: Post release announcement to Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
RELEASE_NAME: ${{ github.event.release.name }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_URL: ${{ github.event.release.html_url }}
RELEASE_BODY: ${{ github.event.release.body }}
REPO: ${{ github.repository }}
run: |
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "DISCORD_WEBHOOK_URL is not configured; skipping."
exit 0
fi
if [ -n "$RELEASE_NAME" ]; then
TITLE="$RELEASE_NAME"
else
TITLE="$RELEASE_TAG"
fi
BODY_CLEAN=$(printf '%s' "$RELEASE_BODY" | sed 's/\r//g')
BODY_TRIM=$(printf '%s' "$BODY_CLEAN" | sed '/^[[:space:]]*$/d')
if [ -n "$BODY_TRIM" ]; then
SUMMARY=$(printf '%s' "$BODY_TRIM" | head -c 1400)
else
SUMMARY="No release notes provided."
fi
PAYLOAD=$(jq -n \
--arg title "🚀 New App/Add-on release published: $TITLE" \
--arg repo "$REPO" \
--arg tag "$RELEASE_TAG" \
--arg url "$RELEASE_URL" \
--arg summary "$SUMMARY" \
'{
content: "",
embeds: [
{
title: $title,
url: $url,
color: 5814783,
fields: [
{name: "Repository", value: $repo, inline: true},
{name: "Tag", value: $tag, inline: true},
{name: "Release URL", value: $url, inline: false},
{name: "Release notes", value: $summary, inline: false}
]
}
]
}')
curl -sS -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"