Skip to content

Commit dd90b57

Browse files
committed
fix: 修复 CI 脚本的细节问题
- get_version.py: git push/tag 加 check=True,修复风格(返回类型注解 + raise SystemExit) - prepare_release_assets.py: 删除死代码 last_err,修正步骤注释序号 - installer_interface.py: 路径安全检查改用 is_relative_to(),语义更清晰
1 parent 5203cdc commit dd90b57

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/one_dragon_qt/view/installer_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _copy_by_manifest_then_cleanup(self, src_root: Path, dst_root: Path) -> bool
108108

109109
# 安全:只允许搬运 src_root 下的内容
110110
try:
111-
if src_root.resolve() not in [src_path.resolve(), *src_path.resolve().parents]:
111+
if not src_path.resolve().is_relative_to(src_root.resolve()):
112112
continue
113113
except Exception:
114114
continue
@@ -167,7 +167,7 @@ def _copy_by_manifest_then_cleanup(self, src_root: Path, dst_root: Path) -> bool
167167
break
168168
# 只处理 src_root 下的目录
169169
try:
170-
if src_root.resolve() not in parent.resolve().parents and parent.resolve() != src_root.resolve():
170+
if not parent.resolve().is_relative_to(src_root.resolve()):
171171
break
172172
except Exception:
173173
# resolve 失败时,退化为字符串前缀判断

tools/ci/get_version.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from datetime import UTC, datetime, timedelta
55

66

7-
def main():
7+
def main() -> int:
88
github_ref = os.environ.get('GITHUB_REF', '')
99
create_release = os.environ.get('CREATE_RELEASE', 'false').lower() == 'true'
1010
github_output = os.environ.get('GITHUB_OUTPUT')
@@ -72,8 +72,11 @@ def main():
7272

7373
if should_push_tag:
7474
print(f"Creating and pushing new tag: {tag}")
75-
subprocess.run(['git', '-c', 'user.name=GitHub Actions', '-c', 'user.email=actions@github.com', 'tag', tag])
76-
subprocess.run(['git', 'push', 'origin', tag])
75+
subprocess.run(['git', '-c', 'user.name=GitHub Actions', '-c', 'user.email=actions@github.com', 'tag', tag], check=True)
76+
subprocess.run(['git', 'push', 'origin', tag], check=True)
77+
78+
return 0
79+
7780

7881
if __name__ == "__main__":
79-
main()
82+
raise SystemExit(main())

tools/ci/prepare_release_assets.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,18 @@ def _download(url: str, dest: Path, *, token: str | None = None, retries: int =
2929
if token:
3030
headers["Authorization"] = f"Bearer {token}"
3131

32-
last_err: Exception | None = None
3332
for attempt in range(1, retries + 1):
3433
try:
3534
req = urllib.request.Request(url, headers=headers)
3635
with urllib.request.urlopen(req, timeout=timeout) as resp, dest.open("wb") as f:
3736
shutil.copyfileobj(resp, f)
3837
return
3938
except Exception as e:
40-
last_err = e
4139
if attempt < retries:
4240
time.sleep(2 * attempt)
4341
else:
4442
raise
4543

46-
if last_err:
47-
raise last_err
48-
4944

5045
def _fetch_json(url: str, *, token: str | None = None, timeout: int = 60) -> object:
5146
headers = {
@@ -292,15 +287,15 @@ def expand_zip_into_named_folder(url: str, download_path: Path, dest_root: Path,
292287
# 清理临时模型目录(避免打包进 Full/Full-Environment)
293288
shutil.rmtree(temp_dir, ignore_errors=True)
294289

295-
# 6. Full 包清单 + 打包(在 repo_root 下打包全部内容;zip 输出在 dist_dir 以避免自包含)
290+
# 7. Full 包清单 + 打包(在 repo_root 下打包全部内容;zip 输出在 dist_dir 以避免自包含)
296291
_log("Generate install manifest (Full)")
297292
_run([sys.executable, "tools/ci/generate_install_manifest.py", "--output", "install_manifest.json"], cwd=repo_root)
298293

299294
full_zip = dist_dir / f"ZenlessZoneZero-OneDragon-{release_version}-Full.zip"
300295
_log(f"Create Full zip: {full_zip}")
301296
_zip_dir_contents(repo_root, full_zip, root_prefix=f"ZenlessZoneZero-OneDragon-{release_version}-Full")
302297

303-
# 7. Full-Environment:把环境包放入 .install 后重新生成清单并打包
298+
# 8. Full-Environment:把环境包放入 .install 后重新生成清单并打包
304299
env_zip = dist_dir / "ZenlessZoneZero-OneDragon-Environment.zip"
305300
if not env_zip.exists():
306301
raise SystemExit(f"Missing {env_zip}")
@@ -314,10 +309,10 @@ def expand_zip_into_named_folder(url: str, download_path: Path, dest_root: Path,
314309
_log(f"Create Full-Environment zip: {full_env_zip}")
315310
_zip_dir_contents(repo_root, full_env_zip, root_prefix=f"ZenlessZoneZero-OneDragon-{release_version}-Full-Environment")
316311

317-
# 8. 复制安装器到版本化文件名
312+
# 9. 复制安装器到版本化文件名
318313
shutil.copy2(repo_root / "OneDragon-Installer.exe", repo_root / f"ZenlessZoneZero-OneDragon-{release_version}-Installer.exe")
319314

320-
# 9. 把 dist_dir 下所有 zip 移到 repo_root,供 release step 上传
315+
# 10. 把 dist_dir 下所有 zip 移到 repo_root,供 release step 上传
321316
for z in dist_dir.glob("*.zip"):
322317
_log(f"Move zip to repo root: {z.name}")
323318
shutil.move(str(z), str(repo_root / z.name))

0 commit comments

Comments
 (0)