From 6edbe5ee73f59e34251c0a1b644b64359fb6add0 Mon Sep 17 00:00:00 2001 From: Andrew Pan Date: Wed, 15 Feb 2023 14:23:41 -0600 Subject: [PATCH] action.py: use requests library for download --- action.py | 26 ++++++++------------------ requirements.txt | 1 + 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/action.py b/action.py index d3f214c..53e8a9a 100755 --- a/action.py +++ b/action.py @@ -26,6 +26,8 @@ from glob import glob from pathlib import Path +import requests + _HERE = Path(__file__).parent.resolve() _TEMPLATES = _HERE / "templates" @@ -57,26 +59,14 @@ def _download_ref_asset(ext): repo = os.getenv('GITHUB_REPOSITORY') ref = os.getenv("GITHUB_REF") - artifact = f"{os.getenv('GITHUB_REF_NAME')}-signed{ext}" + artifact = f"/tmp/{os.getenv('GITHUB_REF_NAME')}{ext}" # GitHub supports /:org/:repo/archive/:ref<.tar.gz|.zip>. - # XX: will this work in Windows runners? - curl_status = subprocess.run( - ["curl", - "-f", - "-L", - "-o", str(artifact), - f"https://github.com/{repo}/archive/{ref}{ext}"], - text=True, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - # do not pass environment to curl - ) - _debug(curl_status.stdout) - - if curl_status.returncode != 0: - _summary(f"❌ failed to download {ext} archive for {ref}") - return None + r = requests.get(f"https://github.com/{repo}/archive/{ref}{ext}", stream=True) + r.raise_for_status() + with Path(artifact).open("wb") as io: + for chunk in r.iter_content(chunk_size=None): + io.write(chunk) return artifact diff --git a/requirements.txt b/requirements.txt index 60843c3..e99b40c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ sigstore ~= 1.1 +requests ~= 2.28