Skip to content

Commit

Permalink
Actually add script
Browse files Browse the repository at this point in the history
  • Loading branch information
wence- committed Nov 22, 2024
1 parent ff03396 commit 4812c12
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import requests
import subprocess
import pathlib
import sys


def get_commit_hash(dir: pathlib.Path) -> str | None:
try:
return subprocess.check_output(
["git", "rev-parse", "HEAD"], cwd=str(dir)
).decode()
except subprocess.CalledProcessError:
return None


def previous_run_hashes(token: str) -> str | None:
req = requests.get(
"https://api.github.com/repos/rapidsai/dask-upstream-testing/actions/artifacts",
headers={
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": token,
},
params={"name": "commit-hashes.txt", "page": 1, "per_page": 1},
)
if req.status_code != 200:
print("Couldn't find uploaded artifact")
return None
artifacts = req.json()["artifacts"]
try:
(artifact,) = artifacts
url = artifact["archive_download_url"]
url_req = requests.get(
url, headers={"X-GitHub-Api-Version": "2022-11-28", "Authorization": token}
)
if url_req.status_code != 302:
print("Failed", url_req.text)
loc = url_req.headers["Location"]
print(loc)
archive = requests.get(
loc, headers={"X-GitHub-Api-Version": "2022-11-28", "Authorization": token}
)
print(archive.status_code)
print(archive.text)
except ValueError:
# Didn't get exactly one artifact, assume we must rebuild
return None


if __name__ == "__main__":
TOKEN = sys.argv[1]
previous_run_hashes(TOKEN)

0 comments on commit 4812c12

Please sign in to comment.