summaryrefslogtreecommitdiff
path: root/ci/download_gha_artifacts.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2020-11-28 13:02:50 -0500
committerNed Batchelder <ned@nedbatchelder.com>2020-11-28 16:13:11 -0500
commit12eca0fc391bb2f89138df3d6dbaabf78ff32d86 (patch)
treec6af8c4c3ce1b8e3ef4b88079394e1adc61ef240 /ci/download_gha_artifacts.py
parent41d8aef04f172bcd78a27d7a2f138a8a712063bd (diff)
downloadpython-coveragepy-git-gh-actions.tar.gz
Remove unneeded CI and kitting supportgh-actions
We don't use AppVeyor or Travis anymore, or make manylinux or local wheels.
Diffstat (limited to 'ci/download_gha_artifacts.py')
-rw-r--r--ci/download_gha_artifacts.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/ci/download_gha_artifacts.py b/ci/download_gha_artifacts.py
new file mode 100644
index 00000000..c5b7bd28
--- /dev/null
+++ b/ci/download_gha_artifacts.py
@@ -0,0 +1,41 @@
+# 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 sys
+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(" extracting {}".format(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)