Give some additional information about what is going on

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-09-12 10:40:36 +01:00 committed by Gareth J. Greenaway
parent 618d26013e
commit 866e40e12a
2 changed files with 35 additions and 6 deletions

View file

@ -214,6 +214,7 @@ def download_file(
auth: str | None = None,
headers: dict[str, str] | None = None,
) -> pathlib.Path:
ctx.info(f"Downloading {dest.name!r} @ {url} ...")
curl = shutil.which("curl")
if curl is not None:
command = [curl, "-sS", "-L"]
@ -240,7 +241,6 @@ def download_file(
ctx.exit(1)
return dest
# NOTE the stream=True parameter below
ctx.info(f"Downloading {url} ...")
with ctx.web as web:
web.headers.update(headers)
with web.get(url, stream=True, auth=auth) as r:

View file

@ -63,6 +63,9 @@ def download_onedir_artifact(
artifact_name += ".zip"
else:
artifact_name += ".tar.xz"
ctx.info(
f"Searching for artifact {artifact_name} from run_id {run_id} in repository {repository} ..."
)
found_artifact_name = download_artifact(
ctx,
dest=artifacts_path,
@ -73,15 +76,24 @@ def download_onedir_artifact(
if found_artifact_name is None:
return ExitCode.FAIL
found_artifact_path = artifacts_path / found_artifact_name
checksum_algo = "sha512"
ctx.info(f"Validating {found_artifact_name!r} {checksum_algo} checksum ...")
artifact_expected_checksum = (
artifacts_path.joinpath(f"{found_artifact_name}.SHA512").read_text().strip()
artifacts_path.joinpath(f"{found_artifact_name}.{checksum_algo.upper()}")
.read_text()
.strip()
)
artifact_checksum = tools.utils.get_file_checksum(
found_artifact_path, checksum_algo
)
artifact_checksum = tools.utils.get_file_checksum(found_artifact_path, "sha512")
if artifact_expected_checksum != artifact_checksum:
ctx.error("The 'sha512' checksum does not match")
ctx.error(f"The {checksum_algo} checksum does not match")
ctx.error(f"{artifact_checksum!r} != {artifact_expected_checksum!r}")
return ExitCode.FAIL
ctx.info(
f"Decompressing {found_artifact_name!r} to {artifacts_path.relative_to(tools.utils.REPO_ROOT)}{os.path.sep} ..."
)
if found_artifact_path.suffix == ".zip":
with zipfile.ZipFile(found_artifact_path) as zfile:
zfile.extractall(path=artifacts_path)
@ -112,6 +124,9 @@ def download_nox_artifact(
)
return ExitCode.SOFT_FAIL
artifact_name = f"nox-{slug}-{nox_env}"
ctx.info(
f"Searching for artifact {artifact_name} from run_id {run_id} in repository {repository} ..."
)
found_artifact_name = download_artifact(
ctx,
dest=tools.utils.REPO_ROOT,
@ -181,6 +196,9 @@ def download_pkgs_artifact(
artifacts_path = tools.utils.REPO_ROOT / "pkg" / "artifacts"
artifacts_path.mkdir(exist_ok=True)
ctx.info(
f"Searching for artifact {artifact_name} from run_id {run_id} in repository {repository} ..."
)
found_artifact_name = download_artifact(
ctx,
dest=artifacts_path,
@ -229,9 +247,11 @@ def download_artifact(
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {github_token}",
"X-GitHub-Api-Version": "2022-11-28",
}
web.headers.update(headers)
page = 0
listed_artifacts: set[str] = set()
while True:
if found_artifact is not None:
break
@ -250,21 +270,30 @@ def download_artifact(
)
ctx.exit(1)
data = ret.json()
if data["total_count"] <= len(listed_artifacts):
ctx.info("Already gone through all of the listed artifacts:")
ctx.print(sorted(listed_artifacts))
break
ctx.debug(f"Processing artifacts listing (page: {page}) ...")
if not data["artifacts"]:
break
for artifact in data["artifacts"]:
listed_artifacts.add(artifact["name"])
ctx.debug(
f"Checking if {artifact['name']!r} matches {artifact_name!r} "
f"({len(listed_artifacts)}/{data['total_count']}) ..."
)
if fnmatch.fnmatch(artifact["name"], artifact_name):
found_artifact = artifact["name"]
tempdir_path = pathlib.Path(tempfile.gettempdir())
download_url = artifact["archive_download_url"]
ctx.info(f"Downloading {download_url}")
downloaded_artifact = tools.utils.download_file(
ctx,
download_url,
tempdir_path / f"{artifact['name']}.zip",
headers=headers,
)
ctx.info("Downloaded", downloaded_artifact)
ctx.info(f"Downloaded {downloaded_artifact}")
with zipfile.ZipFile(downloaded_artifact) as zfile:
zfile.extractall(path=dest)
break