Repository navigation
123 lines (112 loc) · 4.94 KB
/
Copy pathci.yml
File metadata and controls
123 lines (112 loc) · 4.94 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: ci
on:
push:
pull_request:
# 手动触发(可在 Actions 页面指定分支跑一次全量流水线)
workflow_dispatch:
jobs:
# ---------------------------------------------------------------------------
# 主流水线:直接调用 zcp_pipeline.py,一次跑完 env -> deps -> build -> test
# CI 环境不注入 app.asar(--no-deploy),部署步骤由本机看护脚本负责
# ---------------------------------------------------------------------------
pipeline:
name: zcp-pipeline (${{ matrix.os }} / py${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# README 声明「Python >= 3.10」,用 3.10 兜底,防止误用更高版本才有的 API
- os: ubuntu-latest
python-version: "3.10"
- os: ubuntu-latest
python-version: "3.12"
- os: ubuntu-latest
python-version: "3.13"
- os: windows-latest
python-version: "3.12"
- os: macos-latest
python-version: "3.12"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/setup-node@v4
with:
node-version: "22"
# 全自动流水线:依赖自检 -> 构建检查 -> 回归测试,产出机器可读报告
# Python 统一 UTF-8:Windows runner 默认 cp1252,中文日志会在 print 时直接抛
# UnicodeEncodeError(表现为「一条日志都没有、exit 1」)。
- name: 全自动流水线(zcp-pipeline)
if: hashFiles('zcp_pipeline.py') != ''
shell: bash
env:
PYTHONUTF8: "1"
PYTHONIOENCODING: "utf-8"
run: |
mkdir -p logs
python zcp_pipeline.py --no-deploy --unattended --report ci-report.md --log logs/ci.log 2>&1 | tee logs/stdout.log
# 公开仓库的 Actions 日志下载需要管理员权限;失败时把关键日志写进
# job annotation(匿名可读),方便无本地环境时直接定位。
- name: 失败日志注解(排障)
if: failure()
shell: bash
run: |
python - <<'PY'
import pathlib
def esc(s):
return s.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
lines = []
for p, n in (("logs/stdout.log", 120), ("logs/ci.log", 40), ("ci-report.md", 30)):
f = pathlib.Path(p)
if f.is_file():
lines.append(f"=== {p} ===")
lines.extend(f.read_text(encoding="utf-8", errors="replace").splitlines()[-n:])
if not lines:
lines = ["<no log file>"]
print(f"::error title=zcp-pipeline-log::{esc(chr(10).join(lines))}")
PY
# 兼容旧布局:若仓库里还没有 zcp_pipeline.py,退回逐项语法检查
- name: 语法检查(Python,回退路径)
if: hashFiles('zcp_pipeline.py') == ''
shell: bash
run: |
set -e
# 目录名兼容两种仓库布局:扁平 scripts/ 与插件 skills/zcode-pilot/scripts/
for d in scripts skills/zcode-pilot/scripts; do
[ -d "$d" ] || continue
python -m py_compile "$d"/*.py
done
- name: 语法检查(注入脚本,回退路径)
if: hashFiles('zcp_pipeline.py') == ''
shell: bash
run: |
set -e
for d in scripts skills/zcode-pilot/scripts; do
[ -d "$d" ] || continue
for f in "$d"/*.js; do node --check "$f"; done
done
- name: 回归测试(回退路径)
if: hashFiles('zcp_pipeline.py') == ''
run: python -m unittest discover -s tests -v
# 新能力「自动继续」的权威注册点在 hooks/hooks.json:JSON 写坏或漏注册
# Stop / UserPromptSubmit 会**静默**失效(日志干净、退出码 0、界面无异常),
# 所以这里补一次结构校验(契约 docs/CONTRACT.md §2.3.1)。
- name: 校验 hooks.json(自动继续注册)
shell: bash
run: |
python -c "import json,pathlib,sys; h=json.loads(pathlib.Path('hooks/hooks.json').read_text(encoding='utf-8'))['hooks']; m=[e for e in ('Stop','UserPromptSubmit') if e not in h or 'zcp_hook.py' not in h[e][0]['hooks'][0]['command']]; sys.exit('hooks.json 注册异常: '+','.join(m) if m else 0)"
echo "hooks.json OK: Stop / UserPromptSubmit 已指向 zcp_hook.py"
# 无论成功失败都留下报告与日志,便于定位偶发问题
- name: 上传流水线报告
if: always()
uses: actions/upload-artifact@v4
with:
name: ci-report-${{ matrix.os }}-py${{ matrix.python-version }}
path: |
ci-report.md
logs/*.log
logs/*.jsonl
if-no-files-found: ignore
retention-days: 14