-
Notifications
You must be signed in to change notification settings - Fork 8
243 lines (212 loc) · 7.43 KB
/
Copy pathbuild.yml
File metadata and controls
243 lines (212 loc) · 7.43 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
name: Build NFO Tools
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
env:
PYTHONUNBUFFERED: 1
PYTHONUTF8: 1
PYTHONDONTWRITEBYTECODE: 1
jobs:
build:
runs-on: windows-latest
timeout-minutes: 30 # 增加超时时间
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置 Python 版本
uses: actions/setup-python@v5
with:
python-version: '3.9.13'
cache: 'pip'
check-latest: false
- name: 缓存PyInstaller工作目录
uses: actions/cache@v4
with:
path: |
build
dist/shared
key: ${{ runner.os }}-pyinstaller-${{ hashFiles('*.py', 'requirements.txt') }}
restore-keys: |
${{ runner.os }}-pyinstaller-
- name: 安装依赖
run: |
python -m pip install --upgrade pip wheel setuptools
pip install -r requirements.txt
pip install pyinstaller==6.3.0
- name: 设置构建名称
id: set_build_name
shell: pwsh
run: |
git fetch --tags
$latestTag = git describe --tags $(git rev-list --tags --max-count=1)
if ($null -eq $latestTag) {
Write-Error "未找到任何标签,无法继续。"
exit 1
}
echo "build_name=$latestTag" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: 构建应用
shell: pwsh
run: |
# 构建前清理
Remove-Item -Path "dist" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "build" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "shared_libs" -Recurse -Force -ErrorAction SilentlyContinue
# 创建必要目录
New-Item -Path "dist/NFOTools" -ItemType Directory -Force
New-Item -Path "shared_libs" -ItemType Directory -Force
# 定义共同的 PyInstaller 参数
$commonArgs = @(
"--distpath", "./dist/shared",
"--workpath", "./build/shared",
"--onedir",
"--noconsole",
"--hidden-import", "win32com",
"--hidden-import", "win32com.client",
"--hidden-import", "win32com.shell",
"--hidden-import", "pythoncom",
"--hidden-import", "pywintypes",
"--hidden-import", "PIL",
"--hidden-import", "PIL._imaging",
"--hidden-import", "PIL.Image"
)
# 构建 NFO.Editor.Qt5
$editorArgs = $commonArgs + @(
"--name", "NFO.Editor.Qt5",
"--icon", "chuizi.ico",
"--add-data", "*.ico;.",
"--add-data", "mapping_actor.xml;.",
"--add-data", "Img;Img",
"--hidden-import", "win32com.shell.shellcon",
"--hidden-import", "win32wnet",
"--hidden-import", "winshell",
"-y",
"NFO.Editor.Qt5.py"
)
& pyinstaller $editorArgs
Move-Item -Path "dist/shared/NFO.Editor.Qt5/NFO.Editor.Qt5.exe" -Destination "dist/NFOTools/"
if (Test-Path "dist/shared/NFO.Editor.Qt5/PyQt5") {
Move-Item -Path "dist/shared/NFO.Editor.Qt5/PyQt5" -Destination "shared_libs/"
}
if (Test-Path "dist/shared/NFO.Editor.Qt5/_internal") {
Move-Item -Path "dist/shared/NFO.Editor.Qt5/_internal" -Destination "shared_libs/"
}
Remove-Item -Path "dist/shared/NFO.Editor.Qt5" -Recurse -Force
# 构建 cg_crop
$cgCropArgs = $commonArgs + @(
"--name", "cg_crop",
"--icon", "cg_crop.ico",
"--add-data", "cg_crop.ico;.",
"--add-data", "Img;Img",
"-y",
"cg_crop.py"
)
& pyinstaller $cgCropArgs
Move-Item -Path "dist/shared/cg_crop/cg_crop.exe" -Destination "dist/NFOTools/"
Remove-Item -Path "dist/shared/cg_crop" -Recurse -Force
# 构建 cg_rename
$cgRenameArgs = $commonArgs + @(
"--name", "cg_rename",
"--icon", "chuizi.ico",
"--add-data", "chuizi.ico;.",
"--add-data", "mapping_actor.xml;.",
"-y",
"cg_rename.py"
)
& pyinstaller $cgRenameArgs
Move-Item -Path "dist/shared/cg_rename/cg_rename.exe" -Destination "dist/NFOTools/"
Remove-Item -Path "dist/shared/cg_rename" -Recurse -Force
# 构建 cg_dedupe
$cgDedupeArgs = $commonArgs + @(
"--name", "cg_dedupe",
"--icon", "cg_dedupe.ico",
"--add-data", "cg_dedupe.ico;.",
"-y",
"cg_dedupe.py"
)
& pyinstaller $cgDedupeArgs
Move-Item -Path "dist/shared/cg_dedupe/cg_dedupe.exe" -Destination "dist/NFOTools/"
Remove-Item -Path "dist/shared/cg_dedupe" -Recurse -Force
# 构建 cg_photo_wall
$cgPhotoWallArgs = $commonArgs + @(
"--name", "cg_photo_wall",
"--icon", "cg_photo_wall.ico",
"--add-data", "cg_photo_wall.ico;.",
"-y",
"cg_photo_wall.py"
)
& pyinstaller $cgPhotoWallArgs
Move-Item -Path "dist/shared/cg_photo_wall/cg_photo_wall.exe" -Destination "dist/NFOTools/"
Remove-Item -Path "dist/shared/cg_photo_wall" -Recurse -Force
# 移动共享依赖到最终目录
Copy-Item -Path "shared_libs/*" -Destination "dist/NFOTools/" -Recurse -Force
# 移动额外资源文件
Copy-Item -Path "Img" -Destination "dist/NFOTools/" -Recurse -Force
Copy-Item -Path "mapping_actor.xml" -Destination "dist/NFOTools/" -Force
- name: 检查构建结果
shell: pwsh
run: |
$requiredFiles = @(
"NFO.Editor.Qt5.exe",
"cg_crop.exe",
"cg_rename.exe",
"cg_dedupe.exe",
"cg_photo_wall.exe",
"mapping_actor.xml"
)
foreach ($file in $requiredFiles) {
$path = "dist/NFOTools/$file"
if (-not (Test-Path $path)) {
Write-Error "构建失败:找不到必需文件 $file"
exit 1
}
}
- name: 创建ZIP包
shell: pwsh
run: |
Compress-Archive -Path "dist/NFOTools/*" -DestinationPath "NFOTools.${{ env.build_name }}.zip" -Force
- name: 上传构建工件
uses: actions/upload-artifact@v4
with:
name: nfo-tools-release
path: NFOTools.${{ env.build_name }}.zip
retention-days: 7
release:
needs: build
runs-on: windows-latest
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置构建名称
id: set_build_name
shell: pwsh
run: |
git fetch --tags
$latestTag = git describe --tags $(git rev-list --tags --max-count=1)
if ($null -eq $latestTag) {
Write-Error "未找到任何标签,无法继续。"
exit 1
}
echo "build_name=$latestTag" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: 下载构建工件
uses: actions/download-artifact@v4
with:
name: nfo-tools-release
path: dist
- name: 创建 Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ env.build_name }}
tag_name: ${{ env.build_name }}
draft: false
prerelease: false
files: dist/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}