Skip to content

Commit 202e13e

Browse files
committed
refactor(build): 移除重复的FeaturePacks复制逻辑并优化部署脚本
- 删除了各个平台构建工作流中的重复FeaturePacks复制步骤 - 将FeaturePacks复制逻辑统一到deploy.py脚本中 - 重构deploy.py以支持跨平台的特性包管理 - 添加了特性包黑名单过滤功能 - 统一了不同操作系统的部署参数配置 - 使用subprocess模块替代os.system执行命令 - 实现了更可靠的特性包复制和验证机制
1 parent 11da49c commit 202e13e

File tree

5 files changed

+131
-147
lines changed

5 files changed

+131
-147
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ jobs:
3838
python deploy.py
3939
mv dist/Ghost-Downloader-3.dist dist/Ghost-Downloader-3-Unsigned.dist
4040
41-
- name: Copy FeaturePacks
42-
shell: pwsh
43-
run: |
44-
$targetRoot = "dist/Ghost-Downloader-3-Unsigned.dist/features"
45-
New-Item -ItemType Directory -Force -Path $targetRoot | Out-Null
46-
47-
foreach ($pack in @("http_pack", "bili_pack", "ffmpeg_pack")) {
48-
$source = Join-Path "features" $pack
49-
$target = Join-Path $targetRoot $pack
50-
if (Test-Path $target) {
51-
Remove-Item -Recurse -Force $target
52-
}
53-
Copy-Item -Recurse -Force $source $target
54-
}
55-
5641
- name: upload-unsigned-artifact
5742
id: upload-unsigned-artifact
5843
uses: actions/upload-artifact@v4
@@ -135,16 +120,6 @@ jobs:
135120
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
136121
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
137122
138-
- name: Copy FeaturePacks
139-
run: |
140-
target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
141-
mkdir -p "$target_root"
142-
143-
for pack in http_pack bili_pack ffmpeg_pack; do
144-
rm -rf "$target_root/$pack"
145-
cp -R "features/$pack" "$target_root/$pack"
146-
done
147-
148123
- name: Create DMG
149124
run: |
150125
ln -s /Applications dist/Applications
@@ -209,16 +184,6 @@ jobs:
209184
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
210185
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
211186
212-
- name: Copy FeaturePacks
213-
run: |
214-
target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
215-
mkdir -p "$target_root"
216-
217-
for pack in http_pack bili_pack ffmpeg_pack; do
218-
rm -rf "$target_root/$pack"
219-
cp -R "features/$pack" "$target_root/$pack"
220-
done
221-
222187
- name: Reinstall openssl libs
223188
run: |
224189
brew install openssl@3
@@ -266,16 +231,6 @@ jobs:
266231
python deploy.py
267232
chmod +x "dist/Ghost-Downloader-3.dist/Ghost-Downloader-3.bin"
268233
269-
- name: Copy FeaturePacks
270-
run: |
271-
target_root="dist/Ghost-Downloader-3.dist/features"
272-
mkdir -p "$target_root"
273-
274-
for pack in http_pack bili_pack ffmpeg_pack; do
275-
rm -rf "$target_root/$pack"
276-
cp -R "features/$pack" "$target_root/$pack"
277-
done
278-
279234
- name: Tar the contents of Ghost-Downloader
280235
shell: pwsh
281236
run: |

.github/workflows/build_Linux.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ jobs:
3434
rm -rf version.txt
3535
python deploy.py
3636
37-
- name: Copy FeaturePacks
38-
run: |
39-
target_root="dist/Ghost-Downloader-3.dist/features"
40-
mkdir -p "$target_root"
41-
42-
for pack in http_pack bili_pack ffmpeg_pack; do
43-
rm -rf "$target_root/$pack"
44-
cp -R "features/$pack" "$target_root/$pack"
45-
done
46-
4737
- name: Upload artifacts
4838
uses: actions/upload-artifact@v4
4939
with:

.github/workflows/build_Windows.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,6 @@ jobs:
5050
del version.txt
5151
python deploy.py
5252
53-
- name: Copy FeaturePacks
54-
shell: pwsh
55-
run: |
56-
$targetRoot = "dist/Ghost-Downloader-3.dist/features"
57-
New-Item -ItemType Directory -Force -Path $targetRoot | Out-Null
58-
59-
foreach ($pack in @("http_pack", "bili_pack", "ffmpeg_pack")) {
60-
$source = Join-Path "features" $pack
61-
$target = Join-Path $targetRoot $pack
62-
if (Test-Path $target) {
63-
Remove-Item -Recurse -Force $target
64-
}
65-
Copy-Item -Recurse -Force $source $target
66-
}
67-
6853
- name: Prepare For Sign
6954
if: ${{ github.event.inputs.sign_artifact == 'true' }}
7055
run: |

