-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.py
More file actions
56 lines (44 loc) · 1.88 KB
/
Copy pathverify.py
File metadata and controls
56 lines (44 loc) · 1.88 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
#!/usr/bin/env python3
"""verify.py — runs the local pre-push verification suite for a Flutter project.
verify.py — 运行 Flutter 项目推送前的本地校验流程。
Usage: python scripts/python/verify.py [--no-publish]
用法: python scripts/python/verify.py [--no-publish]
Runs: flutter analyze, flutter test, and (unless skipped) flutter pub publish --dry-run.
执行: flutter analyze、flutter test,以及(除非跳过)flutter pub publish --dry-run。
Exits non-zero if any step fails, so it can gate CI or a pre-push hook.
任一环节失败即以非零码退出,可用于 CI 或 pre-push 钩子拦截。
"""
import subprocess
import sys
def run(cmd, args):
"""Run [cmd] with [args]; return the process exit code.
运行 cmd 并传入 args,返回进程退出码。"""
print(f"\n> {cmd} {' '.join(args)}")
result = subprocess.run(
cmd, args if isinstance(args, list) else list(args),
shell=(sys.platform == "win32"), check=False,
)
return result.returncode
def main(argv):
"""Run the local pre-push verification suite. 运行本地推送前校验流程。"""
skip_publish = "--no-publish" in argv
# 1. Static analysis.
# 1. 静态分析。
if run("flutter", ["analyze"]) != 0:
sys.stderr.write("flutter analyze failed.\n")
return 1
# 2. Tests.
# 2. 运行测试。
if run("flutter", ["test"]) != 0:
sys.stderr.write("flutter test failed.\n")
return 1
# 3. Publish dry-run (skipped for apps / private packages).
# 3. 发布预检(应用 / 私有包可加 --no-publish 跳过)。
if not skip_publish:
if run("flutter", ["pub", "publish", "--dry-run"]) != 0:
sys.stderr.write("flutter pub publish --dry-run failed.\n")
return 1
print("\nAll checks passed.")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))