Skip to content

Commit a6bdc90

Browse files
committed
build(github action): 📦 fix release workflow
1 parent 409f168 commit a6bdc90

File tree

2 files changed

+213
-77
lines changed

2 files changed

+213
-77
lines changed

.github/workflows/release.yml

Lines changed: 210 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,153 @@ on:
44
push:
55
tags:
66
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Release version (e.g., 1.0.0)'
11+
required: true
12+
type: string
13+
14+
env:
15+
NODE_VERSION: '22.18.0'
16+
PNPM_VERSION: '10.14.0'
717

818
jobs:
919
create-release:
1020
permissions:
1121
contents: write
1222
runs-on: ubuntu-latest
23+
timeout-minutes: 10
1324
outputs:
1425
release_id: ${{ steps.create-release.outputs.id }}
26+
app_version: ${{ steps.get-version.outputs.version }}
27+
app_name: ${{ steps.get-name.outputs.name }}
1528

1629
steps:
17-
- uses: actions/checkout@v3
30+
- name: 检出代码仓库
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
1834

19-
- name: setup node
20-
uses: actions/setup-node@v3
35+
- name: 设置 Node.js 环境
36+
uses: actions/setup-node@v4
2137
with:
22-
node-version: 21
38+
node-version: ${{ env.NODE_VERSION }}
2339

24-
# pnpm 并使用缓存安装包
25-
- uses: pnpm/action-setup@v2
26-
name: Install pnpm
27-
id: pnpm-install
40+
- name: 安装 pnpm
41+
uses: pnpm/action-setup@v4
2842
with:
29-
version: 9
43+
version: ${{ env.PNPM_VERSION }}
3044
run_install: false
3145

32-
- name: Get pnpm store directory
46+
- name: 获取 pnpm 存储目录
3347
id: pnpm-cache
3448
shell: bash
3549
run: |
3650
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
3751
38-
- uses: actions/cache@v3
39-
name: Setup pnpm cache
52+
- name: 设置 pnpm 缓存
53+
uses: actions/cache@v4
4054
with:
4155
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
4256
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
4357
restore-keys: |
4458
${{ runner.os }}-pnpm-store-
4559
46-
- name: Install frontend dependencies
47-
run: pnpm install
60+
- name: 安装前端依赖
61+
run: pnpm install --frozen-lockfile
4862

49-
- name: Generate UPDATE_LOG.md
50-
run: pnpm run script:changelog
63+
- name: 验证版本一致性
64+
run: |
65+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
66+
TAURI_VERSION=$(node -p "require('./src-tauri/tauri.conf.json').version")
67+
68+
echo "📦 Package.json 版本: $PACKAGE_VERSION"
69+
echo "🦀 Tauri 配置版本: $TAURI_VERSION"
70+
71+
if [ "$PACKAGE_VERSION" != "$TAURI_VERSION" ]; then
72+
echo "❌ package.json 和 tauri.conf.json 版本不一致"
73+
exit 1
74+
fi
75+
76+
echo "✅ 版本一致性验证通过"
5177
52-
- name: get app version
53-
# 版本号
54-
run: echo "app_version=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
78+
- name: 提取发布说明
79+
id: extract-release-notes
80+
uses: ffurrer2/extract-release-notes@v2
81+
with:
82+
changelog_file: CHANGELOG.md
5583

