-
Notifications
You must be signed in to change notification settings - Fork 0
400 lines (360 loc) · 14.3 KB
/
install.yml
File metadata and controls
400 lines (360 loc) · 14.3 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# 自动化构建与发布工作流
# 负责跨平台编译、打包和发布MaaDuDuL项目
name: install
# 触发条件
on:
push:
tags:
- "v*" # 仅在推送v开头的标签时触发(如v1.0.0)
# 注释掉分支和路径触发,避免频繁构建
# branches:
# - "**"
# paths:
# - ".github/workflows/install.yml"
# - "assets/**"
# - "**.py"
pull_request: # PR触发条件
branches:
- "**" # 所有分支的PR
paths: # 仅当以下文件变更时触发
- ".github/workflows/install.yml"
- "assets/**"
- "**.py"
workflow_dispatch: # 允许手动触发
jobs:
# 任务1: 生成版本元数据
meta:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取完整的git历史,用于版本号生成
- id: set_tag
name: 设置版本标签
run: |
# 检查是否为正式发布(基于v*标签)
is_release=${{ startsWith(github.ref, 'refs/tags/v') }}
# 尝试从git获取标签
tag=$(git describe --tags --match "v*" ${{ github.ref }} || true)
# 如果没有找到v*标签,则从GitHub API获取最新发布版本
if [[ $tag != v* ]]; then
tag=$(curl -sX GET "https://api.github.com/repos/${{ github.repository }}/releases/latest" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | awk '/tag_name/{print $4}' FS='["!]')
# 如果仍然没有找到,使用默认版本v0.0.0
if [[ $tag != v* ]]; then
tag="v0.0.0"
fi
# 为CI构建添加日期和commit hash
tag=$(date "+$tag-%y%m%d-$(git rev-parse --short HEAD)")
fi
# 非正式发布版本添加ci标记
if ! $($is_release) ; then
prefix=${tag%-*-*}
suffix=${tag#$prefix-}
tag="$prefix-ci.$suffix"
fi
# 检查是否为预发布版本(包含alpha/beta/rc/dev/ci关键字)
is_prerelease=false
if [[ $tag =~ .*alpha.* || $tag =~ .*beta.* || $tag =~ .*rc.* || $tag =~ .*dev.* || $tag =~ .*-ci.* ]]; then
is_prerelease=true
echo "This is a pre-release version"
fi
# 输出版本信息供后续任务使用
echo tag=$tag | tee -a $GITHUB_OUTPUT
echo is_release=$is_release | tee -a $GITHUB_OUTPUT
echo is_prerelease=$is_prerelease | tee -a $GITHUB_OUTPUT
outputs:
tag: ${{ steps.set_tag.outputs.tag }}
is_release: ${{ steps.set_tag.outputs.is_release }}
is_prerelease: ${{ steps.set_tag.outputs.is_prerelease }}
# 任务2: 多平台构建与打包
install:
needs: meta # 依赖meta任务完成
runs-on: ${{ matrix.runs-on }} # 根据目标平台选择运行环境
strategy:
matrix:
include:
# Windows 构建
- os: win
arch: x86_64
runs-on: windows-latest
- os: win
arch: aarch64
runs-on: windows-latest
# macOS 构建
- os: macos
arch: x86_64
runs-on: macos-latest
is_macos: true
- os: macos
arch: aarch64
runs-on: macos-latest
is_macos: true
# Linux 构建
- os: linux
arch: x86_64
runs-on: ubuntu-latest
- os: linux
arch: aarch64
runs-on: ubuntu-latest
fail-fast: false # 允许部分构建失败时继续其他构建
steps:
- uses: actions/checkout@v4
with:
submodules: true # 同时检出子模块
# 读取版本配置文件
- name: 读取依赖版本配置
id: versions
shell: bash
run: |
# 读取versions.json并设置为环境变量
MAA_FRAMEWORK_VERSION=$(jq -r '.MaaFramework' .github/versions.json)
MFAA_VERSION=$(jq -r '.MFAAvalonia' .github/versions.json)
echo "MAA_FRAMEWORK_VERSION=$MAA_FRAMEWORK_VERSION" >> $GITHUB_OUTPUT
echo "MFAA_VERSION=$MFAA_VERSION" >> $GITHUB_OUTPUT
echo "MaaFramework版本: $MAA_FRAMEWORK_VERSION"
echo "MFAAvalonia版本: $MFAA_VERSION"
# MaaFramework下载
# - name: Download MaaFramework
# uses: robinraju/release-downloader@v1
# with:
# repository: MaaXYZ/MaaFramework
# fileName: "MAA-${{ matrix.os }}-${{ matrix.arch }}*" # 匹配对应平台的文件
# tag: ${{ steps.versions.outputs.MAA_FRAMEWORK_VERSION }} # 从versions.json读取版本
# out-file-path: "mfw_temp" # 临时输出目录
# extract: true # 自动解压
# 清理MaaFramework压缩包
# - name: Clean MaaFramework archives
# shell: bash
# run: |
# echo "清理MaaFramework压缩包文件..."
# rm -f mfw_temp/MAA-*.zip mfw_temp/MAA-*.tar.gz mfw_temp/MAA-*.7z
# echo "压缩包清理完成"
# 设置Python环境
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
# 设置嵌入式Python环境(Windows)
- name: Setup Embed Python (Windows)
if: matrix.os == 'win'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
& ./ci/setup_embed_python.ps1
# 设置嵌入式Python环境(macOS)
- name: Setup Embed Python (macOS)
if: matrix.os == 'macos'
shell: bash
run: |
chmod +x ./ci/setup_embed_python.sh
./ci/setup_embed_python.sh
# 设置嵌入式Python环境(Linux)
- name: Setup Embed Python (Linux)
if: matrix.os == 'linux'
shell: bash
run: |
chmod +x ./ci/setup_embed_python.sh
./ci/setup_embed_python.sh
# 合并Pipeline配置文件
- name: Merge Pipeline
shell: bash
run: |
python -u ./ci/merge_pipeline.py # -u参数确保实时输出
# 安装项目资源文件
- name: Install Resource
shell: bash
run: |
cd tools/
python -m pip install -r ./requirements.txt # 安装依赖
python ./install.py ${{ needs.meta.outputs.tag }} ${{ matrix.os }} # 执行安装脚本,传递平台参数
cd ..
# 映射MFAAvalonia的平台和架构命名
# MFA使用不同的命名规则:macos→osx, x86_64→x64, aarch64→arm64
- name: Set up MFAAvalonia naming
id: mfa_naming
shell: bash
run: |
# 平台命名映射
if [ "${{ matrix.os }}" = "win" ]; then
echo "mfa_os=win" >> $GITHUB_OUTPUT
elif [ "${{ matrix.os }}" = "macos" ]; then
echo "mfa_os=osx" >> $GITHUB_OUTPUT # macOS在MFA中称为osx
elif [ "${{ matrix.os }}" = "linux" ]; then
echo "mfa_os=linux" >> $GITHUB_OUTPUT
else
echo "mfa_os=unknown" >> $GITHUB_OUTPUT
fi
# 架构命名映射
if [ "${{ matrix.arch }}" = "x86_64" ]; then
echo "mfa_arch=x64" >> $GITHUB_OUTPUT
elif [ "${{ matrix.arch }}" = "aarch64" ]; then
echo "mfa_arch=arm64" >> $GITHUB_OUTPUT
else
echo "mfa_arch=unknown" >> $GITHUB_OUTPUT
fi
# 下载MFAAvalonia GUI程序
- name: Download MFAAvalonia
if: steps.mfa_naming.outputs.mfa_os != 'unknown' && steps.mfa_naming.outputs.mfa_arch != 'unknown'
id: download_mfa
uses: robinraju/release-downloader@v1
with:
repository: SweetSmellFox/MFAAvalonia
fileName: "MFAAvalonia-*-${{ steps.mfa_naming.outputs.mfa_os }}-${{ steps.mfa_naming.outputs.mfa_arch }}*"
tag: ${{ steps.versions.outputs.MFAA_VERSION }} # 从versions.json读取版本
out-file-path: "MFA"
extract: true
# 修改MFAAvalonia.exe图标(仅Windows x86_64)
- name: Modify MFAAvalonia exe icon
if: matrix.os == 'win' && matrix.arch == 'x86_64'
shell: bash
run: |
# 下载 rcedit
curl -L https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe -o rcedit.exe
# 修改 exe 图标
./rcedit.exe "MFA/MFAAvalonia.exe" --set-icon "public/logo.ico"
echo "MFAAvalonia icon modified successfully"
# 安装MFAAvalonia到install目录
- name: Install MFAAvalonia
shell: bash
run: |
rm -rf MFA/resource/base/model/ocr # 删除MFA自带的 OCR model目录
mkdir -p install # 创建安装目录
cp -r MFA/* install/ # 复制所有MFA文件
rm -f install/MFAAvalonia-*.zip install/MFAAvalonia-*.tar.gz # 清理下载的压缩包
# 清理MFAA自带的deps文件夹内容
# if [ -d "install/deps" ]; then
# echo "清理MFAA自带的deps目录..."
# rm -rf install/deps/*
# else
# echo "创建deps目录..."
# mkdir -p install/deps
# fi
# 部署MaaFramework到deps目录
# - name: Deploy MaaFramework to deps
# shell: bash
# run: |
# # 将下载的MaaFramework移动到deps目录
# if [ -d "mfw_temp" ]; then
# echo "将MaaFramework部署到install/deps/目录..."
# cp -r mfw_temp/* install/deps/
# echo "MaaFramework部署完成,文件列表:"
# ls -la install/deps/
# rm -rf mfw_temp # 清理临时目录
# echo "临时目录已清理"
# else
# echo "错误: MaaFramework临时目录(mfw_temp)不存在"
# exit 1
# fi
# 配置descs说明文件
- name: Install descs to Resource
shell: bash
run: |
if [ -d "assets/resource/descs" ]; then
mkdir -p install/Resource # 确保Resource目录存在
cp -r assets/resource/descs install/Resource/descs # 复制descs到Resource下
else
echo "Warning: assets/resource/descs folder not found"
fi
if [ -d "assets/resource/descs_en" ]; then
mkdir -p install/Resource
cp -r assets/resource/descs_en install/Resource/descs_en
else
echo "Warning: assets/resource/descs_en folder not found"
fi
# 替换应用图标
- name: Replace Icon
shell: bash
run: |
if [ -f "public/logo.ico" ]; then
mkdir -p install/Assets # 确保Assets目录存在
cp public/logo.ico install/Assets/logo.ico
fi
# 打包启动器(Windows平台)
- name: Packing Launcher (Windows)
if: matrix.os == 'win'
working-directory: launcher
shell: bash
run: |
python -m pip install pyinstaller
# 打包为单文件exe,带图标,无控制台窗口
pyinstaller --onefile --icon=../public/logo.ico --windowed MaaDuDuL.py
cp dist/MaaDuDuL.exe ../install/MaaDuDuL.exe
# 打包启动器(macOS平台)
- name: Packing Launcher (macOS)
if: matrix.os == 'macos'
working-directory: launcher
shell: bash
run: |
python -m pip install pyinstaller
# macOS不使用图标和windowed参数,打包为单文件
pyinstaller --onefile MaaDuDuL.py
cp dist/MaaDuDuL ../install/MaaDuDuL
chmod +x ../install/MaaDuDuL # 添加执行权限
# 打包启动器(Linux平台)
- name: Packing Launcher (Linux)
if: matrix.os == 'linux'
working-directory: launcher
shell: bash
run: |
python -m pip install pyinstaller
# Linux打包为单文件
pyinstaller --onefile MaaDuDuL.py
cp dist/MaaDuDuL ../install/MaaDuDuL
chmod +x ../install/MaaDuDuL # 添加执行权限
# 上传构建产物
- uses: actions/upload-artifact@v4
with:
name: MaaDuDuL-${{ matrix.os }}-${{ matrix.arch }} # 以平台-架构命名
path: "install" # 上传install目录
# 任务3: 读取更新日志
changelog:
name: Read changelog
runs-on: ubuntu-latest
outputs:
release_body: ${{ steps.read_changelog.outputs.content }}
steps:
- name: Checkout
uses: actions/checkout@v4
# 直接读取Changelog.md文件内容
- name: Read Changelog.md
id: read_changelog
run: |
# 读取Changelog.md,跳过前3行,然后在前面添加Mirror酱链接
MIRROR_LINK="[已有 Mirror 酱?点击前往高速下载!](https://mirrorchyan.com/zh/projects?rid=MaaDuDuL&source=mddl-release&os=windows&arch=x64&channel=stable)"
CHANGELOG_CONTENT=$(tail -n +4 assets/resource/Changelog.md)
echo "content<<EOF" >> $GITHUB_OUTPUT
echo "$MIRROR_LINK" >> $GITHUB_OUTPUT
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# 任务4: 发布到GitHub Releases(仅正式版本)
release:
if: ${{ needs.meta.outputs.is_release == 'true' }} # 仅在正式发布时执行
needs: [meta, install, changelog] # 依赖前三个任务
runs-on: ubuntu-latest
steps:
# 下载所有构建产物
- uses: actions/download-artifact@v4
with:
path: assets
# 打包所有产物为zip文件
- name: 打包发布文件
run: |
cd assets
for f in *; do
(cd $f && zip -r ../$f-${{ needs.meta.outputs.tag }}.zip .)
done
# 创建GitHub Release
- uses: softprops/action-gh-release@v2
with:
files: assets/* # 上传所有打包文件
tag_name: ${{ needs.meta.outputs.tag }} # 使用版本标签
body: ${{ needs.changelog.outputs.release_body }} # 使用生成的changelog
draft: false # 不设为草稿
prerelease: ${{ needs.meta.outputs.is_prerelease == 'true' }} # 标记预发布
- name: Trigger MirrorChyanUploading
shell: bash
run: |
gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan_release.yml -f tag=${{ needs.meta.outputs.tag }}
gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan_release_note.yml -f tag=${{ needs.meta.outputs.tag }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}