|
25 | 25 | import urllib.request |
26 | 26 | from typing import Any |
27 | 27 |
|
| 28 | +from github_actions_utils import write_output |
| 29 | + |
28 | 30 | OSSRH_BASE = "https://ossrh-staging-api.central.sonatype.com" |
29 | 31 | PORTAL_BASE = "https://central.sonatype.com" |
30 | 32 |
|
@@ -64,14 +66,6 @@ def extract_deployment_state(payload: dict[str, Any]) -> str: |
64 | 66 | return "unknown" |
65 | 67 |
|
66 | 68 |
|
67 | | -def write_output(key: str, value: str) -> None: |
68 | | - output_path = os.environ.get("GITHUB_OUTPUT", "").strip() |
69 | | - if not output_path: |
70 | | - return |
71 | | - with open(output_path, "a", encoding="utf-8") as stream: |
72 | | - stream.write(f"{key}={value}\n") |
73 | | - |
74 | | - |
75 | 69 | def to_int(value: str, default: int) -> int: |
76 | 70 | try: |
77 | 71 | return int(value) |
@@ -190,7 +184,26 @@ def main() -> int: |
190 | 184 | f"{PORTAL_BASE}/api/v1/publisher/status?" |
191 | 185 | f"id={urllib.parse.quote(deployment_id)}" |
192 | 186 | ) |
193 | | - _, status_payload = request_json("POST", status_url, headers) |
| 187 | + poll_status, status_payload = request_json( |
| 188 | + "POST", |
| 189 | + status_url, |
| 190 | + headers, |
| 191 | + ) |
| 192 | + if poll_status is None or poll_status < 200 or poll_status >= 300: |
| 193 | + poll_error = ( |
| 194 | + status_payload.get("error") |
| 195 | + if isinstance(status_payload, dict) |
| 196 | + else "" |
| 197 | + ) |
| 198 | + if not poll_error: |
| 199 | + poll_error = ( |
| 200 | + f"HTTP {poll_status}" |
| 201 | + if poll_status is not None |
| 202 | + else "HTTP unknown" |
| 203 | + ) |
| 204 | + reason = f"Status polling API failed: {poll_error}" |
| 205 | + break |
| 206 | + |
194 | 207 | final_state = extract_deployment_state(status_payload) |
195 | 208 |
|
196 | 209 | if final_state == "PUBLISHED": |
@@ -234,7 +247,7 @@ def main() -> int: |
234 | 247 |
|
235 | 248 | time.sleep(10) |
236 | 249 |
|
237 | | - if result != "published" and not reason and final_state != "unknown": |
| 250 | + if result != "published" and not reason: |
238 | 251 | reason = ( |
239 | 252 | "Timed out waiting for deployment status. " |
240 | 253 | f"Latest state={final_state}" |
|
0 commit comments