56-
- name: get app name
57-
# 应用名称
58-
run: echo "app_name=$(node -p "require('./package.json').name")" >> $GITHUB_ENV
84+
- name: 获取应用版本
85+
id: get-version
86+
run: |
87+
VERSION=$(node -p "require('./package.json').version")
88+
echo "version=$VERSION" >> $GITHUB_OUTPUT
89+
echo "app_version=$VERSION" >> $GITHUB_ENV
90+
91+
- name: 获取应用名称
92+
id: get-name
93+
run: |
94+
NAME=$(node -p "require('./package.json').name")
95+
echo "name=$NAME" >> $GITHUB_OUTPUT
96+
echo "app_name=$NAME" >> $GITHUB_ENV
5997
60-
- name: create release
98+
- name: 创建发布版本
6199
id: create-release
62100
uses: ncipollo/release-action@v1
63101
with:
64-
owner: ${{ github.actor }}
65-
# 发布的可选标签。 如果省略,将使用 git ref (如果它是标签)。
102+
token: ${{ secrets.GITHUB_TOKEN }}
66103
tag: 'v${{ env.app_version }}'
67104
name: '${{ env.app_name }} v${{ env.app_version }}'
68-
# 可选择将此版本标记为草稿版本。 设置为 true 以启用。
69-
draft: true,
70-
# 发布的可选正文文件。 这应该是文件的路径。
71-
bodyFile: './updater/UPDATE_LOG.md'
72-
73-
- name: echo create-release outputs
74-
run: echo ${{ steps.create-release.outputs }}
75-
- name: echo create-release outputs.id
76-
run: echo ${{ steps.create-release.outputs.id }}
105+
draft: true
106+
prerelease: false
107+
body: |
108+
## 🎉 Release v${{ env.app_version }}
109+
110+
${{ steps.extract-release-notes.outputs.release_notes }}
111+
112+
---
113+
114+
### 📥 下载方式
115+
116+
请根据您的操作系统选择对应的安装包:
117+
118+
#### 🕸️ Windows
119+
- 🔗 **MSI 安装包**: [DevEnvLite_${{ env.app_version }}_x64_en-US.msi](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_x64_en-US.msi)
120+
- 🔗 **NSIS 安装包**: [DevEnvLite_${{ env.app_version }}_x64-setup.exe](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_x64-setup.exe)
121+
122+
#### 🍎 macOS
123+
- 🔗 **DMG 安装包**: [DevEnvLite_${{ env.app_version }}_universal.dmg](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_universal.dmg)
124+
- 🔗 **App 压缩包**: [DevEnvLite_${{ env.app_version }}_universal.app.tar.gz](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_universal.app.tar.gz)
125+
126+
#### 🐧 Linux
127+
- 🔗 **Debian 包**: [dev-env-lite_${{ env.app_version }}_amd64.deb](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/dev-env-lite_${{ env.app_version }}_amd64.deb)
128+
- 🔗 **AppImage**: [dev-env-lite_${{ env.app_version }}_amd64.AppImage](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/dev-env-lite_${{ env.app_version }}_amd64.AppImage)
129+
130+
> 💡 **提示**: 如果上述直链无法下载或文件名不匹配,请查看下方的 **Assets** 区域手动下载对应文件。
131+
132+
### 🔄 自动更新
133+
134+
本应用内置自动更新功能,启动后会自动检查并提示更新到最新版本。您也可以在设置中手动检查更新。
135+
136+
### 🛠️ 系统要求
137+
138+
- **Windows**: Windows 10 (1903) 或更高版本
139+
- **macOS**: macOS 10.15 (Catalina) 或更高版本,支持 Intel 和 Apple Silicon
140+
- **Linux**: 支持 GTK 3.0+ 的主流发行版 (Ubuntu 18.04+, Fedora 30+, etc.)
141+
142+
### 📝 安装说明
143+
144+
- **Windows**:
145+
- 下载 [MSI 安装包](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_x64_en-US.msi) 或 [NSIS 安装包](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_x64-setup.exe)
146+
- 双击下载的 `.msi` 或 `.exe` 文件即可安装
147+
- **macOS**:
148+
- 下载 [DMG 安装包](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_universal.dmg) 或 [App 压缩包](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/DevEnvLite_${{ env.app_version }}_universal.app.tar.gz)
149+
- 打开 `.dmg` 文件,将应用拖拽到 Applications 文件夹
150+
- **Linux**:
151+
- 下载 [Debian 包](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/dev-env-lite_${{ env.app_version }}_amd64.deb) 或 [AppImage](https://github.com/${{ github.repository }}/releases/download/v${{ env.app_version }}/dev-env-lite_${{ env.app_version }}_amd64.AppImage)
152+
- 使用 `sudo dpkg -i` 安装 `.deb` 包,或给 `.AppImage` 文件添加执行权限后直接运行
153+
generateReleaseNotes: true
77154

78155
build-tauri:
79156
needs: create-release
@@ -82,92 +159,149 @@ jobs:
82159
strategy:
83160
fail-fast: false
84161
matrix:
85-
platform: [macos-latest, ubuntu-latest, windows-latest]
86-
outputs:
87-
releaseId: ${{ steps.tauri-action.outputs.releaseId }}
88-
releaseHtmlUrl: ${{ steps.tauri-action.outputs.releaseHtmlUrl }}
89-
releaseUploadUrl: ${{ steps.tauri-action.outputs.releaseUploadUrl }}
90-
artifactPaths: ${{ steps.tauri-action.outputs.artifactPaths }}
91-
appVersion: ${{ steps.tauri-action.outputs.appVersion }}
92-
162+
include:
163+
- platform: 'macos-latest'
164+
args: '--target universal-apple-darwin'
165+
- platform: 'ubuntu-latest'
166+
args: ''
167+
- platform: 'windows-latest'
168+
args: ''
169+
93170
runs-on: ${{ matrix.platform }}
171+
timeout-minutes: 60
172+
94173
steps:
95-
- name: echo release_id
96-
run: echo "release_id = ${{ needs.create-release.outputs.release_id }}" ${{ needs.create-release.outputs.release_id }}
97-
98-
- uses: actions/checkout@v3
174+
- name: 检出代码仓库
175+
uses: actions/checkout@v4
176+
with:
177+
fetch-depth: 0
99178

100-
- name: install Rust stable
179+
- name: 安装 Rust 稳定版
101180
uses: dtolnay/rust-toolchain@stable
181+
with:
182+
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
102183

103-
- name: install dependencies (ubuntu only)
184+
- name: 安装依赖 (仅限 Ubuntu)
104185
if: matrix.platform == 'ubuntu-latest'
105186
run: |
106187
sudo apt-get update
107-
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf javascriptcoregtk-4.1 libsoup-3.0 webkit2gtk-4.1
188+
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libsoup-3.0-dev javascriptcoregtk-4.1-dev webkit2gtk-4.1-dev
108189
109-
- name: setup node
110-
uses: actions/setup-node@v3
190+
- name: 设置 Node.js 环境
191+
uses: actions/setup-node@v4
111192
with:
112-
node-version: 21
193+
node-version: ${{ env.NODE_VERSION }}
113194

114-
# pnpm 并使用缓存安装包
115-
- uses: pnpm/action-setup@v2
116-
name: Install pnpm
117-
id: pnpm-install
195+
- name: 安装 pnpm
196+
uses: pnpm/action-setup@v4
118197
with:
119-
version: 9
198+
version: ${{ env.PNPM_VERSION }}
120199
run_install: false
121200

122-
- name: Get pnpm store directory
201+
- name: 获取 pnpm 存储目录
123202
id: pnpm-cache
124203
shell: bash
125204
run: |
126205
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
127206
128-
- uses: actions/cache@v3
129-
name: Setup pnpm cache
207+
- name: 设置 pnpm 缓存
208+
uses: actions/cache@v4
130209
with:
131210
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
132211
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
133212
restore-keys: |
134213
${{ runner.os }}-pnpm-store-
135214
136-
- name: Install frontend dependencies
137-
run: pnpm install
215+
- name: 设置 Rust 缓存
216+
uses: actions/cache@v4
217+
with:
218+
path: |
219+
~/.cargo/bin/
220+
~/.cargo/registry/index/
221+
~/.cargo/registry/cache/
222+
~/.cargo/git/db/
223+
src-tauri/target/
224+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
225+
restore-keys: |
226+
${{ runner.os }}-cargo-
227+
228+
- name: 安装 Node.js 依赖
229+
run: pnpm install --frozen-lockfile
138230

139-
- uses: tauri-apps/tauri-action@v0
140-
id: tauri-action
231+
- name: 构建 Tauri 应用
232+
uses: tauri-apps/tauri-action@v1
141233
env:
142234
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143235
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
144236
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
145237
with:
146238
releaseId: ${{ needs.create-release.outputs.release_id }}
239+
args: ${{ matrix.args }}
147240
updaterJsonPreferNsis: true
148241

149242
publish-release:
150243
permissions:
151244
contents: write
152245
runs-on: ubuntu-latest
153246
needs: [create-release, build-tauri]
247+
timeout-minutes: 5
248+
if: success()
154249

155250
steps:
156-
- name: echo release_id
157-
run: echo "release_id = ${{ needs.create-release.outputs.release_id }}" ${{ needs.create-release.outputs.release_id }}
158-
- name: publish release
159-
id: publish-release
160-
uses: actions/github-script@v6
251+
- name: 发布版本
252+
uses: actions/github-script@v7
161253
env:
162254
release_id: ${{ needs.create-release.outputs.release_id }}
163255
with:
164256
script: |
165-
github.rest.repos.updateRelease({
166-
owner: context.repo.owner,
167-
repo: context.repo.repo,
168-
release_id: process.env.release_id,
169-
draft: false,
170-
prerelease: false
171-
})
257+
try {
258+
const { data: release } = await github.rest.repos.updateRelease({
259+
owner: context.repo.owner,
260+
repo: context.repo.repo,
261+
release_id: process.env.release_id,
262+
draft: false,
263+
prerelease: false
264+
});
265+
266+
console.log(`✅ 发布成功: ${release.html_url}`);
267+
268+
core.summary
269+
.addHeading('🎉 版本发布成功!')
270+
.addRaw(`
271+
**发布版本**: [${release.name}](${release.html_url})
272+
**标签**: ${release.tag_name}
273+
**创建时间**: ${new Date(release.created_at).toLocaleString('zh-CN')}
274+
`)
275+
.write();
276+
} catch (error) {
277+
core.setFailed(`❌ 发布失败: ${error.message}`);
278+
throw error;
279+
}
172280
281+
cleanup-on-failure:
282+
permissions:
283+
contents: write
284+
runs-on: ubuntu-latest
285+
needs: [create-release, build-tauri]
286+
timeout-minutes: 5
287+
if: failure()
173288

289+
steps:
290+
- name: 删除失败的发布
291+
uses: actions/github-script@v7
292+
env:
293+
release_id: ${{ needs.create-release.outputs.release_id }}
294+
with:
295+
script: |
296+
try {
297+
if (process.env.release_id) {
298+
await github.rest.repos.deleteRelease({
299+
owner: context.repo.owner,
300+
repo: context.repo.repo,
301+
release_id: process.env.release_id,
302+
});
303+
console.log('🗑️ 已清理失败的发布');
304+
}
305+
} catch (error) {
306+
console.log(`⚠️ 无法删除发布: ${error.message}`);
307+
}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ dist-ssr
2727
.history/
2828

2929
# ignore .tauri
30-
.tauri/
30+
.tauri/
31+
32+
%USER*/

0 commit comments

Comments
 (0)