2323 outputs :
2424 tag : ${{ steps.version.outputs.tag }}
2525 version : ${{ steps.version.outputs.version }}
26- changelog : ${{ steps.changelog.outputs.content }}
2726 steps :
2827 - name : 检出代码
2928 uses : actions/checkout@v4
@@ -65,31 +64,28 @@ jobs:
6564 LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
6665 if [ -n "$LAST_TAG" ]; then
6766 echo "上次发布: $LAST_TAG"
68- COMMITS=$( git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)" --no-merges)
67+ git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)" --no-merges > /tmp/commits.txt
6968 else
7069 echo "首次发布,获取最近20条提交"
71- COMMITS=$( git log -20 --pretty=format:"- %s (%h)" --no-merges)
70+ git log -20 --pretty=format:"- %s (%h)" --no-merges > /tmp/commits.txt
7271 fi
73- # 转义换行符以便在 GitHub Actions 中传递
74- COMMITS="${COMMITS//'%'/'%25'}"
75- COMMITS="${COMMITS//$'\n'/'%0A'}"
76- COMMITS="${COMMITS//$'\r'/'%0D'}"
77- echo "commits=$COMMITS" >> "$GITHUB_OUTPUT"
72+ echo "提交记录已保存到 /tmp/commits.txt"
7873
7974 - name : 生成更新日志
8075 id : changelog
8176 uses : actions/github-script@v7
8277 with :
8378 script : |
84- const commits = `${{ steps.commits.outputs.commits }}`.replace(/%0A/g, '\n').replace(/%0D/g, '').replace(/%25/g, '%');
79+ const fs = require('fs');
80+ const commits = fs.readFileSync('/tmp/commits.txt', 'utf8');
8581 const version = '${{ steps.version.outputs.version }}';
8682
87- if (!commits || commits.trim() === '') {
88- core.setOutput('content', '### 🚀 新功能与改进\n\n- 版本更新');
89- return;
90- }
83+ let changelogContent = '';
9184
92- const prompt = `请根据以下 Git 提交记录,生成一份简洁的更新日志(中文)。
85+ if (!commits || commits.trim() === '') {
86+ changelogContent = '### 🚀 新功能与改进\n\n- 版本更新';
87+ } else {
88+ const prompt = `请根据以下 Git 提交记录,生成一份简洁的更新日志(中文)。
9389
9490版本号 : v${version}
9591
@@ -113,35 +109,69 @@ ${commits}
113109# ## 🐛 修复
114110- 修复 xxx 问题`;
115111
116- try {
117- const response = await fetch('https://models.inference.ai.azure.com/chat/completions', {
118- method : ' POST' ,
119- headers : {
120- ' Authorization ' : ` Bearer ${process.env.GITHUB_TOKEN}` ,
121- ' Content-Type ' : ' application/json'
122- },
123- body : JSON.stringify({
124- model : ' gpt-4o-mini' ,
125- messages : [{ role: 'user', content: prompt }],
126- max_tokens : 1000,
127- temperature : 0.7
128- })
129- });
130-
131- if (!response.ok) {
132- throw new Error(`API 请求失败 : ${response.status}`);
112+ try {
113+ const response = await fetch('https://models.inference.ai.azure.com/chat/completions', {
114+ method : ' POST' ,
115+ headers : {
116+ ' Authorization ' : ` Bearer ${process.env.GITHUB_TOKEN}` ,
117+ ' Content-Type ' : ' application/json'
118+ },
119+ body : JSON.stringify({
120+ model : ' gpt-4o-mini' ,
121+ messages : [{ role: 'user', content: prompt }],
122+ max_tokens : 1000,
123+ temperature : 0.7
124+ })
125+ });
126+
127+ if (!response.ok) {
128+ throw new Error(`API 请求失败 : ${response.status}`);
129+ }
130+
131+ const data = await response.json();
132+ changelogContent = data.choices[0]?.message?.content || '### 🚀 更新\n\n- 版本更新';
133+ console.log('更新日志已生成');
134+ } catch (error) {
135+ console.log('AI 生成失败,使用默认更新日志:', error.message);
136+ changelogContent = '### 🚀 更新\n\n- 版本更新';
133137 }
134-
135- const data = await response.json();
136- let changelog = data.choices[0]?.message?.content || '### 🚀 更新\n\n- 版本更新';
137- core.setOutput('content', changelog);
138- } catch (error) {
139- console.log('AI 生成失败,使用默认更新日志:', error.message);
140- core.setOutput('content', '### 🚀 更新\n\n- 版本更新');
141138 }
139+
140+ const fullBody = `## Sound Link v${version}
141+
142+ ${changelogContent}
143+
144+ ---
145+
146+ # ## 📥 下载说明
147+ | 平台 | 架构 | 文件格式 |
148+ |------|------|----------|
149+ | Windows | x64 | \`.msi\` / \`.exe\` |
150+ | Windows | ARM64 | \`.msi\` / \`.exe\` |
151+
152+ # ## 📦 安装依赖
153+ 使用前需安装 [AudioDeviceCmdlets](https://github.com/frgnca/AudioDeviceCmdlets) PowerShell 模块:
154+ \`\`\`powershell
155+ Install-Module -Name AudioDeviceCmdlets -Force
156+ \`\`\`
157+
158+ ---
159+
160+ **作者**: [@CmzYa](https://github.com/CmzYa)
161+ **仓库**: [https://github.com/CmzYa/sound_link](https://github.com/CmzYa/sound_link)
162+ **许可证**: MIT License`;
163+
164+ fs.writeFileSync('/tmp/changelog.md', fullBody);
142165 env :
143166 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
144167
168+ - name : 上传更新日志
169+ uses : actions/upload-artifact@v4
170+ with :
171+ name : changelog
172+ path : /tmp/changelog.md
173+ retention-days : 1
174+
145175 - name : 同步版本号到文件
146176 run : |
147177 set -euo pipefail
@@ -189,15 +219,20 @@ ${commits}
189219 outputs :
190220 tag : ${{ needs.prepare-version.outputs.tag }}
191221 version : ${{ needs.prepare-version.outputs.version }}
192- changelog : ${{ needs.prepare-version.outputs.changelog }}
193222 steps :
223+ - name : 下载更新日志
224+ uses : actions/download-artifact@v4
225+ with :
226+ name : changelog
227+ path : /tmp
228+
194229 - name : 显示发布信息
195230 run : |
196231 echo "✅ 手动触发发布"
197232 echo "✅ 发布版本: ${{ needs.prepare-version.outputs.version }}"
198233 echo ""
199234 echo "📝 更新日志:"
200- echo "${{ needs.prepare-version.outputs. changelog }}"
235+ cat /tmp/ changelog.md
201236
202237 build-windows :
203238 name : 构建 Windows 版本
@@ -218,6 +253,12 @@ ${commits}
218253 - name : 检出代码
219254 uses : actions/checkout@v4
220255
256+ - name : 下载更新日志
257+ uses : actions/download-artifact@v4
258+ with :
259+ name : changelog
260+ path : /tmp
261+
221262 - name : 安装 Node.js
222263 uses : actions/setup-node@v4
223264 with :
@@ -241,30 +282,7 @@ ${commits}
241282 with :
242283 tagName : ${{ needs.validate-tag.outputs.tag }}
243284 releaseName : " Sound Link v${{ needs.validate-tag.outputs.version }}"
244- releaseBody : |
245- ## Sound Link v${{ needs.validate-tag.outputs.version }}
246-
247- ${{ needs.validate-tag.outputs.changelog }}
248-
249- ---
250-
251- ### 📥 下载说明
252- | 平台 | 架构 | 文件格式 |
253- |------|------|----------|
254- | Windows | x64 | `.msi` / `.exe` |
255- | Windows | ARM64 | `.msi` / `.exe` |
256-
257- ### 📦 安装依赖
258- 使用前需安装 [AudioDeviceCmdlets](https://github.com/frgnca/AudioDeviceCmdlets) PowerShell 模块:
259- ```powershell
260- Install-Module -Name AudioDeviceCmdlets -Force
261- ```
262-
263- ---
264-
265- **作者**: [@CmzYa](https://github.com/CmzYa)
266- **仓库**: [https://github.com/CmzYa/sound_link](https://github.com/CmzYa/sound_link)
267- **许可证**: MIT License
285+ releaseBodyFile : /tmp/changelog.md
268286 releaseDraft : true
269287 prerelease : false
270288 args : ${{ matrix.args }}
0 commit comments