ci: reconcile one downstream task per verified release and consumer
This commit is contained in:
1 parent
af60b89dcf
commit
68b7fe0511
3 files changed
+95
-7
No files matched your search
@@ -82,6 +82,8 @@ bash scripts/integration.sh # 生态候选:真实 CLI 制品 +
|
||||
|
||||
正式发布对账使用 `python3 scripts/reconcile-releases.py --plan --published-after <ISO-8601 时间>`。从固定根及领域 tree 解析受管仓库,核对 Gitea tag、`release-evidence.json`、同 SHA Woodpecker 组件 CI 和资产字节摘要。根 `reconcile` 工作流从当前受保护的 `main` 串行运行,使用 `gitea_reconcile_token` 以专用非管理员账号写追踪工单。`historical-baseline` 表示已登记历史输入,`blocked` 表示发布验证未通过,`tracked` 表示已记录经验证的发布。消费者验收和父级接受均需各自的 CI 与 PR 证据。
|
||||
|
||||
对已验证的发布,`--plan` 计算直接 active 消费者的输入摘要。受保护 `--apply` 按发布和消费者登记一条任务,基线变化时在原任务中记录新输入。输入附精确资产、依赖、消费者基线和根追踪编号。下游独立 CI 及批准后的晋升基于各自的真实结果。
|
||||
|
||||
## 发行与回滚
|
||||
|
||||
- 组件可独立 SemVer 发布;领域可发布经过验证的组合制品;根生态 release 固定整个 gitlink 树。独立版本不代表维护多套现行协议。
|
||||
|
||||
@@ -288,6 +288,9 @@ def consumer_inputs(entry, graph):
|
||||
tasks = []
|
||||
for consumer_id in entry["direct_consumers"]:
|
||||
consumer = graph[consumer_id]
|
||||
remote = REPOSITORY.fullmatch(consumer.get("remote") or "")
|
||||
require(remote is not None and match(SHA, consumer.get("sha")),
|
||||
f"{consumer_id}: consumer is missing its managed repository or accepted SHA")
|
||||
inputs = {
|
||||
"release": release,
|
||||
"consumer": {"id": consumer_id, "source_sha": consumer["sha"]},
|
||||
@@ -298,7 +301,7 @@ def consumer_inputs(entry, graph):
|
||||
}
|
||||
digest = hashlib.sha256(json.dumps(inputs, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
|
||||
key = hashlib.sha256(f"{release_key}\n{consumer_id}\n{digest}".encode()).hexdigest()
|
||||
tasks.append({"consumer": consumer_id, "key": key, "digest": digest,
|
||||
tasks.append({"consumer": consumer_id, "repository": remote[1], "key": key, "digest": digest,
|
||||
"baseline_sha": consumer["sha"], "inputs": inputs,
|
||||
"status": "waiting-for-dependencies" if conflicts else "pending",
|
||||
"different_dependencies": conflicts})
|
||||
@@ -353,12 +356,64 @@ def verify_apply_context(client, root_sha):
|
||||
root = client.get(f"/repos/{ROOT_REPOSITORY}")
|
||||
require(isinstance(root, dict) and root.get("default_branch") == "main",
|
||||
"apply requires the root default branch")
|
||||
verify_root_base(client, root_sha)
|
||||
|
||||
|
||||
def verify_root_base(client, root_sha):
|
||||
branch = client.get(f"/repos/{ROOT_REPOSITORY}/branches/main")
|
||||
require(isinstance(branch, dict) and branch.get("protected") is True
|
||||
and (branch.get("commit") or {}).get("id") == root_sha,
|
||||
"apply requires the current protected root commit")
|
||||
|
||||
|
||||
def register_consumer_tasks(client, root_sha, entry, issue_cache):
|
||||
for task in entry["consumer_tasks"]:
|
||||
issues_url = f"/repos/{task['repository']}/issues"
|
||||
marker = f"<!-- marqdo:upstream release={entry['release_key']} consumer={task['consumer']} -->"
|
||||
body = "\n".join([
|
||||
marker,
|
||||
f"<!-- marqdo:candidate-inputs {task['key']} -->",
|
||||
"",
|
||||
f"- Root tracking issue: {FORGE}/{ROOT_REPOSITORY}/issues/{entry['issue']}",
|
||||
f"- Root candidate: {root_sha}",
|
||||
f"- Consumer baseline: {task['baseline_sha']}",
|
||||
f"- Input digest: {task['digest']}",
|
||||
f"- State: {task['status']}",
|
||||
"",
|
||||
"```json",
|
||||
json.dumps(task["inputs"], ensure_ascii=False, sort_keys=True, indent=2),
|
||||
"```",
|
||||
])
|
||||
try:
|
||||
if issues_url not in issue_cache:
|
||||
issue_cache[issues_url] = list(pages(client, issues_url, state="all", type="issues"))
|
||||
issues = issue_cache[issues_url]
|
||||
matches = [issue for issue in issues if is_writer(issue)
|
||||
and (issue.get("body") or "").splitlines()[:1] == [marker]]
|
||||
require(len(matches) <= 1, "multiple matching consumer tasks")
|
||||
if matches:
|
||||
issue = matches[0]
|
||||
if issue["state"] == "open":
|
||||
comments = tracking_comments(client, issues_url, issue)
|
||||
key_line = f"<!-- marqdo:candidate-inputs {task['key']} -->"
|
||||
if not any(key_line in note.splitlines() for note in [issue["body"], *comments]):
|
||||
verify_root_base(client, root_sha)
|
||||
client.post(f"{issues_url}/{issue['number']}/comments", {"body": body})
|
||||
else:
|
||||
task["registration"] = "closed"
|
||||
else:
|
||||
verify_root_base(client, root_sha)
|
||||
issue = client.post(issues_url, {
|
||||
"title": f"[upstream] {entry['component']} {entry['tag']} for {task['consumer']}",
|
||||
"body": body,
|
||||
})
|
||||
issues.append(issue)
|
||||
task["issue"] = issue["number"]
|
||||
task.setdefault("registration", "recorded")
|
||||
except ReconcileError as error:
|
||||
task.update(registration="blocked", error=str(error))
|
||||
|
||||
|
||||
def reconcile(client, root=PROJECT_ROOT, apply=False, report_out=None, cutoff=None):
|
||||
root_sha, graph, managed = managed_repositories(root)
|
||||
cutoff_time = timestamp(cutoff) if cutoff else None
|
||||
@@ -368,7 +423,7 @@ def reconcile(client, root=PROJECT_ROOT, apply=False, report_out=None, cutoff=No
|
||||
verify_apply_context(client, root_sha)
|
||||
labels = f"/repos/{ROOT_REPOSITORY}/labels"
|
||||
label_id = next((x["id"] for x in pages(client, labels) if x.get("name") == LABEL), None) if apply else None
|
||||
results, errors = [], {}
|
||||
results, errors, consumer_issues = [], {}, {}
|
||||
for repository, component in managed.items():
|
||||
known_tags = set()
|
||||
try:
|
||||
@@ -434,6 +489,10 @@ def reconcile(client, root=PROJECT_ROOT, apply=False, report_out=None, cutoff=No
|
||||
entry["issue"] = created["number"]
|
||||
if entry["status"] == "pending":
|
||||
entry["status"] = "created"
|
||||
if (apply and entry.get("consumer_tasks") and not entry.get("tracking_update")
|
||||
and entry["status"] in {"created", "pending", "tracked"}
|
||||
and (not trackers or trackers[0]["state"] == "open")):
|
||||
register_consumer_tasks(client, root_sha, entry, consumer_issues)
|
||||
results.append(entry)
|
||||
prefix = f"<!-- marqdo:release-reconcile repository={repository} tag="
|
||||
for issue in issues:
|
||||
@@ -492,7 +551,9 @@ def main(argv):
|
||||
return 1
|
||||
print(json.dumps(report, ensure_ascii=False, indent=2))
|
||||
return int(not report["scan_complete"] or any(
|
||||
item["status"] == "blocked" or "tracking_update" in item for item in report["results"]))
|
||||
item["status"] == "blocked" or "tracking_update" in item
|
||||
or any(task.get("registration") == "blocked" for task in item.get("consumer_tasks", []))
|
||||
for item in report["results"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -24,6 +24,7 @@ TAG = "v0.1.0-rc.1"
|
||||
PUBLISHED = "2026-11-27T08:00:00+08:00"
|
||||
ASSET = "text-source.tar.gz"
|
||||
ISSUES = "/repos/cflmy/marqdo/issues"
|
||||
CONSUMER_ISSUES = "/repos/cflmy/marqdo-ext-archive/issues"
|
||||
FORGE = reconcile.FORGE
|
||||
ACTOR = {"login": reconcile.RECONCILE_ACCOUNT}
|
||||
COMPONENT = {"id": "std-text", "sha": BASE, "path": "stdlib/text",
|
||||
@@ -34,6 +35,7 @@ class FakeForge:
|
||||
def __init__(self):
|
||||
self.writes = []
|
||||
self.issues = []
|
||||
self.consumer_issues = []
|
||||
self.comments = {}
|
||||
self.pages = []
|
||||
self.pipeline_reads = []
|
||||
@@ -77,6 +79,7 @@ class FakeForge:
|
||||
records = {
|
||||
f"/repos/{REPO}/releases": self.releases,
|
||||
ISSUES: self.issues,
|
||||
CONSUMER_ISSUES: self.consumer_issues,
|
||||
"/repos/cflmy/marqdo/labels": [{"id": 5, "name": reconcile.LABEL}],
|
||||
**self.comments,
|
||||
}.get(path, [])
|
||||
@@ -111,10 +114,11 @@ class FakeForge:
|
||||
|
||||
def post(self, path, data):
|
||||
self.writes.append((path, data))
|
||||
item = {"body": data["body"], "user": ACTOR}
|
||||
if path == ISSUES:
|
||||
item["number"] = 100 + len(self.issues)
|
||||
self.issues.append(item)
|
||||
item = {"body": data["body"], "user": ACTOR, "state": "open"}
|
||||
if path in {ISSUES, CONSUMER_ISSUES}:
|
||||
issues = self.issues if path == ISSUES else self.consumer_issues
|
||||
item["number"] = 100 + len(issues)
|
||||
issues.append(item)
|
||||
else:
|
||||
self.comments.setdefault(path, []).append(item)
|
||||
return item
|
||||
@@ -144,6 +148,7 @@ class ReconcileTest(unittest.TestCase):
|
||||
|
||||
def test_consumer_inputs_are_tied_to_assets_dependencies_and_accepted_sha(self):
|
||||
consumer = {"id": "archive", "state": "active", "sha": "c" * 40,
|
||||
"remote": FORGE + "/cflmy/marqdo-ext-archive.git",
|
||||
"requires": ["std-text", "cli"], "checks_with": []}
|
||||
cli = {"id": "cli", "state": "active", "sha": "d" * 40,
|
||||
"requires": [], "checks_with": []}
|
||||
@@ -169,6 +174,26 @@ class ReconcileTest(unittest.TestCase):
|
||||
self.assertEqual(task["different_dependencies"], ["cli"])
|
||||
self.assertEqual(self.forge.writes, [])
|
||||
|
||||
def test_apply_creates_one_consumer_issue_and_records_new_inputs_in_it(self):
|
||||
consumer = {"id": "archive", "state": "active", "sha": "c" * 40,
|
||||
"remote": FORGE + "/cflmy/marqdo-ext-archive.git",
|
||||
"requires": ["std-text"], "checks_with": []}
|
||||
graph = {item["id"]: item for item in (COMPONENT, consumer)}
|
||||
with patch.object(reconcile, "managed_repositories", return_value=(BASE, graph, {REPO: COMPONENT})):
|
||||
entry, = self.run_scan(apply=True)["results"]
|
||||
task, = entry["consumer_tasks"]
|
||||
self.assertEqual(task["registration"], "recorded")
|
||||
self.assertEqual(task["issue"], 100)
|
||||
self.assertIn(FORGE + "/cflmy/marqdo/issues/100", self.forge.consumer_issues[0]["body"])
|
||||
self.run_scan(apply=True)
|
||||
self.assertEqual(len(self.forge.writes), 2)
|
||||
consumer["sha"] = "e" * 40
|
||||
self.run_scan(apply=True)
|
||||
self.assertEqual(len(self.forge.consumer_issues), 1)
|
||||
self.assertEqual(len(self.forge.comments[CONSUMER_ISSUES + "/100/comments"]), 1)
|
||||
self.run_scan(apply=True)
|
||||
self.assertEqual(len(self.forge.comments[CONSUMER_ISSUES + "/100/comments"]), 1)
|
||||
|
||||
def test_apply_creates_one_verified_tracker_then_rechecks_it(self):
|
||||
entry, = self.run_scan(apply=True)["results"]
|
||||
self.assertEqual(entry["status"], "created")
|
||||
|
||||
Reference in new issue
Block a user