@elvis1513/auto-coding-skill 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -23,6 +23,13 @@ npm install -g git+https://github.com/elvis1513/auto-coding-skill.git
|
|
|
23
23
|
|
|
24
24
|
## Release Notes
|
|
25
25
|
|
|
26
|
+
### v2.0.4
|
|
27
|
+
|
|
28
|
+
- Added a generic impact-aware gate engine: `ap.py impact`, `light-gate --scope auto|changed|standard|full`, and `--explain`.
|
|
29
|
+
- Added project-owned `gate.*` policy support in `docs/ENGINEERING.md`; the skill chooses scope, while each project declares its own commands and optional path rules.
|
|
30
|
+
- Kept backward compatibility: projects without `gate.*` continue to use the existing standard `commands.light_gate` / quick-test fallback.
|
|
31
|
+
- Added conservative full-gate upgrades for CI, deploy, Docker, lockfile, build-tool, and autopipeline config changes.
|
|
32
|
+
|
|
26
33
|
### v2.0.3
|
|
27
34
|
|
|
28
35
|
- Fixed `doctor`, `light-gate`, `verify-target`, and Jenkins API verification to accept secret references via `*_password_env`.
|
|
@@ -148,6 +155,7 @@ It must be committed to Git. Do not add it to `.gitignore`.
|
|
|
148
155
|
重点字段:
|
|
149
156
|
- `workflow.mode`
|
|
150
157
|
- `commands.*`
|
|
158
|
+
- `gate.*`
|
|
151
159
|
- `target_env.*`
|
|
152
160
|
- `jenkins.*`
|
|
153
161
|
- `docs.*`
|
|
@@ -155,7 +163,7 @@ It must be committed to Git. Do not add it to `.gitignore`.
|
|
|
155
163
|
默认必填:
|
|
156
164
|
- `workflow.mode`
|
|
157
165
|
- `project.name`
|
|
158
|
-
- `commands.light_gate`
|
|
166
|
+
- `commands.gate_changed` / `commands.gate_standard` / `commands.gate_full`,或 `commands.light_gate` / `commands.quick_test` / `commands.test` / `commands.build`
|
|
159
167
|
- `target_env.name`
|
|
160
168
|
- `target_env.frontend_base_url`
|
|
161
169
|
- `target_env.frontend_username`
|
|
@@ -235,6 +243,10 @@ It must be committed to Git. Do not add it to `.gitignore`.
|
|
|
235
243
|
|
|
236
244
|
## Default Gate Policy
|
|
237
245
|
- Default local gate is lightweight only.
|
|
246
|
+
- Use `python3 docs/tools/autopipeline/ap.py impact --scope auto` to inspect changed files, matched project rules, and selected gate scope.
|
|
247
|
+
- Use `python3 docs/tools/autopipeline/ap.py light-gate --scope auto --explain` for small-step development after a project declares `gate.default_scope: auto`, `commands.gate_changed`, or matching `gate.rules`.
|
|
248
|
+
- Use `light-gate --scope standard` for the backward-compatible configured gate, and `light-gate --scope full` before release/deploy-sensitive closure.
|
|
249
|
+
- The gate engine is generic. Project-specific path mapping belongs in `docs/ENGINEERING.md` under `gate.rules`; unknown or high-risk impact should upgrade to standard/full rather than silently skipping checks.
|
|
238
250
|
- Do not require local Docker Compose or full local regression unless the task explicitly needs local runtime diagnosis.
|
|
239
251
|
- In `dev` mode, push is the finish line after `DEV-CLOSED` is recorded.
|
|
240
252
|
- In `verify` mode, Jenkins success, target environment verification, and closure record are mandatory.
|
|
@@ -78,6 +78,7 @@ Fill only:
|
|
|
78
78
|
This contains all manual fields:
|
|
79
79
|
- `workflow.mode`
|
|
80
80
|
- `commands.*`
|
|
81
|
+
- `gate.*`
|
|
81
82
|
- `runtime.*` (only for optional local diagnostics)
|
|
82
83
|
- `target_env.*`
|
|
83
84
|
- `jenkins.*`
|
|
@@ -89,7 +90,7 @@ Do not hide `docs/ENGINEERING.md` in `.gitignore`.
|
|
|
89
90
|
Minimum required config for the default flow:
|
|
90
91
|
- `workflow.mode`
|
|
91
92
|
- `project.name`
|
|
92
|
-
- `commands.
|
|
93
|
+
- `commands.gate_changed` / `commands.gate_standard` / `commands.gate_full`, or `commands.light_gate` / `commands.quick_test` / `commands.test` / `commands.build`
|
|
93
94
|
- `target_env.name`
|
|
94
95
|
- `target_env.frontend_base_url`
|
|
95
96
|
- `target_env.frontend_username`
|
|
@@ -149,6 +150,9 @@ Default commands:
|
|
|
149
150
|
|
|
150
151
|
```bash
|
|
151
152
|
python3 docs/tools/autopipeline/ap.py doctor
|
|
153
|
+
python3 docs/tools/autopipeline/ap.py impact --scope auto
|
|
154
|
+
python3 docs/tools/autopipeline/ap.py light-gate --scope auto --explain
|
|
155
|
+
python3 docs/tools/autopipeline/ap.py light-gate --scope full
|
|
152
156
|
python3 docs/tools/autopipeline/ap.py commit-push <TASK_ID> --msg "<TASK_ID>: <summary>"
|
|
153
157
|
python3 docs/tools/autopipeline/ap.py commit-push <TASK_ID> --mode dev --msg "<TASK_ID>: <summary>"
|
|
154
158
|
python3 docs/tools/autopipeline/ap.py commit-push <TASK_ID> --mode verify --msg "<TASK_ID>: <summary>" --backend-path /health --frontend-path /
|
|
@@ -167,6 +171,9 @@ python3 docs/tools/autopipeline/ap.py gen-summary <TASK_ID>
|
|
|
167
171
|
## Quality policy
|
|
168
172
|
|
|
169
173
|
- Default local gate is lightweight and time-bounded: prefer one curated project command via `commands.light_gate`, then run only diff/API/Jenkins checks.
|
|
174
|
+
- For small-step development, prefer the generic impact-aware gate: `light-gate --scope auto`. The skill provides the gate engine; each project owns its commands and optional `gate.rules` path mapping in `docs/ENGINEERING.md`.
|
|
175
|
+
- Keep `standard` as the backward-compatible default when no `gate.*` policy is configured. Use `changed` only when project commands/rules make the reduced scope explicit.
|
|
176
|
+
- Automatically upgrade to `full` for CI/deploy/build-tool/lockfile/autopipeline config changes, project-declared full rules, unknown impact when configured, or release/verify tasks.
|
|
170
177
|
- `workflow.mode: dev` closes development after light gate, closure record, commit, and push.
|
|
171
178
|
- `workflow.mode: verify` closes only after Jenkins and target-environment verification.
|
|
172
179
|
- `doctor` should be used early to catch missing or invalid config before the first implementation loop.
|
|
@@ -13,6 +13,9 @@ project:
|
|
|
13
13
|
jenkinsfile: "Jenkinsfile"
|
|
14
14
|
|
|
15
15
|
commands:
|
|
16
|
+
gate_changed: ""
|
|
17
|
+
gate_standard: ""
|
|
18
|
+
gate_full: ""
|
|
16
19
|
light_gate: ""
|
|
17
20
|
build: ""
|
|
18
21
|
test: ""
|
|
@@ -21,6 +24,35 @@ commands:
|
|
|
21
24
|
typecheck: ""
|
|
22
25
|
format: ""
|
|
23
26
|
|
|
27
|
+
gate:
|
|
28
|
+
default_scope: "standard"
|
|
29
|
+
fallback_scope: "standard"
|
|
30
|
+
full_on_unknown: true
|
|
31
|
+
no_change_scope: "standard"
|
|
32
|
+
full_on:
|
|
33
|
+
paths:
|
|
34
|
+
- "Jenkinsfile"
|
|
35
|
+
- "Jenkinsfile.*"
|
|
36
|
+
- ".github/workflows/**"
|
|
37
|
+
- "Dockerfile"
|
|
38
|
+
- "**/Dockerfile"
|
|
39
|
+
- "docker-compose*.yml"
|
|
40
|
+
- "docker-compose*.yaml"
|
|
41
|
+
- "compose*.yml"
|
|
42
|
+
- "compose*.yaml"
|
|
43
|
+
- "docs/ENGINEERING.md"
|
|
44
|
+
- "docs/tools/autopipeline/**"
|
|
45
|
+
- "package-lock.json"
|
|
46
|
+
- "pnpm-lock.yaml"
|
|
47
|
+
- "yarn.lock"
|
|
48
|
+
- "go.mod"
|
|
49
|
+
- "go.sum"
|
|
50
|
+
- "Cargo.lock"
|
|
51
|
+
- "pom.xml"
|
|
52
|
+
- "build.gradle*"
|
|
53
|
+
- "settings.gradle*"
|
|
54
|
+
rules: []
|
|
55
|
+
|
|
24
56
|
runtime:
|
|
25
57
|
docker_compose_file: ""
|
|
26
58
|
docker_service: ""
|
|
@@ -96,7 +128,8 @@ docs:
|
|
|
96
128
|
|
|
97
129
|
先填写 `docs/ENGINEERING.md` frontmatter 中的所有空值。重点包括:
|
|
98
130
|
- `workflow.mode`:`dev` 或 `verify`,默认推荐 `dev`
|
|
99
|
-
- `commands.light_gate
|
|
131
|
+
- `commands.gate_changed` / `commands.gate_standard` / `commands.gate_full`:推荐配置分层门禁命令;旧项目也可以继续只配置 `commands.light_gate`
|
|
132
|
+
- `gate.*`:按项目声明路径规则和高风险升级规则;未配置时保持标准门禁行为
|
|
100
133
|
- `target_env.*`:目标环境前端 / 后端地址、用户名、密码引用,必须全部填写且真实可用
|
|
101
134
|
- `jenkins.*`:Jenkins UI/API 用户名、密码引用、Job、分支、镜像、部署环境,必须全部填写且真实可用
|
|
102
135
|
|
|
@@ -110,7 +143,7 @@ docs:
|
|
|
110
143
|
默认必填:
|
|
111
144
|
- `workflow.mode`
|
|
112
145
|
- `project.name`
|
|
113
|
-
- `commands.light_gate`
|
|
146
|
+
- `commands.gate_changed` / `commands.gate_standard` / `commands.gate_full`,或 `commands.light_gate` / `commands.quick_test` / `commands.test` / `commands.build`
|
|
114
147
|
- `target_env.name`
|
|
115
148
|
- `target_env.frontend_base_url`
|
|
116
149
|
- `target_env.frontend_username`
|
|
@@ -134,6 +167,8 @@ docs:
|
|
|
134
167
|
- `jenkins.job_url`
|
|
135
168
|
|
|
136
169
|
按需填写:
|
|
170
|
+
- `gate.default_scope`:默认 `standard`;需要小步快跑时设为 `auto` 或 `changed`
|
|
171
|
+
- `gate.rules`:项目自定义路径规则。每条规则可包含 `name`、`paths`、`commands`、`scope`
|
|
137
172
|
- `runtime.*`:仅在本地运行诊断时使用
|
|
138
173
|
- `commands.build` / `commands.test` / `commands.quick_test` / `commands.lint` / `commands.typecheck` / `commands.format`:按项目实际情况保留
|
|
139
174
|
|
|
@@ -7,6 +7,7 @@ from __future__ import annotations
|
|
|
7
7
|
import argparse
|
|
8
8
|
import base64
|
|
9
9
|
import datetime as _dt
|
|
10
|
+
import fnmatch
|
|
10
11
|
import json
|
|
11
12
|
import os
|
|
12
13
|
import time
|
|
@@ -638,6 +639,296 @@ def _resolve_secret(section_name: str, section_cfg: dict, field: str) -> str:
|
|
|
638
639
|
)
|
|
639
640
|
|
|
640
641
|
|
|
642
|
+
_GATE_SCOPES = {"auto", "changed", "standard", "full"}
|
|
643
|
+
_DOC_PATH_PATTERNS = ["*.md", "docs/**"]
|
|
644
|
+
_DEFAULT_FULL_PATH_PATTERNS = [
|
|
645
|
+
".agents/**",
|
|
646
|
+
".claude/**",
|
|
647
|
+
".github/workflows/**",
|
|
648
|
+
"Jenkinsfile",
|
|
649
|
+
"Jenkinsfile.*",
|
|
650
|
+
"Dockerfile",
|
|
651
|
+
"**/Dockerfile",
|
|
652
|
+
"docker-compose*.yml",
|
|
653
|
+
"docker-compose*.yaml",
|
|
654
|
+
"compose*.yml",
|
|
655
|
+
"compose*.yaml",
|
|
656
|
+
"docs/ENGINEERING.md",
|
|
657
|
+
"docs/tools/autopipeline/**",
|
|
658
|
+
"package-lock.json",
|
|
659
|
+
"pnpm-lock.yaml",
|
|
660
|
+
"yarn.lock",
|
|
661
|
+
"bun.lockb",
|
|
662
|
+
"go.mod",
|
|
663
|
+
"go.sum",
|
|
664
|
+
"Cargo.lock",
|
|
665
|
+
"pom.xml",
|
|
666
|
+
"build.gradle",
|
|
667
|
+
"build.gradle.kts",
|
|
668
|
+
"settings.gradle",
|
|
669
|
+
"settings.gradle.kts",
|
|
670
|
+
]
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
def _gate_cfg(cfg: dict) -> dict:
|
|
674
|
+
gate_cfg = cfg.get("gate") or {}
|
|
675
|
+
return gate_cfg if isinstance(gate_cfg, dict) else {}
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
def _as_list(value: object) -> list:
|
|
679
|
+
if value is None:
|
|
680
|
+
return []
|
|
681
|
+
if isinstance(value, list):
|
|
682
|
+
return value
|
|
683
|
+
return [value]
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
def _command_name(ref: object) -> str:
|
|
687
|
+
raw = _text(ref)
|
|
688
|
+
if raw.startswith("commands."):
|
|
689
|
+
raw = raw.split(".", 1)[1]
|
|
690
|
+
return raw
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
def _configured_command(cfg: dict, name: str) -> str:
|
|
694
|
+
commands = cfg.get("commands") or {}
|
|
695
|
+
return _text(commands.get(name))
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def _run_first_configured_command(repo: Path, cfg: dict, names: list[str]) -> str:
|
|
699
|
+
for name in names:
|
|
700
|
+
command_name = _command_name(name)
|
|
701
|
+
if command_name and _configured_command(cfg, command_name):
|
|
702
|
+
_run_configured_command(repo, cfg, command_name)
|
|
703
|
+
return command_name
|
|
704
|
+
return ""
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
def _run_configured_command_list(repo: Path, cfg: dict, names: list) -> list[str]:
|
|
708
|
+
executed: list[str] = []
|
|
709
|
+
missing: list[str] = []
|
|
710
|
+
for name_ref in names:
|
|
711
|
+
name = _command_name(name_ref)
|
|
712
|
+
if not name:
|
|
713
|
+
continue
|
|
714
|
+
if _configured_command(cfg, name):
|
|
715
|
+
_run_configured_command(repo, cfg, name)
|
|
716
|
+
executed.append(name)
|
|
717
|
+
else:
|
|
718
|
+
missing.append(name)
|
|
719
|
+
if missing and not executed:
|
|
720
|
+
raise APError("Gate rule references missing commands: " + ", ".join(missing))
|
|
721
|
+
return executed
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
def _path_matches(path: str, patterns: list) -> bool:
|
|
725
|
+
normalized = path.replace("\\", "/").lstrip("./")
|
|
726
|
+
for pattern_ref in patterns:
|
|
727
|
+
pattern = _text(pattern_ref).replace("\\", "/").lstrip("./")
|
|
728
|
+
if not pattern:
|
|
729
|
+
continue
|
|
730
|
+
if fnmatch.fnmatch(normalized, pattern):
|
|
731
|
+
return True
|
|
732
|
+
if "/" not in pattern and fnmatch.fnmatch(Path(normalized).name, pattern):
|
|
733
|
+
return True
|
|
734
|
+
return False
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
def _unique_paths(paths: list[str]) -> list[str]:
|
|
738
|
+
seen = set()
|
|
739
|
+
out = []
|
|
740
|
+
for path in paths:
|
|
741
|
+
normalized = path.replace("\\", "/").strip()
|
|
742
|
+
if not normalized or normalized in seen:
|
|
743
|
+
continue
|
|
744
|
+
seen.add(normalized)
|
|
745
|
+
out.append(normalized)
|
|
746
|
+
return sorted(out)
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
def _git_lines(repo: Path, cmd: list[str]) -> list[str]:
|
|
750
|
+
try:
|
|
751
|
+
result = run(cmd, cwd=repo, check=False)
|
|
752
|
+
except APError:
|
|
753
|
+
return []
|
|
754
|
+
if result.returncode != 0:
|
|
755
|
+
return []
|
|
756
|
+
return [line.strip() for line in result.stdout.splitlines() if line.strip()]
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
def _default_base_ref(repo: Path) -> str:
|
|
760
|
+
upstream = _git_lines(repo, ["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"])
|
|
761
|
+
return upstream[0] if upstream else ""
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
def _changed_files(repo: Path, base_ref: str = "") -> list[str]:
|
|
765
|
+
paths: list[str] = []
|
|
766
|
+
effective_base = base_ref or _default_base_ref(repo)
|
|
767
|
+
if effective_base:
|
|
768
|
+
paths.extend(_git_lines(repo, ["git", "diff", "--name-only", "--diff-filter=ACMRTUXB", f"{effective_base}...HEAD"]))
|
|
769
|
+
paths.extend(_git_lines(repo, ["git", "diff", "--name-only", "--diff-filter=ACMRTUXB"]))
|
|
770
|
+
paths.extend(_git_lines(repo, ["git", "diff", "--cached", "--name-only", "--diff-filter=ACMRTUXB"]))
|
|
771
|
+
paths.extend(_git_lines(repo, ["git", "ls-files", "--others", "--exclude-standard"]))
|
|
772
|
+
return _unique_paths(paths)
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
def _docs_only(paths: list[str]) -> bool:
|
|
776
|
+
return bool(paths) and all(_path_matches(path, _DOC_PATH_PATTERNS) for path in paths)
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
def _gate_rules(gate_cfg: dict) -> list[dict]:
|
|
780
|
+
rules = gate_cfg.get("rules") or []
|
|
781
|
+
return [rule for rule in rules if isinstance(rule, dict)]
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def _matching_gate_rules(paths: list[str], gate_cfg: dict) -> list[dict]:
|
|
785
|
+
matches = []
|
|
786
|
+
for rule in _gate_rules(gate_cfg):
|
|
787
|
+
patterns = _as_list(rule.get("paths"))
|
|
788
|
+
if patterns and any(_path_matches(path, patterns) for path in paths):
|
|
789
|
+
matches.append(rule)
|
|
790
|
+
return matches
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
def _gate_full_patterns(gate_cfg: dict) -> list:
|
|
794
|
+
full_on = gate_cfg.get("full_on") or {}
|
|
795
|
+
patterns = list(_DEFAULT_FULL_PATH_PATTERNS)
|
|
796
|
+
if isinstance(full_on, dict):
|
|
797
|
+
patterns.extend(_as_list(full_on.get("paths")))
|
|
798
|
+
else:
|
|
799
|
+
patterns.extend(_as_list(full_on))
|
|
800
|
+
return patterns
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
def _has_changed_gate(cfg: dict, gate_cfg: dict, paths: list[str]) -> bool:
|
|
804
|
+
if _configured_command(cfg, "gate_changed"):
|
|
805
|
+
return True
|
|
806
|
+
for rule in _matching_gate_rules(paths, gate_cfg):
|
|
807
|
+
if _as_list(rule.get("commands")):
|
|
808
|
+
return True
|
|
809
|
+
return False
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
def _select_gate_scope(cfg: dict, requested_scope: str, paths: list[str]) -> tuple[str, list[str], list[dict]]:
|
|
813
|
+
gate_cfg = _gate_cfg(cfg)
|
|
814
|
+
scope = (requested_scope or _text(gate_cfg.get("default_scope")) or "standard").lower()
|
|
815
|
+
if scope not in _GATE_SCOPES:
|
|
816
|
+
raise APError("gate scope must be one of: " + ", ".join(sorted(_GATE_SCOPES)))
|
|
817
|
+
|
|
818
|
+
matching_rules = _matching_gate_rules(paths, gate_cfg)
|
|
819
|
+
reasons: list[str] = []
|
|
820
|
+
|
|
821
|
+
if scope != "auto":
|
|
822
|
+
return scope, [f"requested scope: {scope}"], matching_rules
|
|
823
|
+
|
|
824
|
+
if not paths:
|
|
825
|
+
fallback = _text(gate_cfg.get("no_change_scope")) or "standard"
|
|
826
|
+
if fallback not in {"changed", "standard", "full"}:
|
|
827
|
+
fallback = "standard"
|
|
828
|
+
return fallback, ["no changed files detected"], matching_rules
|
|
829
|
+
|
|
830
|
+
rule_scopes = {_text(rule.get("scope")).lower() for rule in matching_rules if _text(rule.get("scope"))}
|
|
831
|
+
if "full" in rule_scopes:
|
|
832
|
+
return "full", ["matched gate rule with scope=full"], matching_rules
|
|
833
|
+
if "standard" in rule_scopes:
|
|
834
|
+
return "standard", ["matched gate rule with scope=standard"], matching_rules
|
|
835
|
+
|
|
836
|
+
if any(_path_matches(path, _gate_full_patterns(gate_cfg)) for path in paths):
|
|
837
|
+
return "full", ["changed files match full-gate patterns"], matching_rules
|
|
838
|
+
|
|
839
|
+
if _docs_only(paths):
|
|
840
|
+
return "changed", ["docs-only change"], matching_rules
|
|
841
|
+
|
|
842
|
+
if _has_changed_gate(cfg, gate_cfg, paths):
|
|
843
|
+
return "changed", ["matched changed-gate command or rule"], matching_rules
|
|
844
|
+
|
|
845
|
+
fallback = _text(gate_cfg.get("fallback_scope")) or "standard"
|
|
846
|
+
if fallback not in {"changed", "standard", "full"}:
|
|
847
|
+
fallback = "standard"
|
|
848
|
+
if fallback == "changed" and _text(gate_cfg.get("full_on_unknown")).lower() in {"1", "true", "yes", "on"}:
|
|
849
|
+
fallback = "full"
|
|
850
|
+
reasons.append("no changed-gate command/rule matched")
|
|
851
|
+
return fallback, reasons, matching_rules
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
def _impact_summary(cfg: dict, repo: Path, requested_scope: str, base_ref: str = "") -> dict:
|
|
855
|
+
paths = _changed_files(repo, base_ref=base_ref)
|
|
856
|
+
scope, reasons, matching_rules = _select_gate_scope(cfg, requested_scope, paths)
|
|
857
|
+
return {
|
|
858
|
+
"requested_scope": requested_scope or _text(_gate_cfg(cfg).get("default_scope")) or "standard",
|
|
859
|
+
"selected_scope": scope,
|
|
860
|
+
"reasons": reasons,
|
|
861
|
+
"changed_files": paths,
|
|
862
|
+
"matched_rules": [_text(rule.get("name")) or "(unnamed)" for rule in matching_rules],
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
def _print_impact(summary: dict, as_json: bool = False) -> None:
|
|
867
|
+
if as_json:
|
|
868
|
+
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
|
869
|
+
return
|
|
870
|
+
print(f"[impact] requested_scope={summary['requested_scope']}")
|
|
871
|
+
print(f"[impact] selected_scope={summary['selected_scope']}")
|
|
872
|
+
for reason in summary.get("reasons") or []:
|
|
873
|
+
print(f"[impact] reason: {reason}")
|
|
874
|
+
for rule in summary.get("matched_rules") or []:
|
|
875
|
+
print(f"[impact] matched_rule: {rule}")
|
|
876
|
+
files = summary.get("changed_files") or []
|
|
877
|
+
if files:
|
|
878
|
+
for path in files:
|
|
879
|
+
print(f"[impact] changed: {path}")
|
|
880
|
+
else:
|
|
881
|
+
print("[impact] changed: (none)")
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
def _run_changed_gate(repo: Path, cfg: dict, paths: list[str], matching_rules: list[dict]) -> list[str]:
|
|
885
|
+
executed: list[str] = []
|
|
886
|
+
for rule in matching_rules:
|
|
887
|
+
executed.extend(_run_configured_command_list(repo, cfg, _as_list(rule.get("commands"))))
|
|
888
|
+
if executed:
|
|
889
|
+
return executed
|
|
890
|
+
|
|
891
|
+
fallback_commands = ["gate_changed"]
|
|
892
|
+
if _docs_only(paths):
|
|
893
|
+
fallback_commands.append("docs_check")
|
|
894
|
+
command = _run_first_configured_command(repo, cfg, fallback_commands)
|
|
895
|
+
if command:
|
|
896
|
+
return [command]
|
|
897
|
+
|
|
898
|
+
if _docs_only(paths):
|
|
899
|
+
print("[gate] docs-only change with no changed-gate command configured; running built-in post checks only.")
|
|
900
|
+
return ["docs_only_builtin"]
|
|
901
|
+
|
|
902
|
+
fallback = _run_first_configured_command(repo, cfg, ["quick_test", "test", "build"])
|
|
903
|
+
if fallback:
|
|
904
|
+
return [fallback]
|
|
905
|
+
|
|
906
|
+
raise APError(
|
|
907
|
+
"Changed gate has no configured command. Add commands.gate_changed or matching gate.rules commands, "
|
|
908
|
+
"or run light-gate --scope standard/full."
|
|
909
|
+
)
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
def _run_standard_gate(repo: Path, cfg: dict) -> list[str]:
|
|
913
|
+
command = _run_first_configured_command(repo, cfg, ["gate_standard", "light_gate", "quick_test", "test", "build"])
|
|
914
|
+
if not command:
|
|
915
|
+
raise APError(
|
|
916
|
+
"Standard gate is under-configured. Add commands.gate_standard, commands.light_gate, "
|
|
917
|
+
"commands.quick_test, commands.test, or commands.build."
|
|
918
|
+
)
|
|
919
|
+
return [command]
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
def _run_full_gate(repo: Path, cfg: dict) -> list[str]:
|
|
923
|
+
command = _run_first_configured_command(repo, cfg, ["gate_full", "full_gate", "gate_standard", "light_gate", "test", "build"])
|
|
924
|
+
if not command:
|
|
925
|
+
raise APError(
|
|
926
|
+
"Full gate is under-configured. Add commands.gate_full, commands.full_gate, commands.test, "
|
|
927
|
+
"commands.build, or commands.light_gate."
|
|
928
|
+
)
|
|
929
|
+
return [command]
|
|
930
|
+
|
|
931
|
+
|
|
641
932
|
def _run_git_diff_check(repo: Path, cfg: dict) -> None:
|
|
642
933
|
print("[diff-check] git diff --check")
|
|
643
934
|
run(["git", "diff", "--check"], cwd=repo)
|
|
@@ -671,38 +962,35 @@ def cmd_light_gate(args: argparse.Namespace) -> None:
|
|
|
671
962
|
repo = Path(args.repo).resolve()
|
|
672
963
|
cmd_doctor(argparse.Namespace(repo=str(repo)))
|
|
673
964
|
cfg = _load_cfg(repo)
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
executed
|
|
685
|
-
elif
|
|
686
|
-
|
|
687
|
-
executed.append("test")
|
|
688
|
-
elif str(commands.get("build") or "").strip():
|
|
689
|
-
_run_configured_command(repo, cfg, "build")
|
|
690
|
-
executed.append("build")
|
|
965
|
+
requested_scope = str(getattr(args, "scope", "") or "").strip().lower()
|
|
966
|
+
impact = _impact_summary(cfg, repo, requested_scope=requested_scope, base_ref=str(getattr(args, "base", "") or ""))
|
|
967
|
+
if getattr(args, "explain", False):
|
|
968
|
+
_print_impact(impact)
|
|
969
|
+
|
|
970
|
+
selected_scope = str(impact["selected_scope"])
|
|
971
|
+
paths = list(impact.get("changed_files") or [])
|
|
972
|
+
matching_rules = _matching_gate_rules(paths, _gate_cfg(cfg))
|
|
973
|
+
|
|
974
|
+
if selected_scope == "changed":
|
|
975
|
+
executed = _run_changed_gate(repo, cfg, paths, matching_rules)
|
|
976
|
+
elif selected_scope == "full":
|
|
977
|
+
executed = _run_full_gate(repo, cfg)
|
|
691
978
|
else:
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if missing:
|
|
695
|
-
raise APError(
|
|
696
|
-
"Light gate is under-configured. Missing required commands: "
|
|
697
|
-
+ ", ".join(missing)
|
|
698
|
-
+ ". Edit docs/ENGINEERING.md frontmatter."
|
|
699
|
-
)
|
|
979
|
+
executed = _run_standard_gate(repo, cfg)
|
|
700
980
|
|
|
701
981
|
_run_git_diff_check(repo, cfg)
|
|
702
982
|
cmd_verify_api_docs(argparse.Namespace(repo=str(repo)))
|
|
703
983
|
cmd_verify_jenkins(argparse.Namespace(repo=str(repo)))
|
|
704
984
|
executed.extend(["diff_check", "verify_api_docs", "verify_jenkins"])
|
|
705
|
-
print("[light-gate] OK: " + ", ".join(executed))
|
|
985
|
+
print(f"[light-gate] OK scope={selected_scope}: " + ", ".join(executed))
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
def cmd_impact(args: argparse.Namespace) -> None:
|
|
989
|
+
repo = Path(args.repo).resolve()
|
|
990
|
+
cfg = _load_cfg(repo)
|
|
991
|
+
scope = str(args.scope or "").strip().lower()
|
|
992
|
+
summary = _impact_summary(cfg, repo, requested_scope=scope, base_ref=str(args.base or ""))
|
|
993
|
+
_print_impact(summary, as_json=bool(args.json))
|
|
706
994
|
|
|
707
995
|
|
|
708
996
|
def cmd_runtime_up(args: argparse.Namespace) -> None:
|
|
@@ -858,12 +1146,19 @@ def cmd_doctor(args: argparse.Namespace) -> None:
|
|
|
858
1146
|
if not str(project_cfg.get("name") or "").strip():
|
|
859
1147
|
missing.append("project.name")
|
|
860
1148
|
if not (
|
|
861
|
-
str(commands.get("
|
|
1149
|
+
str(commands.get("gate_changed") or "").strip()
|
|
1150
|
+
or str(commands.get("gate_standard") or "").strip()
|
|
1151
|
+
or str(commands.get("gate_full") or "").strip()
|
|
1152
|
+
or str(commands.get("full_gate") or "").strip()
|
|
1153
|
+
or str(commands.get("light_gate") or "").strip()
|
|
862
1154
|
or str(commands.get("quick_test") or "").strip()
|
|
863
1155
|
or str(commands.get("test") or "").strip()
|
|
864
1156
|
or str(commands.get("build") or "").strip()
|
|
865
1157
|
):
|
|
866
|
-
missing.append(
|
|
1158
|
+
missing.append(
|
|
1159
|
+
"commands.gate_changed/gate_standard/gate_full, commands.light_gate, "
|
|
1160
|
+
"commands.quick_test, commands.test, or commands.build"
|
|
1161
|
+
)
|
|
867
1162
|
_require_explicit_field(missing, "target_env.name", target_cfg.get("name"))
|
|
868
1163
|
_require_explicit_field(missing, "target_env.frontend_base_url", target_cfg.get("frontend_base_url"))
|
|
869
1164
|
_require_explicit_field(missing, "target_env.frontend_username", target_cfg.get("frontend_username"))
|
|
@@ -1256,7 +1551,16 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
1256
1551
|
s.add_argument("name")
|
|
1257
1552
|
s.set_defaults(func=cmd_run)
|
|
1258
1553
|
|
|
1554
|
+
s = sp.add_parser("impact")
|
|
1555
|
+
s.add_argument("--scope", choices=sorted(_GATE_SCOPES), default="")
|
|
1556
|
+
s.add_argument("--base")
|
|
1557
|
+
s.add_argument("--json", action="store_true")
|
|
1558
|
+
s.set_defaults(func=cmd_impact)
|
|
1559
|
+
|
|
1259
1560
|
s = sp.add_parser("light-gate")
|
|
1561
|
+
s.add_argument("--scope", choices=sorted(_GATE_SCOPES), default="")
|
|
1562
|
+
s.add_argument("--base")
|
|
1563
|
+
s.add_argument("--explain", action="store_true")
|
|
1260
1564
|
s.set_defaults(func=cmd_light_gate)
|
|
1261
1565
|
|
|
1262
1566
|
s = sp.add_parser("doctor")
|
package/package.json
CHANGED