fix(cd): 支持已合入主干的现场基线
build / build (push) Successful in 1m40s

This commit is contained in:
姚章浩
2026-11-23 13:48:07 +08:00
parent 922ff66533
commit 8faabdcf9e
3 changed files with 50 additions and 7 deletions
+11 -6
View File
@@ -86,18 +86,23 @@ def check_qa(plan, receipt, reports, authors):
f'{task}: required QA cases have not passed')
def git(*args, cwd=None):
def git(*args, cwd=None, allowed=(0,)):
env = dict(os.environ, GIT_TERMINAL_PROMPT='0')
return cd.run(['git', *args], 'read candidate source', cwd=cwd, env=env, timeout=120).decode().strip()
return cd.run(['git', *args], 'read candidate source', cwd=cwd, env=env, allowed=allowed,
timeout=120).decode().strip()
def verify_source(plan, repo):
check_plan(plan)
main_line = git('rev-list', '--first-parent', 'origin/main', cwd=repo).splitlines()
sha, base = plan['sha'], plan['base']
cd.require(sha in main_line and base in main_line and main_line.index(sha) < main_line.index(base),
'candidate and baseline must be ordered commits on main first-parent history')
check_scope(plan, lambda n: read_forge(API + f'/pulls/{n}'),
main_line[main_line.index(sha):main_line.index(base)])
cd.require(sha in main_line, 'candidate must be on main first-parent history')
cd.require(git('merge-base', sha, base, cwd=repo, allowed=(0, 1)) == base,
'running baseline must be an ancestor of the candidate')
# A previously deployed branch may enter main as a second parent. Its reachable
# commits are already represented by the baseline, but the integration itself is in scope.
added = git('rev-list', '--first-parent', f'{base}..{sha}', cwd=repo).splitlines()
check_scope(plan, lambda n: read_forge(API + f'/pulls/{n}'), added)
contexts = {line.split('#', 1)[0].strip() for line in CONTEXTS.read_text().splitlines()} - {''}
cd.verify_contexts(read_forge(API + f'/commits/{sha}/status'), contexts)