Skip to content

Commit bc4cfa0

Browse files
committed
build: trigger_action.py is more helpful
1 parent ee19480 commit bc4cfa0

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ cheats: ## Create some useful snippets for releasing.
192192
python igor.py cheats | tee cheats.txt
193193

194194
relbranch: #: Create the branch for releasing (see howto.txt).
195-
git switch -c nedbat/release-$$(date +%Y%m%d)
195+
git switch -c nedbat/release-$$(date +%Y%m%d-%H%M%S)
196196

197197
relcommit1: #: Commit the first release changes (see howto.txt).
198198
git commit -am "docs: prep for $$(python setup.py --version)"
@@ -206,9 +206,11 @@ kit: ## Make the source distribution.
206206

207207
pypi_upload: ## Upload the built distributions to PyPI.
208208
python ci/trigger_action.py $(REPO_OWNER) publish-pypi
209+
@echo "Use that^ URL to approve the upload"
209210

210211
test_upload: ## Upload the distributions to PyPI's testing server.
211212
python ci/trigger_action.py $(REPO_OWNER) publish-testpypi
213+
@echo "Use that^ URL to approve the upload"
212214

213215
kit_local:
214216
# pip.conf looks like this:

ci/trigger_action.py

+36-10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"""Trigger a repository_dispatch GitHub action."""
55

66
import sys
7+
import time
78

89
from session import get_session
910

10-
repo_owner, event_type = sys.argv[1:]
11-
1211
# The GitHub URL makes no mention of which workflow to use. It's found based on
1312
# the event_type, which matches the types in the workflow:
1413
#
@@ -18,12 +17,39 @@
1817
# - build-kits
1918
#
2019

21-
url = f"https://api.github.com/repos/{repo_owner}/dispatches"
22-
data = {"event_type": event_type}
2320

24-
resp = get_session().post(url, json=data)
25-
if resp.status_code // 100 == 2:
26-
print("Success")
27-
else:
28-
print(f"Status: {resp.status_code}")
29-
print(resp.text)
21+
def latest_action_run(repo_owner, event):
22+
"""
23+
Get the newest action run for a certain kind of event.
24+
"""
25+
resp = get_session().get(
26+
f"https://api.github.com/repos/{repo_owner}/actions/runs?event={event}"
27+
)
28+
resp.raise_for_status()
29+
return resp.json()["workflow_runs"][0]
30+
31+
32+
def dispatch_action(repo_owner, event_type):
33+
"""
34+
Trigger an action with a particular dispatch event_type.
35+
Wait until it starts, and print the URL to it.
36+
"""
37+
latest_id = latest_action_run(repo_owner, "repository_dispatch")["id"]
38+
39+
url = f"https://api.github.com/repos/{repo_owner}/dispatches"
40+
data = {"event_type": event_type}
41+
42+
resp = get_session().post(url, json=data)
43+
resp.raise_for_status()
44+
print(f"Success: {resp.status_code}")
45+
while True:
46+
run = latest_action_run(repo_owner, "repository_dispatch")
47+
if run["id"] != latest_id:
48+
break
49+
print(".", end=" ", flush=True)
50+
time.sleep(0.5)
51+
print(run["html_url"])
52+
53+
54+
if __name__ == "__main__":
55+
dispatch_action(*sys.argv[1:])

0 commit comments

Comments
 (0)