summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-07-24 11:35:56 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-07-24 11:35:56 -0400
commit3232c608a0b43011f96d1361fcb3066cc46b3956 (patch)
treeaf83a19975575996d99df7a70b3c29505a9b6779
parente87d2180079f42a6003d425f9486ee33d32a872d (diff)
downloadpython-coveragepy-git-3232c608a0b43011f96d1361fcb3066cc46b3956.tar.gz
build: better error reporting in download_gha_artifacts
-rw-r--r--ci/download_gha_artifacts.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/ci/download_gha_artifacts.py b/ci/download_gha_artifacts.py
index d3d2e932..7828d3f8 100644
--- a/ci/download_gha_artifacts.py
+++ b/ci/download_gha_artifacts.py
@@ -4,6 +4,7 @@
"""Use the GitHub API to download built artifacts."""
import datetime
+import json
import os
import os.path
import sys
@@ -47,17 +48,21 @@ dest = "dist"
repo_owner = sys.argv[1]
temp_zip = "artifacts.zip"
-if not os.path.exists(dest):
- os.makedirs(dest)
+os.makedirs(dest, exist_ok=True)
os.chdir(dest)
r = requests.get(f"https://api.github.com/repos/{repo_owner}/actions/artifacts")
-dists = [a for a in r.json()["artifacts"] if a["name"] == "dist"]
-if not dists:
- print("No recent dists!")
+if r.status_code == 200:
+ dists = [a for a in r.json()["artifacts"] if a["name"] == "dist"]
+ if not dists:
+ print("No recent dists!")
+ else:
+ latest = max(dists, key=lambda a: a["created_at"])
+ print(f"Artifacts created at {utc2local(latest['created_at'])}")
+ download_url(latest["archive_download_url"], temp_zip)
+ unpack_zipfile(temp_zip)
+ os.remove(temp_zip)
else:
- latest = max(dists, key=lambda a: a["created_at"])
- print(f"Artifacts created at {utc2local(latest['created_at'])}")
- download_url(latest["archive_download_url"], temp_zip)
- unpack_zipfile(temp_zip)
- os.remove(temp_zip)
+ print(f"Fetching artifacts returned status {r.status_code}:")
+ print(json.dumps(r.json(), indent=4))
+ sys.exit(1)