Repository navigation
246 lines (224 loc) · 7.39 KB
/
Copy pathrelease.yml
File metadata and controls
246 lines (224 loc) · 7.39 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
# tag(v*)触发
# 各架构原生 runner 构建 → 合并清单 → 创建 GitHub 草稿 Release
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "要发布的标签(例如 v1.1.0 或 v1.1.0-beta.1)"
required: true
type: string
permissions:
contents: write
env:
NODE_VERSION: 24.x
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
# 同一个 tag 的发布串行执行,避免并发上传资源产生竞态
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
cancel-in-progress: false
jobs:
# 各平台/架构在对应的原生 runner 上独立构建
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:
- name: Check out git repository
uses: actions/checkout@v5
with:
ref: ${{ env.RELEASE_TAG }}
- name: Setup pnpm
uses: pnpm/action-setup@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
workspaces: ". -> target"
# 校验标签、版本和更新通道;Beta 由 beta.yml 自动打 tag,版本号以 tag 为准写入
- name: Verify release metadata
shell: bash
run: |
VERSION="${RELEASE_TAG#v}"
case "$VERSION" in
*-beta.*)
npm pkg set version="$VERSION"
echo "UPDATE_CHANNEL=beta" >> "$GITHUB_ENV"
;;
*-*)
echo "不支持的预发布版本格式: $VERSION"
exit 1
;;
*)
if [ "$(node -p "require('./package.json').version")" != "$VERSION" ]; then
echo "标签 $RELEASE_TAG 与 package.json 版本不一致"
exit 1
fi
echo "UPDATE_CHANNEL=latest" >> "$GITHUB_ENV"
;;
esac
# Linux: 安装系统构建/打包依赖
- name: 安装系统依赖 (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y \
libasound2-dev libdbus-1-dev libpipewire-0.3-dev libpulse-dev pkg-config clang \
rpm libarchive-tools
# 清理旧构建产物
- name: Clean workspace
shell: bash
run: rm -rf dist out
# CI 不需要国内镜像
- name: 移除 .npmrc
shell: bash
run: rm -f .npmrc
# 安装项目依赖
- name: Install dependencies
run: pnpm install --frozen-lockfile
# 仅构建本机架构
- name: Build ${{ matrix.name }}
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CSC_IDENTITY_AUTO_DISCOVERY: false
run: |
case "${{ matrix.target }}" in
windows-x64)
pnpm build:win --x64 --publish never
;;
windows-arm64)
pnpm build:win --arm64 --publish never
;;
macos-x64)
pnpm build:mac --x64 --publish never
;;
macos-arm64)
pnpm build:mac --arm64 --publish never
;;
linux-x64)
pnpm build:linux --x64 --publish never
;;
linux-arm64)
pnpm build:linux --arm64 --publish never
;;
*)
echo "Unsupported target: ${{ matrix.target }}"
exit 1
;;
esac
- name: Upload Artifact
uses: actions/upload-artifact@v7
with:
name: SPlayer-Next-${{ matrix.name }}
path: dist/*.*
# 合并多架构更新清单并创建 GitHub 草稿 Release
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ env.RELEASE_TAG }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
- name: Verify release metadata
shell: bash
run: |
VERSION="${RELEASE_TAG#v}"
case "$VERSION" in
*-beta.*)
echo "UPDATE_CHANNEL=beta" >> "$GITHUB_ENV"
;;
*-*)
echo "不支持的预发布版本格式: $VERSION"
exit 1
;;
*)
if [ "$(node -p "require('./package.json').version")" != "$VERSION" ]; then
echo "标签 $RELEASE_TAG 与 package.json 版本不一致"
exit 1
fi
echo "UPDATE_CHANNEL=latest" >> "$GITHUB_ENV"
;;
esac
echo "APP_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
# 整理待发布资源
- name: Prepare release assets
shell: bash
run: |
npm install --no-save --prefix "$RUNNER_TEMP/jsyaml" js-yaml@4.1.0
NODE_PATH="$RUNNER_TEMP/jsyaml/node_modules" \
node --test .github/scripts/prepare-release-assets.test.cjs
NODE_PATH="$RUNNER_TEMP/jsyaml/node_modules" \
node .github/scripts/prepare-release-assets.cjs artifacts release-assets "$APP_VERSION"
echo "待发布资源:"
ls -1 release-assets
# 用官方 gh CLI 确定性创建 Release
# 正式版保持草稿,预览版直接发布为 prerelease
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
# 重跑场景:若同名 release 已存在则先删除,避免脏状态(保留 tag)
if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release delete "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --yes
fi
if [ "$UPDATE_CHANNEL" != "latest" ]; then
gh release create "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "$RELEASE_TAG" \
--generate-notes \
--verify-tag \
--prerelease \
release-assets/*
else
gh release create "$RELEASE_TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "$RELEASE_TAG" \
--generate-notes \
--verify-tag \
--draft \
release-assets/*
fi