summaryrefslogtreecommitdiff
path: root/ci
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2020-11-28 08:59:54 -0500
committerNed Batchelder <ned@nedbatchelder.com>2020-11-28 19:48:31 -0500
commit52e361421322414c5a30dc490805195bfb402ea7 (patch)
treec500f35999278a823ef4e016e424ad6fe4bb226d /ci
parent10b2f67dc55d2886adf2286f320e13223a23fbed (diff)
downloadpython-coveragepy-git-52e361421322414c5a30dc490805195bfb402ea7.tar.gz
Building kits with GitHub Actions
Diffstat (limited to 'ci')
-rw-r--r--ci/download_gha_artifacts.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/ci/download_gha_artifacts.py b/ci/download_gha_artifacts.py
new file mode 100644
index 00000000..9580dced
--- /dev/null
+++ b/ci/download_gha_artifacts.py
@@ -0,0 +1,40 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
+
+"""Use the GitHub API to download built artifacts."""
+
+import os
+import os.path
+import zipfile
+
+import requests
+
+def download_url(url, filename):
+ """Download a file from `url` to `filename`."""
+ response = requests.get(url, stream=True)
+ if response.status_code == 200:
+ with open(filename, "wb") as f:
+ for chunk in response.iter_content(16*1024):
+ f.write(chunk)
+
+def unpack_zipfile(filename):
+ """Unpack a zipfile, using the names in the zip."""
+ with open(filename, "rb") as fzip:
+ z = zipfile.ZipFile(fzip)
+ for name in z.namelist():
+ print(f" extracting {name}")
+ z.extract(name)
+
+dest = "dist"
+repo_owner = "nedbat/coveragepy"
+temp_zip = "artifacts.zip"
+
+if not os.path.exists(dest):
+ os.makedirs(dest)
+os.chdir(dest)
+
+r = requests.get(f"https://api.github.com/repos/{repo_owner}/actions/artifacts")
+latest = max(r.json()["artifacts"], key=lambda a: a["created_at"])
+download_url(latest["archive_download_url"], temp_zip)
+unpack_zipfile(temp_zip)
+os.remove(temp_zip)