Skip to content

Commit 43dc35d

Browse files
committed
build: 更改GitHub工作流
1 parent f357f48 commit 43dc35d

1 file changed

Lines changed: 68 additions & 80 deletions

File tree

.github/workflows/release.yml

Lines changed: 68 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,42 @@ name: Release Packages
22

33
on:
44
release:
5-
# 仅在 GitHub Release 发布时触发。
65
types: [published]
7-
# 允许手动触发(用于测试)。
86
workflow_dispatch:
97

108
permissions:
11-
# 用于上传构建产物到 Release。
129
contents: write
1310

1411
jobs:
1512
build:
16-
name: Build (${{ matrix.os }})
17-
runs-on: ${{ matrix.os }}
13+
name: Build (${{ matrix.target_os }}-${{ matrix.arch }})
14+
runs-on: ${{ matrix.runner }}
1815
env:
19-
# 提前切换到 Node.js 24 运行 JavaScript actions,避免 Node.js 20 弃用警告。
16+
# Use Node.js 24 to run JavaScript actions and avoid Node 20 deprecation warnings.
2017
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
21-
# FFmpeg 下载源(使用仓库环境变量/密钥可覆盖)。
2218
FFMPEG_BASE_URL: https://dl.liangbm3.site/downloads/ffmpeg
23-
# 如果需要鉴权,请在仓库 Secrets 里配置 FFMPEG_TOKEN。
2419
FFMPEG_TOKEN: ${{ secrets.FFMPEG_TOKEN }}
20+
TARGET_OS: ${{ matrix.target_os }}
21+
TARGET_ARCH: ${{ matrix.arch }}
2522
strategy:
26-
# 允许某个平台失败时其它平台继续构建。
2723
fail-fast: false
2824
matrix:
29-
os: [ubuntu-latest, macos-latest, windows-latest]
25+
include:
26+
- runner: ubuntu-latest
27+
target_os: linux
28+
arch: amd64
29+
- runner: ubuntu-24.04-arm
30+
target_os: linux
31+
arch: arm64
32+
- runner: macos-13
33+
target_os: darwin
34+
arch: amd64
35+
- runner: macos-14
36+
target_os: darwin
37+
arch: arm64
38+
- runner: windows-latest
39+
target_os: windows
40+
arch: amd64
3041

3142
steps:
3243
- name: Checkout
@@ -35,27 +46,23 @@ jobs:
3546
- name: Set up Go
3647
uses: actions/setup-go@v5
3748
with:
38-
# 对齐项目的 Go 版本要求。
39-
go-version: '1.26.x'
49+
go-version: "1.26.x"
4050

4151
- name: Set up Node
4252
uses: actions/setup-node@v4
4353
with:
44-
node-version: '20'
45-
# 缓存前端依赖以加速构建。
46-
cache: 'npm'
54+
node-version: "20"
55+
cache: "npm"
4756
cache-dependency-path: frontend/package-lock.json
4857

