11# .github/workflows/notify-discord-release.yml
2- name : Notify Discord 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- RELEASE_TITLE : ${{ github.event.release.name }}
16- TAG_NAME : ${{ github.event.release.tag_name }}
17- RELEASE_NOTE : ${{ github.event.release.body }}
18- run : |
19- jq -n \
20- --arg title "$RELEASE_TITLE" \
21- --arg tag "$TAG_NAME" \
22- --arg note "$RELEASE_NOTE" \
23- '{
24- embeds: [
25- {
26- title: "New GitHub Release",
27- fields: [
28- {
29- name: "Release Title",
30- value: (if $title == "" then "(empty)" else $title end),
31- inline: false
32- },
33- {
34- name: "Tag Name",
35- value: (if $tag == "" then "(empty)" else $tag end),
36- inline: false
37- },
38- {
39- name: "Release Note",
40- value: (if $note == "" then "(empty)" else $note end),
41- inline: false
42- }
43- ]
44- }
45- ]
46- }' > payload.json
47-
48- curl -H "Content-Type: application/json" \
49- -X POST \
50- -d @payload.json \
51- "$DISCORD_WEBHOOK_URL"
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"
0 commit comments