11name : Release
22
33on :
4- push :
5- tags :
6- - ' v*'
74 workflow_dispatch :
85 inputs :
96 version :
107 description : ' Release version (e.g., v0.1.0)'
118 required : true
12- default : ' v0.1.1'
139 type : string
1410
1511permissions :
@@ -21,42 +17,187 @@ env:
2117 REPO_URL : https://github.com/CmzYa/sound_link
2218
2319jobs :
24- validate-tag :
25- name : 校验 Tag 来源并提取版本
20+ prepare-version :
21+ name : 准备版本号并同步文件
2622 runs-on : ubuntu-22.04
2723 outputs :
28- tag : ${{ steps.meta.outputs.tag }}
29- version : ${{ steps.meta.outputs.version }}
24+ tag : ${{ steps.version.outputs.tag }}
25+ version : ${{ steps.version.outputs.version }}
26+ changelog : ${{ steps.changelog.outputs.content }}
3027 steps :
3128 - name : 检出代码
3229 uses : actions/checkout@v4
3330 with :
3431 fetch-depth : 0
32+ token : ${{ secrets.GITHUB_TOKEN }}
3533
36- - name : 校验 Tag 指向 main 分支提交
34+ - name : 读取当前版本号
35+ id : current
3736 run : |
3837 set -euo pipefail
39- git fetch origin main --no-tags
40- if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
41- echo "❌ 当前 tag (${GITHUB_REF_NAME}) 对应提交不在 main 分支上 "
42- exit 1
43- fi
44- echo "✅ Tag 来源校验通过 "
38+ CURRENT_VERSION=$(jq -r '.version' package.json)
39+ echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
40+ echo "当前文件版本: $CURRENT_VERSION "
41+ echo ""
42+ echo "📋 当前版本号: $CURRENT_VERSION"
43+ echo " 请在手动触发时输入新版本号(如: v0.1.4) "
4544
46- - name : 提取版本信息
47- id : meta
45+ - name : 确定目标版本
46+ id : version
4847 run : |
4948 set -euo pipefail
50- TAG ="${{ github.event.inputs.version || github.ref_name }}"
51- VERSION="$(echo "$TAG " | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)"
49+ INPUT_VERSION ="${{ github.event.inputs.version }}"
50+ VERSION="$(echo "$INPUT_VERSION " | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)"
5251 if [ -z "$VERSION" ]; then
53- echo "❌ 无法从 tag 提取版本号 : $TAG "
52+ echo "❌ 无法从输入提取版本号 : $INPUT_VERSION "
5453 exit 1
5554 fi
56-
55+ TAG="v$VERSION"
56+
5757 echo "tag=$TAG" >> "$GITHUB_OUTPUT"
5858 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
59- echo "✅ 发布版本: $VERSION"
59+ echo "目标版本: $VERSION"
60+
61+ - name : 获取提交记录
62+ id : commits
63+ run : |
64+ set -euo pipefail
65+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
66+ if [ -n "$LAST_TAG" ]; then
67+ echo "上次发布: $LAST_TAG"
68+ COMMITS=$(git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)" --no-merges)
69+ else
70+ echo "首次发布,获取最近20条提交"
71+ COMMITS=$(git log -20 --pretty=format:"- %s (%h)" --no-merges)
72+ fi
73+ # 转义换行符以便在 GitHub Actions 中传递
74+ COMMITS="${COMMITS//'%'/'%25'}"
75+ COMMITS="${COMMITS//$'\n'/'%0A'}"
76+ COMMITS="${COMMITS//$'\r'/'%0D'}"
77+ echo "commits=$COMMITS" >> "$GITHUB_OUTPUT"
78+
79+ - name : 生成更新日志
80+ id : changelog
81+ uses : actions/github-script@v7
82+ with :
83+ script : |
84+ const commits = `${{ steps.commits.outputs.commits }}`.replace(/%0A/g, '\n').replace(/%0D/g, '').replace(/%25/g, '%');
85+ const version = '${{ steps.version.outputs.version }}';
86+
87+ if (!commits || commits.trim() === '') {
88+ core.setOutput('content', '### 🚀 新功能与改进\n\n- 版本更新');
89+ return;
90+ }
91+
92+ const prompt = `请根据以下 Git 提交记录,生成一份简洁的更新日志(中文)。
93+
94+ 版本号 : v${version}
95+
96+ 提交记录 :
97+ ${commits}
98+
99+ 要求 :
100+ 1. 按功能分类(新功能、改进、修复等)
101+ 2. 每类列出 2-5 条主要更新
102+ 3. 使用 emoji 增强可读性
103+ 4. 保持简洁,不要冗余
104+ 5. 只输出更新日志内容,不要其他说明
105+
106+ 格式示例 :
107+ # ## ✨ 新功能
108+ - 添加 xxx 功能
109+
110+ # ## 🔧 改进
111+ - 优化 xxx 性能
112+
113+ # ## 🐛 修复
114+ - 修复 xxx 问题`;
115+
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}`);
133+ }
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- 版本更新');
141+ }
142+ env :
143+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
144+
145+ - name : 同步版本号到文件
146+ run : |
147+ set -euo pipefail
148+ VERSION="${{ steps.version.outputs.version }}"
149+ CURRENT="${{ steps.current.outputs.version }}"
150+
151+ if [ "$VERSION" != "$CURRENT" ]; then
152+ echo "更新版本号: $CURRENT -> $VERSION"
153+
154+ # 更新 package.json
155+ jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp
156+ mv package.json.tmp package.json
157+
158+ # 更新 tauri.conf.json
159+ jq --arg v "$VERSION" '.version = $v' src-tauri/tauri.conf.json > tauri.conf.json.tmp
160+ mv tauri.conf.json.tmp src-tauri/tauri.conf.json
161+
162+ # 更新 Cargo.toml
163+ sed -i "s/^version = \".*\"/version = \"$VERSION\"/" src-tauri/Cargo.toml
164+
165+ echo "✅ 版本号已同步到所有文件"
166+ else
167+ echo "版本号未变化,跳过同步"
168+ fi
169+
170+ - name : 提交版本更新
171+ run : |
172+ set -euo pipefail
173+ VERSION="${{ steps.version.outputs.version }}"
174+ CURRENT="${{ steps.current.outputs.version }}"
175+
176+ if [ "$VERSION" != "$CURRENT" ]; then
177+ git config user.name "github-actions[bot]"
178+ git config user.email "github-actions[bot]@users.noreply.github.com"
179+ git add package.json src-tauri/tauri.conf.json src-tauri/Cargo.toml
180+ git commit -m "chore: bump version to $VERSION"
181+ git push
182+ echo "✅ 版本更新已提交"
183+ fi
184+
185+ validate-tag :
186+ name : 校验发布信息
187+ needs : prepare-version
188+ runs-on : ubuntu-22.04
189+ outputs :
190+ tag : ${{ needs.prepare-version.outputs.tag }}
191+ version : ${{ needs.prepare-version.outputs.version }}
192+ changelog : ${{ needs.prepare-version.outputs.changelog }}
193+ steps :
194+ - name : 显示发布信息
195+ run : |
196+ echo "✅ 手动触发发布"
197+ echo "✅ 发布版本: ${{ needs.prepare-version.outputs.version }}"
198+ echo ""
199+ echo "📝 更新日志:"
200+ echo "${{ needs.prepare-version.outputs.changelog }}"
60201
61202 build-windows :
62203 name : 构建 Windows 版本
@@ -103,22 +244,17 @@ jobs:
103244 releaseBody : |
104245 ## Sound Link v${{ needs.validate-tag.outputs.version }}
105246
106- > 可视化音频设备切换工具
247+ ${{ needs.validate-tag.outputs.changelog }}
107248
108- ### 功能特点
109- - 🎧 可视化显示系统音频设备
110- - ⚡ 一键切换音频输出设备
111- - 🌙 跟随系统主题(深色/浅色模式)
112- - 🎨 跟随系统主题色
113- - ✨ 高级毛玻璃材质效果
249+ ---
114250
115- ### 下载说明
251+ ### 📥 下载说明
116252 | 平台 | 架构 | 文件格式 |
117253 |------|------|----------|
118254 | Windows | x64 | `.msi` / `.exe` |
119255 | Windows | ARM64 | `.msi` / `.exe` |
120256
121- ### 安装依赖
257+ ### 📦 安装依赖
122258 使用前需安装 [AudioDeviceCmdlets](https://github.com/frgnca/AudioDeviceCmdlets) PowerShell 模块:
123259 ```powershell
124260 Install-Module -Name AudioDeviceCmdlets -Force
0 commit comments