11name : discord message
22on :
3- release :
4- types : [published]
3+ # release:
4+ # types: [published]
5+ push :
6+ branches :
7+ - main
58
69jobs :
710 build :
@@ -10,18 +13,33 @@ jobs:
1013 - name : Checkout code
1114 uses : actions/checkout@v4
1215
13- - name : Send Discord notification
14- env :
15- DISCORD_WEBHOOK : ${{ secrets.DISCORD_WEBHOOK_URL }}
16- DISCORD_USERNAME : Github Actions
17- DISCORD_AVATAR : https://cdn.discordapp.com/avatars/1460099944252702846/e57fd67dc7ca0cc840a0e87a82281bc5.webp?size=80
16+ - name : Prepare Discord message
17+ id : prepare_message
18+ run : |
19+ # 构造完整消息
20+ full_msg="🚀 **New Release!** ${{ github.event.release.name }}
21+
22+ **Tag:** ${{ github.event.release.tag_name }}
23+ **Author:** ${{ github.event.release.author.login }}
24+
25+ **Release Notes:**
26+ ${{ github.event.release.body }}"
27+
28+ # 截断到 1990 字符(留 10 字符给可能的 ... 和安全余量)
29+ if [ ${#full_msg} -gt 1990 ]; then
30+ truncated_msg="${full_msg:0:1987}..."
31+ else
32+ truncated_msg="$full_msg"
33+ fi
34+
35+ # 转义换行符和特殊字符,以便通过 env 传递(可选,但更安全)
36+ echo "DISCORD_MSG<<EOF" >> $GITHUB_ENV
37+ echo "$truncated_msg" >> $GITHUB_ENV
38+ echo "EOF" >> $GITHUB_ENV
39+
40+ - name : Send to Discord
1841 uses : Ilshidur/action-discord@0.4.0
1942 with :
2043 args : |
21- 🚀 **New Release!** ${{ github.event.release.name }}
22-
23- **Tag:** ${{ github.event.release.tag_name }}
24- **Author:** ${{ github.event.release.author.login }}
44+ ${{ env.DISCORD_MSG }}
2545
26- **Release Notes:**
27- ${{ github.event.release.body }}
0 commit comments