mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-25 11:03:55 +01:00
fix(release): wait for GitHub draft readback before tagging Builds
This commit is contained in:
committed by
John Winter Murphy
parent
9bb2a519ac
commit
535e71178c
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
REPO = "Such-Software/hash-wallet"
|
||||
@@ -80,6 +81,21 @@ def has_release_driver(commit):
|
||||
return source.returncode == 0 and source.stdout.strip() == Path(__file__).read_text().strip()
|
||||
|
||||
|
||||
def confirm_draft(commit, tag, ref):
|
||||
for delay in (0, 1, 2, 4, 8):
|
||||
if delay:
|
||||
time.sleep(delay)
|
||||
canonical = remote_tag("origin", ref)
|
||||
release = release_for(tag)
|
||||
if canonical is not None and canonical != commit:
|
||||
raise ValueError(f"GitHub tag {tag} moved to a different commit")
|
||||
if release is not None and not release["draft"]:
|
||||
raise ValueError(f"GitHub release {tag} is already public")
|
||||
if canonical == commit and release is not None:
|
||||
return release
|
||||
raise ValueError("GitHub did not confirm the exact release tag and draft")
|
||||
|
||||
|
||||
def stage(commit, tag, version, ref, canonical, builds, release):
|
||||
if not has_release_driver(commit):
|
||||
raise ValueError("The exact release commit does not contain this desktop release automation")
|
||||
@@ -95,9 +111,7 @@ def stage(commit, tag, version, ref, canonical, builds, release):
|
||||
"--title", f"Hash Bags {version}", "--notes", ""],
|
||||
check=True,
|
||||
)
|
||||
release = release_for(tag)
|
||||
if release is None or not release["draft"] or remote_tag("origin", ref) != commit:
|
||||
raise ValueError("GitHub did not confirm the exact release tag and draft")
|
||||
release = confirm_draft(commit, tag, ref)
|
||||
if builds is None:
|
||||
subprocess.run(["git", "push", "gitea-builds", f"{commit}:{ref}"], check=True)
|
||||
if remote_tag("gitea-builds", ref) != commit:
|
||||
|
||||
@@ -49,6 +49,24 @@ class DesktopReleaseTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "AppImage"):
|
||||
release.verify_assets({"assets": []}, ["Hash_Bags-x86_64.AppImage"])
|
||||
|
||||
def test_staging_waits_for_the_draft_without_recreating_it(self):
|
||||
commit = "a" * 40
|
||||
tag = "hash-bags-1.2.3-build4"
|
||||
draft = {"draft": True, "html_url": "https://example.invalid/draft"}
|
||||
with (
|
||||
patch.object(release, "has_release_driver", return_value=True),
|
||||
patch.object(release, "release_for", side_effect=[None, draft]),
|
||||
patch.object(release, "remote_tag", return_value=commit),
|
||||
patch.object(release.subprocess, "run") as run,
|
||||
patch.object(release.time, "sleep") as sleep,
|
||||
contextlib.redirect_stdout(io.StringIO()),
|
||||
):
|
||||
release.stage(commit, tag, "1.2.3", f"refs/tags/{tag}", commit, None, None)
|
||||
actions = [call.args[0] for call in run.call_args_list]
|
||||
self.assertEqual([action[0] for action in actions], ["gh", "git"])
|
||||
self.assertIn("--draft", actions[0])
|
||||
sleep.assert_called_once()
|
||||
|
||||
|
||||
class DesktopPublisherTests(unittest.TestCase):
|
||||
def test_tag_build_refuses_public_release(self):
|
||||
|
||||
Reference in New Issue
Block a user