优化打包流程,增加编译路径和忽略规则
This commit is contained in:
@@ -57,6 +57,9 @@ jobs:
|
||||
shutil.rmtree(d)
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 编译路径(与 scripts/compile.py 保持一致)
|
||||
compile_dirs = ["app/services", "app/native/wndb", "app/algorithms"]
|
||||
# 全局忽略的项目
|
||||
ignore_names = {
|
||||
".git",
|
||||
".github",
|
||||
@@ -72,12 +75,22 @@ jobs:
|
||||
}
|
||||
|
||||
def ignore_func(directory, names):
|
||||
# 获取当前处理目录相对于根目录的路径(统一使用正斜杠)
|
||||
rel_dir = os.path.relpath(directory, root).replace("\\", "/")
|
||||
# 判断当前目录是否处于需要编译的路径下
|
||||
is_in_compile_path = any(rel_dir.startswith(d) for d in compile_dirs)
|
||||
|
||||
ignored = []
|
||||
for name in names:
|
||||
# 忽略全局黑名单或编译产生的临时 pyc 文件
|
||||
if name in ignore_names or name.endswith(".pyc"):
|
||||
ignored.append(name)
|
||||
# 如果在编译路径下,则忽略 .py 源码文件(保留编译后的二进制产物)
|
||||
elif is_in_compile_path and name.endswith(".py"):
|
||||
ignored.append(name)
|
||||
return ignored
|
||||
|
||||
# 遍历根目录进行复制
|
||||
for item in root.iterdir():
|
||||
if item.name in ignore_names:
|
||||
continue
|
||||
@@ -87,9 +100,15 @@ jobs:
|
||||
else:
|
||||
shutil.copy2(item, target)
|
||||
|
||||
# 安全防护:确保产物中不含 .github 目录
|
||||
github_paths = [p for p in package_dir.rglob(".github") if p.is_dir()]
|
||||
for p in github_paths:
|
||||
shutil.rmtree(p, ignore_errors=True)
|
||||
|
||||
sha = os.environ["GITHUB_SHA"]
|
||||
run_os = os.environ["RUNNER_OS"].lower()
|
||||
|
||||
# 根据操作系统创建相应的压缩包
|
||||
if run_os == "windows":
|
||||
archive_path = dist_dir / f"tjwater-server-{run_os}-{sha}.zip"
|
||||
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
|
||||
@@ -101,7 +120,7 @@ jobs:
|
||||
with tarfile.open(archive_path, "w:gz") as tf:
|
||||
tf.add(package_dir, arcname=".")
|
||||
|
||||
print(f"Archive created: {archive_path}")
|
||||
print(f"压缩包已创建: {archive_path}")
|
||||
PY
|
||||
shell: bash
|
||||
|
||||
|
||||
Reference in New Issue
Block a user