Nightly: materialize tag on publication
This commit is contained in:
1 parent
30e669359a
commit
9401f19ad5
4 files changed
+202
-21
No files matched your search
@@ -326,9 +326,11 @@ def verify_release_metadata(
|
||||
def verify_tag_target(
|
||||
api: GiteaApi, base: str, tag: str, expected_commit: str
|
||||
) -> None:
|
||||
_, document = api.request_json(
|
||||
"GET", f"{base}/tags/{quote(tag, safe='')}", allowed_statuses=(200,)
|
||||
)
|
||||
if not tag_target_exists(api, base, tag, expected_commit):
|
||||
fail("the release tag does not exist")
|
||||
|
||||
|
||||
def validate_tag_target(document: Any, expected_commit: str) -> None:
|
||||
if (
|
||||
not isinstance(document, dict)
|
||||
or not isinstance(document.get("commit"), dict)
|
||||
@@ -337,6 +339,24 @@ def verify_tag_target(
|
||||
fail("the release tag does not target the requested commit")
|
||||
|
||||
|
||||
def tag_target_exists(
|
||||
api: GiteaApi,
|
||||
base: str,
|
||||
tag: str,
|
||||
expected_commit: str,
|
||||
) -> bool:
|
||||
tag_path = quote(tag, safe="")
|
||||
status, document = api.request_json(
|
||||
"GET",
|
||||
f"{base}/tags/{tag_path}",
|
||||
allowed_statuses=(200, 404),
|
||||
)
|
||||
if status == 404:
|
||||
return False
|
||||
validate_tag_target(document, expected_commit)
|
||||
return True
|
||||
|
||||
|
||||
def publish(arguments: argparse.Namespace, api: GiteaApi) -> None:
|
||||
owner = arguments.owner
|
||||
repo = arguments.repo
|
||||
@@ -355,6 +375,17 @@ def publish(arguments: argparse.Namespace, api: GiteaApi) -> None:
|
||||
or any(character in arguments.name for character in "\r\n\0")
|
||||
):
|
||||
fail("the release name is invalid")
|
||||
is_nightly = arguments.prerelease and tag.startswith("nightly-")
|
||||
if arguments.allow_missing_draft_tag and not is_nightly:
|
||||
fail("--allow-missing-draft-tag is restricted to nightly-* prereleases")
|
||||
tag_exists = tag_target_exists(
|
||||
api,
|
||||
base,
|
||||
tag,
|
||||
arguments.target,
|
||||
)
|
||||
if not tag_exists and not is_nightly:
|
||||
fail("the release tag does not exist")
|
||||
tag_path = quote(tag, safe="")
|
||||
status, release = api.request_json(
|
||||
"GET",
|
||||
@@ -379,9 +410,10 @@ def publish(arguments: argparse.Namespace, api: GiteaApi) -> None:
|
||||
fail("Gitea returned an invalid release")
|
||||
if release.get("tag_name") != tag:
|
||||
fail("Gitea returned a release for the wrong tag")
|
||||
verify_tag_target(api, base, tag, arguments.target)
|
||||
release_id = release["id"]
|
||||
if not release.get("draft", False):
|
||||
if not tag_exists:
|
||||
fail("a published release has no Git tag")
|
||||
verify_release_metadata(
|
||||
release,
|
||||
tag=tag,
|
||||
@@ -588,6 +620,11 @@ def parser() -> argparse.ArgumentParser:
|
||||
body_group.add_argument("--body-file", type=Path)
|
||||
publish_parser.add_argument("--artifacts", type=Path, required=True)
|
||||
publish_parser.add_argument("--prerelease", action="store_true")
|
||||
publish_parser.add_argument(
|
||||
"--allow-missing-draft-tag",
|
||||
action="store_true",
|
||||
help="declare that a nightly-* tag may be created with its verified draft",
|
||||
)
|
||||
|
||||
prune_parser = subparsers.add_parser("prune-nightlies")
|
||||
prune_parser.add_argument("--owner", required=True)
|
||||
|
||||
Reference in new issue
Block a user