.github/workflows/build_macOS.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ jobs:
3737
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
3838
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
3939
40-
- name: Copy FeaturePacks
41-
run: |
42-
target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
43-
mkdir -p "$target_root"
44-
45-
for pack in http_pack bili_pack ffmpeg_pack; do
46-
rm -rf "$target_root/$pack"
47-
cp -R "features/$pack" "$target_root/$pack"
48-
done
49-
5040
- name: Create DMG
5141
run: |
5242
ln -s /Applications dist/Applications
@@ -111,16 +101,6 @@ jobs:
111101
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
112102
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
113103
114-
- name: Copy FeaturePacks
115-
run: |
116-
target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
117-
mkdir -p "$target_root"
118-
119-
for pack in http_pack bili_pack ffmpeg_pack; do
120-
rm -rf "$target_root/$pack"
121-
cp -R "features/$pack" "$target_root/$pack"
122-
done
123-
124104
- name: Reinstall openssl libs
125105
run: |
126106
brew install openssl@3

deploy.py

Lines changed: 131 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,85 @@
1-
import os
1+
import shutil
2+
import subprocess
23
import sys
4+
from pathlib import Path
35

46
from app.supports.config import VERSION, YEAR, AUTHOR
57

6-
if sys.platform == "win32":
7-
args = [
8-
'nuitka',
9-
'--standalone', # Following all imports is the default for standalone mode and need not be specified.
10-
'--windows-console-mode=disable',
11-
'--plugin-enable=pyside6',
12-
'--include-package=urllib3',
13-
'--include-package=qrcode',
14-
'--include-package=winrt',
15-
'--include-module=app.supports.sysio',
16-
'--assume-yes-for-downloads',
17-
'--msvc=latest', # Use MSVC
18-
# '--mingw64', # Use MinGW
19-
# '--show-memory' ,
20-
# '--show-progress' ,
21-
'--windows-icon-from-ico=app/assets/logo.ico',
22-
'--company-name=XiaoYouChR',
23-
'--product-name="Ghost Downloader"',
24-
f'--file-version={VERSION}',
25-
f'--product-version={VERSION}',
26-
'--file-description="Ghost Downloader"',
27-
f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
28-
'--output-dir=dist',
29-
'Ghost-Downloader-3.py',
30-
]
8+
FEATURES_ROOT = Path("features")
9+
FEATURE_PACK_BLACKLIST = {"jack_yao"}
10+
COMMON_INCLUDE_PACKAGES = [
11+
"urllib3",
12+
"qrcode",
13+
"libtorrent"
14+
]
15+
PLATFORM_INCLUDE_PACKAGES = {
16+
"win32": [
17+
"winrt",
18+
],
19+
}
20+
INCLUDE_MODULES = [
21+
"app.supports.sysio",
22+
]
3123

32-
if "--onefile" in sys.argv:
33-
args.pop(args.index("--standalone"))
34-
args.insert(1, "--onefile")
35-
args.insert(1, "--onefile-cache-mode=cached")
3624

