Skip to content

Commit a785a28

Browse files
committed
ci: surface repository list api failures
1 parent 38a9e16 commit a785a28

1 file changed

Lines changed: 73 additions & 63 deletions

File tree

.github/scripts/sonatype_publish.py

Lines changed: 73 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -159,78 +159,88 @@ def main() -> int:
159159
f"{OSSRH_BASE}/manual/search/repositories?"
160160
f"ip=any&profile_id={urllib.parse.quote(namespace)}"
161161
)
162-
_, list_payload = request_json("GET", list_url, headers)
163-
repositories = (
164-
list_payload.get("repositories", [])
165-
if isinstance(list_payload, dict)
166-
else []
167-
)
168-
for item in repositories:
169-
if item.get("key") == repository_key and item.get("portal_deployment_id"):
170-
deployment_id = item.get("portal_deployment_id")
171-
break
172-
173-
if deployment_id:
174-
deployment_url = f"{PORTAL_BASE}/publishing/deployments/{deployment_id}"
175-
publish_triggered = False
176-
deadline = time.time() + timeout_minutes * 60
177-
178-
while time.time() <= deadline:
179-
status_url = (
180-
f"{PORTAL_BASE}/api/v1/publisher/status?"
181-
f"id={urllib.parse.quote(deployment_id)}"
162+
list_status, list_payload = request_json("GET", list_url, headers)
163+
if list_status is None or list_status < 200 or list_status >= 300:
164+
list_error = list_payload.get("error") if isinstance(list_payload, dict) else ""
165+
if not list_error:
166+
list_error = (
167+
f"HTTP {list_status}"
168+
if list_status is not None
169+
else "HTTP unknown"
182170
)
183-
_, status_payload = request_json("POST", status_url, headers)
184-
final_state = extract_deployment_state(status_payload)
185-
186-
if final_state == "PUBLISHED":
187-
result = "published"
188-
reason = ""
171+
reason = f"Repository list API failed after upload: {list_error}"
172+
else:
173+
repositories = (
174+
list_payload.get("repositories", [])
175+
if isinstance(list_payload, dict)
176+
else []
177+
)
178+
for item in repositories:
179+
if item.get("key") == repository_key and item.get("portal_deployment_id"):
180+
deployment_id = item.get("portal_deployment_id")
189181
break
190182

191-
if final_state in {"FAILED", "BROKEN", "ERROR"}:
192-
reason = f"Deployment entered terminal state: {final_state}"
193-
break
183+
if deployment_id:
184+
deployment_url = f"{PORTAL_BASE}/publishing/deployments/{deployment_id}"
185+
publish_triggered = False
186+
deadline = time.time() + timeout_minutes * 60
194187

195-
if (
196-
mode == "portal_api"
197-
and final_state == "VALIDATED"
198-
and not publish_triggered
199-
):
200-
publish_url = (
201-
f"{PORTAL_BASE}/api/v1/publisher/deployment/"
202-
f"{urllib.parse.quote(deployment_id)}"
188+
while time.time() <= deadline:
189+
status_url = (
190+
f"{PORTAL_BASE}/api/v1/publisher/status?"
191+
f"id={urllib.parse.quote(deployment_id)}"
203192
)
204-
publish_status, publish_payload = request_json(
205-
"POST",
206-
publish_url,
207-
headers,
208-
)
209-
if publish_status is None or publish_status >= 400:
210-
publish_error = publish_payload.get("error")
211-
if not publish_error:
212-
publish_error = (
213-
f"HTTP {publish_status}"
214-
if publish_status is not None
215-
else "HTTP unknown"
216-
)
217-
reason = f"Publish API failed: {publish_error}"
193+
_, status_payload = request_json("POST", status_url, headers)
194+
final_state = extract_deployment_state(status_payload)
195+
196+
if final_state == "PUBLISHED":
197+
result = "published"
198+
reason = ""
218199
break
219-
publish_triggered = True
220200

221-
if mode == "user_managed" and final_state == "VALIDATED":
222-
reason = "Mode user_managed requires manual publish in portal"
223-
break
201+
if final_state in {"FAILED", "BROKEN", "ERROR"}:
202+
reason = f"Deployment entered terminal state: {final_state}"
203+
break
224204

225-
time.sleep(10)
205+
if (
206+
mode == "portal_api"
207+
and final_state == "VALIDATED"
208+
and not publish_triggered
209+
):
210+
publish_url = (
211+
f"{PORTAL_BASE}/api/v1/publisher/deployment/"
212+
f"{urllib.parse.quote(deployment_id)}"
213+
)
214+
publish_status, publish_payload = request_json(
215+
"POST",
216+
publish_url,
217+
headers,
218+
)
219+
if publish_status is None or publish_status >= 400:
220+
publish_error = publish_payload.get("error")
221+
if not publish_error:
222+
publish_error = (
223+
f"HTTP {publish_status}"
224+
if publish_status is not None
225+
else "HTTP unknown"
226+
)
227+
reason = f"Publish API failed: {publish_error}"
228+
break
229+
publish_triggered = True
230+
231+
if mode == "user_managed" and final_state == "VALIDATED":
232+
reason = "Mode user_managed requires manual publish in portal"
233+
break
226234

227-
if result != "published" and not reason and final_state != "unknown":
228-
reason = (
229-
"Timed out waiting for deployment status. "
230-
f"Latest state={final_state}"
231-
)
232-
else:
233-
reason = "No portal deployment id found for repository"
235+
time.sleep(10)
236+
237+
if result != "published" and not reason and final_state != "unknown":
238+
reason = (
239+
"Timed out waiting for deployment status. "
240+
f"Latest state={final_state}"
241+
)
242+
else:
243+
reason = "No portal deployment id found for repository"
234244

235245
if result != "published" and not reason:
236246
reason = "Automatic publish did not complete"

0 commit comments

Comments
 (0)