fix(cd): 校验候选部署入口并隔离凭据
build / build (push) Successful in 1m30s

This commit is contained in:
姚章浩
2026-11-23 13:28:40 +08:00
parent 1beaa31771
commit 0246db357f
4 changed files with 23 additions and 14 deletions
+3 -7
View File
@@ -31,13 +31,9 @@ def verify_job(run_id, plan, repo):
guard = [job for job in jobs if job.get('name') == 'guard' and job.get('conclusion') == 'success']
cd.require(len(guard) == 1 and type(guard[0].get('id')) is int, 'candidate guard did not succeed')
# Gitea logs are plaintext and may prefix each line with a timestamp.
from urllib.request import ProxyHandler, build_opener
from urllib.request import Request
token = os.environ['KG_CANDIDATE_READ_TOKEN']
request = Request(cd.FORGE + candidate.API + f'/actions/jobs/{guard[0]["id"]}/logs',
headers={'Authorization': 'token ' + token})
with build_opener(ProxyHandler({}), cd.NoRedirect()).open(request, timeout=15) as response:
lines = response.read(2**20).decode().splitlines()
raw = coordinator.hfx.forge('GET', candidate.API + f'/actions/jobs/{guard[0]["id"]}/logs', raw=True)
cd.require(len(raw) <= 2**20, 'candidate guard log exceeded the read limit')
lines = raw.decode().splitlines()
cd.require(sum(line.strip().endswith(candidate.proof(plan, 'prepare')) for line in lines) == 1,
'candidate input does not match Gitea guard proof')