Skip to content

Commit

Permalink
action.py: use requests library for download
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Pan <a@tny.town>
  • Loading branch information
tnytown committed Feb 15, 2023
1 parent e752fbe commit 77a8ee7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
26 changes: 8 additions & 18 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from glob import glob
from pathlib import Path

import requests

_HERE = Path(__file__).parent.resolve()
_TEMPLATES = _HERE / "templates"

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sigstore ~= 1.1
requests ~= 2.28

0 comments on commit 77a8ee7

Please sign in to comment.