diff --git a/Makefile b/Makefile index ad8018b51..fd510301a 100644 --- a/Makefile +++ b/Makefile @@ -192,7 +192,7 @@ cheats: ## Create some useful snippets for releasing. python igor.py cheats | tee cheats.txt relbranch: #: Create the branch for releasing (see howto.txt). - git switch -c nedbat/release-$$(date +%Y%m%d) + git switch -c nedbat/release-$$(date +%Y%m%d-%H%M%S) relcommit1: #: Commit the first release changes (see howto.txt). git commit -am "docs: prep for $$(python setup.py --version)" @@ -206,9 +206,11 @@ kit: ## Make the source distribution. pypi_upload: ## Upload the built distributions to PyPI. python ci/trigger_action.py $(REPO_OWNER) publish-pypi + @echo "Use that^ URL to approve the upload" test_upload: ## Upload the distributions to PyPI's testing server. python ci/trigger_action.py $(REPO_OWNER) publish-testpypi + @echo "Use that^ URL to approve the upload" kit_local: # pip.conf looks like this: diff --git a/ci/trigger_action.py b/ci/trigger_action.py index f0fd49c27..07399172e 100644 --- a/ci/trigger_action.py +++ b/ci/trigger_action.py @@ -4,11 +4,10 @@ """Trigger a repository_dispatch GitHub action.""" import sys +import time from session import get_session -repo_owner, event_type = sys.argv[1:] - # The GitHub URL makes no mention of which workflow to use. It's found based on # the event_type, which matches the types in the workflow: # @@ -18,12 +17,39 @@ # - build-kits # -url = f"https://api.github.com/repos/{repo_owner}/dispatches" -data = {"event_type": event_type} -resp = get_session().post(url, json=data) -if resp.status_code // 100 == 2: - print("Success") -else: - print(f"Status: {resp.status_code}") - print(resp.text) +def latest_action_run(repo_owner, event): + """ + Get the newest action run for a certain kind of event. + """ + resp = get_session().get( + f"https://api.github.com/repos/{repo_owner}/actions/runs?event={event}" + ) + resp.raise_for_status() + return resp.json()["workflow_runs"][0] + + +def dispatch_action(repo_owner, event_type): + """ + Trigger an action with a particular dispatch event_type. + Wait until it starts, and print the URL to it. + """ + latest_id = latest_action_run(repo_owner, "repository_dispatch")["id"] + + url = f"https://api.github.com/repos/{repo_owner}/dispatches" + data = {"event_type": event_type} + + resp = get_session().post(url, json=data) + resp.raise_for_status() + print(f"Success: {resp.status_code}") + while True: + run = latest_action_run(repo_owner, "repository_dispatch") + if run["id"] != latest_id: + break + print(".", end=" ", flush=True) + time.sleep(0.5) + print(run["html_url"]) + + +if __name__ == "__main__": + dispatch_action(*sys.argv[1:])