Release: verify assets after draft publication
Modular container CI / release-build (push) Has been cancelled
Modular container CI / release-build (push) Has been cancelled
This commit is contained in:
2 files changed
+52
-8
No files matched your search
@@ -293,11 +293,9 @@ def release_assets(release: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
return assets
|
||||
|
||||
|
||||
def verify_assets(
|
||||
api: GiteaApi,
|
||||
release: dict[str, Any],
|
||||
artifacts: dict[str, Path],
|
||||
) -> None:
|
||||
def verify_asset_metadata(
|
||||
release: dict[str, Any], artifacts: dict[str, Path]
|
||||
) -> dict[str, dict[str, Any]]:
|
||||
remote: dict[str, dict[str, Any]] = {}
|
||||
for asset in release_assets(release):
|
||||
name = asset.get("name")
|
||||
@@ -308,14 +306,26 @@ def verify_assets(
|
||||
missing = sorted(set(artifacts) - set(remote))
|
||||
extra = sorted(set(remote) - set(artifacts))
|
||||
fail(f"release asset set mismatch (missing={missing}, extra={extra})")
|
||||
for name, path in artifacts.items():
|
||||
asset = remote[name]
|
||||
expected_size = path.stat().st_size
|
||||
if asset.get("size") != expected_size:
|
||||
fail(f"Gitea metadata size mismatch for {name}")
|
||||
return remote
|
||||
|
||||
|
||||
def verify_assets(
|
||||
api: GiteaApi,
|
||||
release: dict[str, Any],
|
||||
artifacts: dict[str, Path],
|
||||
) -> None:
|
||||
remote = verify_asset_metadata(release, artifacts)
|
||||
for name, path in artifacts.items():
|
||||
asset = remote[name]
|
||||
download_url = asset.get("browser_download_url")
|
||||
if not isinstance(download_url, str) or not download_url:
|
||||
fail(f"Gitea returned no download URL for {name}")
|
||||
expected_size = path.stat().st_size
|
||||
if asset.get("size") != expected_size:
|
||||
fail(f"Gitea metadata size mismatch for {name}")
|
||||
actual_size, actual_hash = api.remote_sha256(download_url)
|
||||
if actual_size != expected_size or actual_hash != sha256(path):
|
||||
fail(f"download verification failed for {name}")
|
||||
@@ -477,7 +487,12 @@ def publish(arguments: argparse.Namespace, api: GiteaApi) -> None:
|
||||
body=body,
|
||||
prerelease=arguments.prerelease,
|
||||
)
|
||||
verify_assets(api, release, artifacts)
|
||||
# Gitea deliberately returns 404 for draft download URLs to Actions task
|
||||
# tokens, even when that task created the release. Validate the complete
|
||||
# asset set and sizes while the release is private, then publish briefly
|
||||
# for byte-for-byte download verification. A failed verification is moved
|
||||
# back to draft before the error is reported.
|
||||
verify_asset_metadata(release, artifacts)
|
||||
_, release = api.request_json(
|
||||
"PATCH",
|
||||
f"{base}/releases/{release_id}",
|
||||
@@ -499,6 +514,25 @@ def publish(arguments: argparse.Namespace, api: GiteaApi) -> None:
|
||||
body=body,
|
||||
prerelease=arguments.prerelease,
|
||||
)
|
||||
try:
|
||||
verify_assets(api, release, artifacts)
|
||||
except SystemExit:
|
||||
try:
|
||||
api.request_json(
|
||||
"PATCH",
|
||||
f"{base}/releases/{release_id}",
|
||||
{
|
||||
"name": arguments.name,
|
||||
"body": body,
|
||||
"draft": True,
|
||||
"prerelease": arguments.prerelease,
|
||||
"target_commitish": arguments.target,
|
||||
},
|
||||
allowed_statuses=(200,),
|
||||
)
|
||||
except SystemExit:
|
||||
pass
|
||||
raise
|
||||
verify_tag_target(api, base, tag, arguments.target)
|
||||
print(f"published and verified release {tag} with {len(artifacts)} assets")
|
||||
|
||||
|
||||
Reference in new issue
Block a user