4958
- name: Install Linux build deps
50-
if: runner.os == 'Linux'
51-
# Wails 在 Linux 上需要 GTK/WebKit 的开发依赖。
59+
if: matrix.target_os == 'linux'
5260
run: |
5361
sudo apt-get update
5462
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev
5563
5664
- name: Install NSIS
57-
if: runner.os == 'Windows'
58-
# 生成 Windows 安装包需要 NSIS。
65+
if: matrix.target_os == 'windows'
5966
shell: powershell
6067
run: |
6168
choco install -y nsis
@@ -67,7 +74,6 @@ jobs:
6774
- name: Install Wails and Task
6875
shell: bash
6976
run: |
70-
# 安装构建与打包所需的 CLI 工具。
7177
go install github.com/wailsapp/wails/v3/cmd/wails3@latest
7278
go install github.com/go-task/task/v3/cmd/task@latest
7379
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
@@ -79,7 +85,6 @@ jobs:
7985
8086
- name: Resolve package version
8187
shell: bash
82-
# 优先使用发布 tag,其次回退到 VERSION 文件。
8388
run: |
8489
if [ "${GITHUB_EVENT_NAME}" = "release" ] && [ -n "${GITHUB_REF_NAME}" ]; then
8590
raw="${GITHUB_REF_NAME}"
@@ -97,136 +102,119 @@ jobs:
97102
98103
- name: Build packages (no ffmpeg)
99104
shell: bash
100-
# 产出依赖系统 FFmpeg 的版本。
101105
run: |
102-
task package:no-ffmpeg
106+
task package:no-ffmpeg ARCH="${TARGET_ARCH}"
103107
104108
- name: Collect artifacts (no ffmpeg)
105109
shell: bash
106-
# 用后缀区分产物版本。
107110
run: |
108111
mkdir -p dist
109112
shopt -s nullglob
110113
version="${PACKAGE_VERSION}"
111114
suffix="no-ffmpeg"
112-
if [ "$RUNNER_OS" = "Windows" ]; then
113-
if [ -f "bin/AI-ViewNote.exe" ]; then
114-
cp "bin/AI-ViewNote.exe" "dist/AI-ViewNote-${version}-$suffix.exe"
115-
fi
115+
116+
if [ "${TARGET_OS}" = "windows" ]; then
116117
for f in bin/AI-ViewNote-*-installer.exe; do
117118
base=$(basename "$f")
118-
cp "$f" "dist/${base%.exe}-${version}-$suffix.exe"
119-
done
120-
for f in bin/*.msix; do
121-
base=$(basename "$f")
122-
cp "$f" "dist/${base%.msix}-${version}-$suffix.msix"
119+
cp "$f" "dist/${base%.exe}-${version}-${suffix}.exe"
123120
done
124-
elif [ "$RUNNER_OS" = "macOS" ]; then
121+
elif [ "${TARGET_OS}" = "darwin" ]; then
125122
if [ -d "bin/AI-ViewNote.app" ]; then
126-
ditto -c -k --sequesterRsrc --keepParent "bin/AI-ViewNote.app" "dist/AI-ViewNote-macos-${version}-$suffix.app.zip"
123+
ditto -c -k --sequesterRsrc --keepParent "bin/AI-ViewNote.app" "dist/AI-ViewNote-macos-${TARGET_ARCH}-${version}-${suffix}.app.zip"
127124
fi
128125
else
129-
if [ -f "bin/AI-ViewNote" ]; then
130-
cp "bin/AI-ViewNote" "dist/AI-ViewNote-${version}-$suffix"
131-
fi
132126
for f in bin/*.AppImage; do
133127
base=$(basename "$f")
134-
cp "$f" "dist/${base%.AppImage}-${version}-$suffix.AppImage"
128+
cp "$f" "dist/${base%.AppImage}-${version}-${suffix}-${TARGET_ARCH}.AppImage"
135129
done
136130
for f in bin/*.deb; do
137131
base=$(basename "$f")
138-
cp "$f" "dist/${base%.deb}-${version}-$suffix.deb"
132+
cp "$f" "dist/${base%.deb}-${version}-${suffix}-${TARGET_ARCH}.deb"
139133
done
140134
for f in bin/*.rpm; do
141135
base=$(basename "$f")
142-
cp "$f" "dist/${base%.rpm}-${version}-$suffix.rpm"
136+
cp "$f" "dist/${base%.rpm}-${version}-${suffix}-${TARGET_ARCH}.rpm"
143137
done
144138
for f in bin/*.pkg.tar.zst; do
145139
base=$(basename "$f")
146-
cp "$f" "dist/${base%.pkg.tar.zst}-${version}-$suffix.pkg.tar.zst"
140+
cp "$f" "dist/${base%.pkg.tar.zst}-${version}-${suffix}-${TARGET_ARCH}.pkg.tar.zst"
147141
done
148142
fi
149143
144+
- name: Clean package outputs
145+
shell: bash
146+
run: |
147+
shopt -s nullglob
148+
rm -rf "bin/AI-ViewNote.app"
149+
rm -f \
150+
bin/AI-ViewNote \
151+
bin/AI-ViewNote.exe \
152+
bin/*.AppImage \
153+
bin/*.deb \
154+
bin/*.rpm \
155+
bin/*.pkg.tar.zst \
156+
bin/AI-ViewNote-*-installer.exe \
157+
bin/*.msix \
158+
bin/ffmpeg \
159+
bin/ffmpeg.exe
160+
150161
- name: Build packages (with ffmpeg)
151162
shell: bash
152-
# 将 FFmpeg 打包进各平台产物。
153163
run: |
154-
# 先下载对应平台的 FFmpeg 到 bin 目录。
155164
mkdir -p bin
156-
if [ "$RUNNER_OS" = "Windows" ]; then
157-
curl -fL -H "X-Download-Token: ${FFMPEG_TOKEN}" "${FFMPEG_BASE_URL}/ffmpeg-windows-amd64.exe" -o "bin/ffmpeg-windows-amd64.exe"
158-
elif [ "$RUNNER_OS" = "macOS" ]; then
159-
arch="arm64"
160-
if [ "$(uname -m)" = "x86_64" ]; then
161-
arch="amd64"
162-
fi
163-
curl -fL -H "X-Download-Token: ${FFMPEG_TOKEN}" "${FFMPEG_BASE_URL}/ffmpeg-darwin-${arch}" -o "bin/ffmpeg-darwin-${arch}"
165+
if [ "${TARGET_OS}" = "windows" ]; then
166+
ffmpeg_name="ffmpeg-windows-${TARGET_ARCH}.exe"
164167
else
165-
arch="amd64"
166-
if [ "$(uname -m)" = "aarch64" ]; then
167-
arch="arm64"
168-
fi
169-
curl -fL -H "X-Download-Token: ${FFMPEG_TOKEN}" "${FFMPEG_BASE_URL}/ffmpeg-linux-${arch}" -o "bin/ffmpeg-linux-${arch}"
168+
ffmpeg_name="ffmpeg-${TARGET_OS}-${TARGET_ARCH}"
170169
fi
171-
task package:with-ffmpeg NFPM_CONFIG=./build/linux/nfpm/nfpm-with-ffmpeg.yaml
170+
curl -fL -H "X-Download-Token: ${FFMPEG_TOKEN}" "${FFMPEG_BASE_URL}/${ffmpeg_name}" -o "bin/${ffmpeg_name}"
171+
task package:with-ffmpeg ARCH="${TARGET_ARCH}" NFPM_CONFIG=./build/linux/nfpm/nfpm-with-ffmpeg.yaml
172172
173173
- name: Collect artifacts (with ffmpeg)
174174
shell: bash
175-
# 保持文件名唯一,避免上传冲突。
176175
run: |
177176
mkdir -p dist
178177
shopt -s nullglob
179178
version="${PACKAGE_VERSION}"
180179
suffix="ffmpeg"
181-
if [ "$RUNNER_OS" = "Windows" ]; then
182-
if [ -f "bin/AI-ViewNote.exe" ]; then
183-
cp "bin/AI-ViewNote.exe" "dist/AI-ViewNote-${version}-$suffix.exe"
184-
fi
180+
181+
if [ "${TARGET_OS}" = "windows" ]; then
185182
for f in bin/AI-ViewNote-*-installer.exe; do
186183
base=$(basename "$f")
187-
cp "$f" "dist/${base%.exe}-${version}-$suffix.exe"
188-
done
189-
for f in bin/*.msix; do
190-
base=$(basename "$f")
191-
cp "$f" "dist/${base%.msix}-${version}-$suffix.msix"
184+
cp "$f" "dist/${base%.exe}-${version}-${suffix}.exe"
192185
done
193-
elif [ "$RUNNER_OS" = "macOS" ]; then
186+
elif [ "${TARGET_OS}" = "darwin" ]; then
194187
if [ -d "bin/AI-ViewNote.app" ]; then
195-
ditto -c -k --sequesterRsrc --keepParent "bin/AI-ViewNote.app" "dist/AI-ViewNote-macos-${version}-$suffix.app.zip"
188+
ditto -c -k --sequesterRsrc --keepParent "bin/AI-ViewNote.app" "dist/AI-ViewNote-macos-${TARGET_ARCH}-${version}-${suffix}.app.zip"
196189
fi
197190
else
198-
if [ -f "bin/AI-ViewNote" ]; then
199-
cp "bin/AI-ViewNote" "dist/AI-ViewNote-${version}-$suffix"
200-
fi
201191
for f in bin/*.AppImage; do
202192
base=$(basename "$f")
203-
cp "$f" "dist/${base%.AppImage}-${version}-$suffix.AppImage"
193+
cp "$f" "dist/${base%.AppImage}-${version}-${suffix}-${TARGET_ARCH}.AppImage"
204194
done
205195
for f in bin/*.deb; do
206196
base=$(basename "$f")
207-
cp "$f" "dist/${base%.deb}-${version}-$suffix.deb"
197+
cp "$f" "dist/${base%.deb}-${version}-${suffix}-${TARGET_ARCH}.deb"
208198
done
209199
for f in bin/*.rpm; do
210200
base=$(basename "$f")
211-
cp "$f" "dist/${base%.rpm}-${version}-$suffix.rpm"
201+
cp "$f" "dist/${base%.rpm}-${version}-${suffix}-${TARGET_ARCH}.rpm"
212202
done
213203
for f in bin/*.pkg.tar.zst; do
214204
base=$(basename "$f")
215-
cp "$f" "dist/${base%.pkg.tar.zst}-${version}-$suffix.pkg.tar.zst"
205+
cp "$f" "dist/${base%.pkg.tar.zst}-${version}-${suffix}-${TARGET_ARCH}.pkg.tar.zst"
216206
done
217207
fi
218208
219209
- name: Upload release assets
220210
uses: softprops/action-gh-release@v2
221211
if: github.event_name == 'release'
222212
with:
223-
# 上传 dist 中的所有产物到 Release。
224213
files: dist/**
225214

226215
- name: Upload artifacts (manual)
227216
uses: actions/upload-artifact@v4
228217
if: github.event_name == 'workflow_dispatch'
229218
with:
230-
# 手动触发时上传到 Actions 产物。
231-
name: dist-${{ runner.os }}
219+
name: dist-${{ matrix.target_os }}-${{ matrix.arch }}
232220
path: dist/**

0 commit comments

Comments
 (0)