-
Notifications
You must be signed in to change notification settings - Fork 1.2k
276 lines (252 loc) · 9.51 KB
/
release.yml
File metadata and controls
276 lines (252 loc) · 9.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Build & Release
on:
push:
tags:
- v* # 只在 tag v* 时触发
workflow_dispatch:
env:
NODE_VERSION: 22.x
jobs:
# ===================================================================
# 并行构建所有平台和架构
# ===================================================================
build:
name: Build on ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
strategy:
# 矩阵策略
# 即使一个矩阵任务失败,其他任务也会继续运行
fail-fast: false
matrix:
include:
- name: Windows x64
runner: windows-latest
target: windows-x64
- name: Windows arm64
runner: windows-11-arm
target: windows-arm64
- name: macOS x64
runner: macos-15-intel
target: macos-x64
- name: macOS arm64
runner: macos-latest
target: macos-arm64
- name: Linux x64
runner: ubuntu-latest
target: linux-x64
- name: Linux arm64
runner: ubuntu-24.04-arm
target: linux-arm64
# 开始步骤
steps:
# 检出 Git 仓库
- name: Check out git repository
uses: actions/checkout@v6
# 设置 pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v5
# 安装 Node.js
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
# 设置 Rust
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Rust Cache
uses: Swatinem/rust-cache@v2
# 清理旧的构建产物
- name: Clean workspace on Windows
if: runner.os == 'Windows'
run: |
Write-Host "🧹 Cleaning workspace, node_modules, and Electron caches..."
if (Test-Path dist) { Remove-Item -Recurse -Force dist }
if (Test-Path out) { Remove-Item -Recurse -Force out }
if (Test-Path node_modules) { Remove-Item -Recurse -Force node_modules }
if (Test-Path "$env:LOCALAPPDATA\electron-builder") {
Remove-Item "$env:LOCALAPPDATA\electron-builder" -Recurse -Force -ErrorAction SilentlyContinue
}
if (Test-Path "$env:LOCALAPPDATA\electron") {
Remove-Item "$env:LOCALAPPDATA\electron" -Recurse -Force -ErrorAction SilentlyContinue
}
if (Test-Path "$env:USERPROFILE\.pnpm-store") {
Remove-Item "$env:USERPROFILE\.pnpm-store" -Recurse -Force -ErrorAction SilentlyContinue
}
- name: Clean workspace on macOS & Linux
if: runner.os == 'macOS' || runner.os == 'Linux'
run: |
echo "🧹 Cleaning workspace, node_modules, and Electron caches..."
rm -rf dist out node_modules ~/.cache/electron-builder ~/.cache/electron
# 更新 Ubuntu 软件源并安装依赖
- name: Update and Install Ubuntu Dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y rpm libarchive-tools libopenjp2-tools
# macOS 上安装 LLVM 以支持 Wasm 编译
- name: Install LLVM on macOS
if: runner.os == 'macOS'
run: brew install llvm
- name: Set Environment Variables on macOS
if: runner.os == 'macOS'
run: |
echo "CC=$(brew --prefix llvm)/bin/clang" >> $GITHUB_ENV
echo "AR=$(brew --prefix llvm)/bin/llvm-ar" >> $GITHUB_ENV
# 复制环境变量文件
- name: Copy .env file on Windows
if: runner.os == 'Windows'
run: |
if (-not (Test-Path .env)) {
Copy-Item .env.example .env
} else {
Write-Host ".env file already exists. Skipping the copy step."
}
- name: Copy .env file on macOS & Linux
if: runner.os == 'macOS' || runner.os == 'Linux'
run: |
if [ ! -f .env ]; then
cp .env.example .env
else
echo ".env file already exists. Skipping the copy step."
fi
# 安装项目依赖
- name: Install dependencies
run: pnpm install
# 构建 Electron App
- name: Build
env:
CSC_IDENTITY_AUTO_DISCOVERY: false
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
case "${{ matrix.target }}" in
windows-x64)
pnpm build:win -- --x64
;;
windows-arm64)
pnpm build:win -- --arm64
;;
macos-x64)
pnpm build:mac -- --x64
;;
macos-arm64)
pnpm build:mac -- --arm64
;;
linux-x64)
pnpm build:linux -- --x64
;;
linux-arm64)
pnpm build:linux -- --arm64
;;
*)
echo "Unsupported target: ${{ matrix.target }}"
exit 1
;;
esac
# 合并所有构建
- name: Upload Artifact
uses: actions/upload-artifact@v7
with:
name: SPlayer-${{ matrix.name }}
path: dist/*.*
# ===================================================================
# Generate Changelog & Release
# ===================================================================
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Generate Changelog
id: changelog
shell: bash
run: |
# 获取前一个 tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
CURRENT_TAG=${GITHUB_REF#refs/tags/}
echo "Previous tag: $PREV_TAG"
echo "Current tag: $CURRENT_TAG"
if [ -z "$PREV_TAG" ]; then
echo "No previous tag found. Generating log from start."
git log --pretty=format:"- %s (%h)" > changelog_content.md
else
echo "Generating log from $PREV_TAG to $CURRENT_TAG"
git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" > changelog_content.md
fi
# 翻译提交类型 (Conventional Commits)
sed -i -E 's/^- feat(\(.*\))?:/- ✨ 新增:/g' changelog_content.md
sed -i -E 's/^- fix(\(.*\))?:/- 🐞 修复:/g' changelog_content.md
sed -i -E 's/^- docs(\(.*\))?:/- 📝 文档:/g' changelog_content.md
sed -i -E 's/^- style(\(.*\))?:/- 💄 样式:/g' changelog_content.md
sed -i -E 's/^- refactor(\(.*\))?:/- ♻️ 重构:/g' changelog_content.md
sed -i -E 's/^- perf(\(.*\))?:/- ⚡️ 性能:/g' changelog_content.md
sed -i -E 's/^- test(\(.*\))?:/- ✅ 测试:/g' changelog_content.md
sed -i -E 's/^- build(\(.*\))?:/- 📦 构建:/g' changelog_content.md
sed -i -E 's/^- ci(\(.*\))?:/- 👷 CI:/g' changelog_content.md
sed -i -E 's/^- chore(\(.*\))?:/- 🔧 维护:/g' changelog_content.md
sed -i -E 's/^- revert(\(.*\))?:/- ⏪️ 回退:/g' changelog_content.md
# 1. 生成 CHANGELOG.md 的新条目
# 添加标题和日期
DATE=$(date +%Y-%m-%d)
echo -e "\n## [$CURRENT_TAG] - $DATE\n" > temp_header.md
cat temp_header.md changelog_content.md > new_entry.md
# 更新 CHANGELOG.md
if [ ! -f CHANGELOG.md ]; then
echo "# 更新日志" > CHANGELOG.md
fi
# 将新内容插入到 CHANGELOG.md 的第二行(标题之后)
head -n 1 CHANGELOG.md > temp_changelog.md
echo "" >> temp_changelog.md
cat new_entry.md >> temp_changelog.md
echo "" >> temp_changelog.md
tail -n +2 CHANGELOG.md >> temp_changelog.md
mv temp_changelog.md CHANGELOG.md
# 2. 生成 Release Body (release_notes.md)
cat changelog_content.md > release_notes.md
# 输出生成的日志内容供 Release 使用
cat release_notes.md
- name: Commit & Push Changelog
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add CHANGELOG.md
git commit -m "docs: 更新变更日志 $GITHUB_REF_NAME [skip ci]" || echo "No changes to commit"
git push origin HEAD:main || echo "Failed to push to main. This might happen if tag is not on main."
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
# 创建 GitHub Release 并上传所有产物
- name: Create GitHub Release and Upload Assets
uses: softprops/action-gh-release@v2
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
body_path: release_notes.md
generate_release_notes: true
draft: false
# 发布为预发布
prerelease: false
# 全部上传
files: |
!artifacts/**/*-unpacked/**
artifacts/**/*.exe
artifacts/**/*.dmg
artifacts/**/*.zip
artifacts/**/*.AppImage
artifacts/**/*.deb
artifacts/**/*.rpm
artifacts/**/*.pacman
artifacts/**/*.snap
artifacts/**/*.tar.gz
artifacts/**/*.yml
artifacts/**/*.blockmap