1- # .github/workflows/notify-discord-release.yml
2- name : Notify Discord on Release
3-
4- on :
5- release :
6- types : [published]
7-
8- jobs :
9- notify-discord :
10- runs-on : ubuntu-latest
11- steps :
12- - name : Send release info to Discord
13- env :
14- DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
15- run : |
16- # Escape special characters in release notes
17- SAFE_NOTES="${{ github.event.release.body }}"
18- SAFE_NOTES="${SAFE_NOTES//\"/\\\"}"
19- SAFE_NOTES="${SAFE_NOTES//$'\n'/\\n}"
20-
21- # Create timestamp
22- CREATED_AT="${{ github.event.release.created_at }}"
23- CREATED_AT="${CREATED_AT//T/ }"
24- CREATED_AT="${CREATED_AT//Z/ UTC}"
25-
26- jq -n \
27- --arg title "${{ github.event.release.name }}" \
28- --arg tag "${{ github.event.release.tag_name }}" \
29- --arg url "${{ github.event.release.html_url }}" \
30- --arg author "${{ github.actor }}" \
31- --arg notes "$SAFE_NOTES" \
32- --arg created "$CREATED_AT" \
33- --arg repo "${{ github.repository }}" \
34- '{
35- username: "GitHub Release Bot",
36- avatar_url: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
37- embeds: [
38- {
39- title: "🚀 New Release Published",
40- url: $url,
41- color: 5793266,
42- author: {
43- name: $author,
44- icon_url: ("https://github.com/" + $author + ".png")
45- },
46- fields: [
47- {name: "Repository", value: $repo, inline: true},
48- {name: "Tag", value: $tag, inline: true},
49- {name: "Released at", value: $created, inline: false},
50- {name: "Release Notes", value: (if $notes == "" then "No description" else $notes end), inline: false}
51- ],
52- footer: {
53- text: "GitHub Actions",
54- icon_url: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
55- },
56- timestamp: (now | todate)
57- }
58- ]
59- }' > payload.json
60-
61- curl -H "Content-Type: application/json" \
62- -X POST \
63- -d @payload.json \
64- "$DISCORD_WEBHOOK_URL"
1+ name : Notify Discord on Release
2+
3+ on :
4+ release :
5+ types : [published]
6+
7+ jobs :
8+ notify-discord :
9+ runs-on : ubuntu-latest
10+ steps :
11+ - name : Send release info to Discord
12+ env :
13+ DISCORD_WEBHOOK_URL : ${{ secrets.DISCORD_WEBHOOK_URL }}
14+ run : |
15+ RELEASE_TITLE="${{ github.event.release.name }}"
16+ TAG_NAME="${{ github.event.release.tag_name }}"
17+ RELEASE_NOTE="${{ github.event.release.body }}"
18+
19+ if [ -z "$RELEASE_NOTE" ]; then
20+ RELEASE_NOTE="(empty)"
21+ fi
22+
23+ if [ ${#RELEASE_NOTE} -gt 1000 ]; then
24+ RELEASE_NOTE="${RELEASE_NOTE:0:1000}..."
25+ fi
26+
27+ jq -n \
28+ --arg title "$RELEASE_TITLE" \
29+ --arg tag "$TAG_NAME" \
30+ --arg note "$RELEASE_NOTE" \
31+ '{
32+ embeds: [
33+ {
34+ title: "GitHub Release",
35+ fields: [
36+ { "name": "Release Title", "value": $title, "inline": false },
37+ { "name": "Tag Name", "value": $tag, "inline": false },
38+ { "name": "Release Note", "value": $note, "inline": false }
39+ ]
40+ }
41+ ]
42+ }' > payload.json
43+
44+ cat payload.json
45+
46+ curl --fail-with-body \
47+ -H "Content-Type: application/json" \
48+ -X POST \
49+ -d @payload.json \
50+ "$DISCORD_WEBHOOK_URL"
0 commit comments