fix(promote): read published digest from CI logs
This commit is contained in:
@@ -58,34 +58,22 @@ jobs:
|
||||
jobs_request = urllib.request.Request(f"{api_root}/actions/runs/{run['id']}/jobs", headers=api_headers)
|
||||
with urllib.request.urlopen(jobs_request, timeout=30) as response:
|
||||
jobs = json.load(response).get('jobs') or []
|
||||
if any(job.get('name') == 'server-image' and job.get('conclusion') == 'success' for job in jobs):
|
||||
candidates.append(run)
|
||||
for job in jobs:
|
||||
if job.get('name') == 'server-image' and job.get('conclusion') == 'success':
|
||||
candidates.append((run, job))
|
||||
if not candidates:
|
||||
raise SystemExit('No successful server-image workflow run was found')
|
||||
run = max(candidates, key=lambda item: (item.get('run_number', 0), item.get('run_attempt', 0)))
|
||||
run, job = max(candidates, key=lambda item: (item[0].get('run_number', 0), item[0].get('run_attempt', 0)))
|
||||
commit = run['head_sha']
|
||||
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
|
||||
credentials = base64.b64encode(
|
||||
f"{os.environ['HARBOR_USERNAME']}:{os.environ['HARBOR_PASSWORD']}".encode()
|
||||
).decode()
|
||||
headers = {'Authorization': f'Basic {credentials}'}
|
||||
|
||||
manifest_url = f'https://{registry}/v2/{encoded_repo}/manifests/{urllib.parse.quote(tag, safe="")}'
|
||||
manifest_headers = {
|
||||
**headers,
|
||||
'Accept': ', '.join([
|
||||
'application/vnd.oci.image.index.v1+json',
|
||||
'application/vnd.docker.distribution.manifest.list.v2+json',
|
||||
'application/vnd.oci.image.manifest.v1+json',
|
||||
'application/vnd.docker.distribution.manifest.v2+json',
|
||||
]),
|
||||
}
|
||||
request = urllib.request.Request(manifest_url, headers=manifest_headers)
|
||||
logs_url = f"{api_root}/actions/jobs/{job['id']}/logs"
|
||||
request = urllib.request.Request(logs_url, headers=api_headers)
|
||||
with urllib.request.urlopen(request, timeout=30) as response:
|
||||
response.read()
|
||||
digest = response.headers.get('Docker-Content-Digest', '')
|
||||
if not re.fullmatch(r'sha256:[0-9a-f]{64}', digest):
|
||||
raise SystemExit(f'Registry returned invalid manifest digest for {tag}')
|
||||
logs = response.read().decode(errors='replace')
|
||||
digest_match = re.search(r'Digest:\s+registry\.aeternalisgames\.com/[^@\s]+@(sha256:[0-9a-f]{64})', logs)
|
||||
if not digest_match:
|
||||
raise SystemExit(f'No published digest found in successful server-image job {job["id"]}')
|
||||
digest = digest_match.group(1)
|
||||
print(f'digest={digest}')
|
||||
print(f'build={digest.removeprefix("sha256:")}')
|
||||
print(f'tag={tag}')
|
||||
|
||||
@@ -58,34 +58,22 @@ jobs:
|
||||
jobs_request = urllib.request.Request(f"{api_root}/actions/runs/{run['id']}/jobs", headers=api_headers)
|
||||
with urllib.request.urlopen(jobs_request, timeout=30) as response:
|
||||
jobs = json.load(response).get('jobs') or []
|
||||
if any(job.get('name') == 'server-image' and job.get('conclusion') == 'success' for job in jobs):
|
||||
candidates.append(run)
|
||||
for job in jobs:
|
||||
if job.get('name') == 'server-image' and job.get('conclusion') == 'success':
|
||||
candidates.append((run, job))
|
||||
if not candidates:
|
||||
raise SystemExit('No successful server-image workflow run was found')
|
||||
run = max(candidates, key=lambda item: (item.get('run_number', 0), item.get('run_attempt', 0)))
|
||||
run, job = max(candidates, key=lambda item: (item[0].get('run_number', 0), item[0].get('run_attempt', 0)))
|
||||
commit = run['head_sha']
|
||||
tag = f"sha-{commit}-run-{run['run_number']}-{run.get('run_attempt', 1)}"
|
||||
credentials = base64.b64encode(
|
||||
f"{os.environ['HARBOR_USERNAME']}:{os.environ['HARBOR_PASSWORD']}".encode()
|
||||
).decode()
|
||||
headers = {'Authorization': f'Basic {credentials}'}
|
||||
|
||||
manifest_url = f'https://{registry}/v2/{encoded_repo}/manifests/{urllib.parse.quote(tag, safe="")}'
|
||||
manifest_headers = {
|
||||
**headers,
|
||||
'Accept': ', '.join([
|
||||
'application/vnd.oci.image.index.v1+json',
|
||||
'application/vnd.docker.distribution.manifest.list.v2+json',
|
||||
'application/vnd.oci.image.manifest.v1+json',
|
||||
'application/vnd.docker.distribution.manifest.v2+json',
|
||||
]),
|
||||
}
|
||||
request = urllib.request.Request(manifest_url, headers=manifest_headers)
|
||||
logs_url = f"{api_root}/actions/jobs/{job['id']}/logs"
|
||||
request = urllib.request.Request(logs_url, headers=api_headers)
|
||||
with urllib.request.urlopen(request, timeout=30) as response:
|
||||
response.read()
|
||||
digest = response.headers.get('Docker-Content-Digest', '')
|
||||
if not re.fullmatch(r'sha256:[0-9a-f]{64}', digest):
|
||||
raise SystemExit(f'Registry returned invalid manifest digest for {tag}')
|
||||
logs = response.read().decode(errors='replace')
|
||||
digest_match = re.search(r'Digest:\s+registry\.aeternalisgames\.com/[^@\s]+@(sha256:[0-9a-f]{64})', logs)
|
||||
if not digest_match:
|
||||
raise SystemExit(f'No published digest found in successful server-image job {job["id"]}')
|
||||
digest = digest_match.group(1)
|
||||
print(f'digest={digest}')
|
||||
print(f'build={digest.removeprefix("sha256:")}')
|
||||
print(f'tag={tag}')
|
||||
|
||||
Reference in New Issue
Block a user