37-
elif sys.platform == "darwin":
38-
args = [
39-
'python3 -m nuitka',
40-
'--standalone',
41-
'--plugin-enable=pyside6',
42-
'--include-package=urllib3',
43-
'--include-package=qrcode',
44-
'--include-module=app.supports.sysio',
45-
# '--show-memory',
46-
# '--show-progress',
47-
'--static-libpython=no',
48-
"--macos-create-app-bundle",
49-
"--assume-yes-for-download",
50-
"--macos-app-mode=gui",
51-
f"--macos-app-version={VERSION}",
52-
"--macos-app-icon=app/assets/logo.icns",
53-
f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
54-
'--output-dir=dist',
55-
'Ghost-Downloader-3.py',
25+
def build_include_args() -> list[str]:
26+
include_packages = COMMON_INCLUDE_PACKAGES + PLATFORM_INCLUDE_PACKAGES.get(sys.platform, [])
27+
return [
28+
*[f"--include-package={package}" for package in include_packages],
29+
*[f"--include-module={module}" for module in INCLUDE_MODULES],
5630
]
57-
else:
58-
args = [
59-
'nuitka',
31+
32+
33+
def build_args() -> list[str]:
34+
nuitka_command = f'"{sys.executable}" -m nuitka'
35+
36+
if sys.platform == "win32":
37+
return [
38+
nuitka_command,
39+
'--standalone', # Following all imports is the default for standalone mode and need not be specified.
40+
'--windows-console-mode=disable',
41+
'--plugin-enable=pyside6',
42+
*build_include_args(),
43+
'--assume-yes-for-downloads',
44+
'--msvc=latest', # Use MSVC
45+
# '--mingw64', # Use MinGW
46+
# '--show-memory' ,
47+
# '--show-progress' ,
48+
'--windows-icon-from-ico=app/assets/logo.ico',
49+
'--company-name=XiaoYouChR',
50+
'--product-name="Ghost Downloader"',
51+
f'--file-version={VERSION}',
52+
f'--product-version={VERSION}',
53+
'--file-description="Ghost Downloader"',
54+
f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
55+
'--output-dir=dist',
56+
'Ghost-Downloader-3.py',
57+
]
58+
59+
if sys.platform == "darwin":
60+
return [
61+
nuitka_command,
62+
'--standalone',
63+
'--plugin-enable=pyside6',
64+
*build_include_args(),
65+
# '--show-memory',
66+
# '--show-progress',
67+
'--static-libpython=no',
68+
"--macos-create-app-bundle",
69+
"--assume-yes-for-download",
70+
"--macos-app-mode=gui",
71+
f"--macos-app-version={VERSION}",
72+
"--macos-app-icon=app/assets/logo.icns",
73+
f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
74+
'--output-dir=dist',
75+
'Ghost-Downloader-3.py',
76+
]
77+
78+
return [
79+
nuitka_command,
6080
'--standalone',
6181
'--plugin-enable=pyside6',
62-
'--include-package=urllib3',
63-
'--include-package=qrcode',
64-
'--include-module=app.supports.sysio',
82+
*build_include_args(),
6583
'--include-qt-plugins=platforms',
6684
'--assume-yes-for-downloads',
6785
# '--show-memory',
@@ -71,5 +89,61 @@
7189
'Ghost-Downloader-3.py',
7290
]
7391

74-
print(args)
75-
os.system(' '.join(args))
92+
93+
def get_feature_pack_sources() -> list[Path]:
94+
if not FEATURES_ROOT.is_dir():
95+
raise FileNotFoundError(f"FeaturePacks source directory not found: {FEATURES_ROOT}")
96+
97+
return sorted(
98+
(
99+
item
100+
for item in FEATURES_ROOT.iterdir()
101+
if item.is_dir()
102+
and item.name not in FEATURE_PACK_BLACKLIST
103+
and (item / "manifest.toml").is_file()
104+
),
105+
key=lambda item: item.name,
106+
)
107+
108+
109+
def get_feature_pack_target_root() -> Path:
110+
if sys.platform == "darwin":
111+
return Path("dist") / "Ghost-Downloader-3.app" / "Contents" / "MacOS" / "features"
112+
return Path("dist") / "Ghost-Downloader-3.dist" / "features"
113+
114+
115+
def copy_feature_packs() -> None:
116+
feature_pack_sources = get_feature_pack_sources()
117+
if not feature_pack_sources:
118+
raise RuntimeError("No feature packs were found to copy.")
119+
120+
target_root = get_feature_pack_target_root()
121+
if not target_root.parent.exists():
122+
raise FileNotFoundError(f"FeaturePacks target directory does not exist: {target_root.parent}")
123+
124+
if target_root.exists():
125+
shutil.rmtree(target_root)
126+
target_root.mkdir(parents=True, exist_ok=True)
127+
128+
for source in feature_pack_sources:
129+
shutil.copytree(source, target_root / source.name)
130+
131+
print(f"Copied FeaturePacks to {target_root}: {[source.name for source in feature_pack_sources]}")
132+
133+
134+
def main() -> int:
135+
args = build_args()
136+
command = ' '.join(args)
137+
138+
print(command)
139+
result = subprocess.run(command, shell=True)
140+
if result.returncode != 0:
141+
return result.returncode
142+
143+
copy_feature_packs()
144+
145+
return 0
146+
147+
148+
if __name__ == "__main__":
149+
raise SystemExit(main())

0 commit comments

Comments
 (0)