移除中文注释,避免 Github Action 工作流出错
This commit is contained in:
@@ -46,6 +46,7 @@ jobs:
|
|||||||
import shutil
|
import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
root = Path.cwd()
|
root = Path.cwd()
|
||||||
@@ -57,9 +58,9 @@ jobs:
|
|||||||
shutil.rmtree(d)
|
shutil.rmtree(d)
|
||||||
d.mkdir(parents=True, exist_ok=True)
|
d.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# 编译路径(与 scripts/compile.py 保持一致)
|
# Define directories with compiled artifacts
|
||||||
compile_dirs = ["app/services", "app/native/wndb", "app/algorithms"]
|
compile_dirs = ["app/services", "app/native/wndb", "app/algorithms"]
|
||||||
# 全局忽略的项目
|
# Global ignore list
|
||||||
ignore_names = {
|
ignore_names = {
|
||||||
".git",
|
".git",
|
||||||
".github",
|
".github",
|
||||||
@@ -75,22 +76,18 @@ jobs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def ignore_func(directory, names):
|
def ignore_func(directory, names):
|
||||||
# 获取当前处理目录相对于根目录的路径(统一使用正斜杠)
|
|
||||||
rel_dir = os.path.relpath(directory, root).replace("\\", "/")
|
rel_dir = os.path.relpath(directory, root).replace("\\", "/")
|
||||||
# 判断当前目录是否处于需要编译的路径下
|
|
||||||
is_in_compile_path = any(rel_dir.startswith(d) for d in compile_dirs)
|
is_in_compile_path = any(rel_dir.startswith(d) for d in compile_dirs)
|
||||||
|
|
||||||
ignored = []
|
ignored = []
|
||||||
for name in names:
|
for name in names:
|
||||||
# 忽略全局黑名单或编译产生的临时 pyc 文件
|
|
||||||
if name in ignore_names or name.endswith(".pyc"):
|
if name in ignore_names or name.endswith(".pyc"):
|
||||||
ignored.append(name)
|
ignored.append(name)
|
||||||
# 如果在编译路径下,则忽略 .py 源码文件(保留编译后的二进制产物)
|
# Exclude source .py files only in compiled directories
|
||||||
elif is_in_compile_path and name.endswith(".py"):
|
elif is_in_compile_path and name.endswith(".py"):
|
||||||
ignored.append(name)
|
ignored.append(name)
|
||||||
return ignored
|
return ignored
|
||||||
|
|
||||||
# 遍历根目录进行复制
|
|
||||||
for item in root.iterdir():
|
for item in root.iterdir():
|
||||||
if item.name in ignore_names:
|
if item.name in ignore_names:
|
||||||
continue
|
continue
|
||||||
@@ -100,7 +97,7 @@ jobs:
|
|||||||
else:
|
else:
|
||||||
shutil.copy2(item, target)
|
shutil.copy2(item, target)
|
||||||
|
|
||||||
# 安全防护:确保产物中不含 .github 目录
|
# Safety guard: ensure no .github directory remains
|
||||||
github_paths = [p for p in package_dir.rglob(".github") if p.is_dir()]
|
github_paths = [p for p in package_dir.rglob(".github") if p.is_dir()]
|
||||||
for p in github_paths:
|
for p in github_paths:
|
||||||
shutil.rmtree(p, ignore_errors=True)
|
shutil.rmtree(p, ignore_errors=True)
|
||||||
@@ -108,7 +105,6 @@ jobs:
|
|||||||
sha = os.environ["GITHUB_SHA"]
|
sha = os.environ["GITHUB_SHA"]
|
||||||
run_os = os.environ["RUNNER_OS"].lower()
|
run_os = os.environ["RUNNER_OS"].lower()
|
||||||
|
|
||||||
# 根据操作系统创建相应的压缩包
|
|
||||||
if run_os == "windows":
|
if run_os == "windows":
|
||||||
archive_path = dist_dir / f"tjwater-server-{run_os}-{sha}.zip"
|
archive_path = dist_dir / f"tjwater-server-{run_os}-{sha}.zip"
|
||||||
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
|
with zipfile.ZipFile(archive_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
|
||||||
@@ -120,7 +116,7 @@ jobs:
|
|||||||
with tarfile.open(archive_path, "w:gz") as tf:
|
with tarfile.open(archive_path, "w:gz") as tf:
|
||||||
tf.add(package_dir, arcname=".")
|
tf.add(package_dir, arcname=".")
|
||||||
|
|
||||||
print(f"压缩包已创建: {archive_path}")
|
print(f"Archive created: {archive_path}")
|
||||||
PY
|
PY
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user