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')
+2 -2
View File
@@ -19,7 +19,7 @@ PATH = Path.home() / '.local/state/kg-hifox-release'
RUN_ID = re.compile('[1-9][0-9]{0,14}')
def forge(method, path, payload=None):
def forge(method, path, payload=None, *, raw=False):
request = Request(cd.FORGE + path, method=method,
data=json.dumps(payload).encode() if payload is not None else None)
env = {**os.environ, 'GIT_TERMINAL_PROMPT': '0', 'GIT_ASKPASS': '/bin/false'}
@@ -31,7 +31,7 @@ def forge(method, path, payload=None):
request.add_header('Authorization', 'Basic ' + auth)
request.add_header('Content-Type', 'application/json')
with build_opener(ProxyHandler({}), cd.NoRedirect()).open(request, timeout=20) as response:
return json.load(response)
return response.read(2**20 + 1) if raw else json.load(response)
def hifox(cli, *args):