diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/collect_artifacts_metadata.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/collect_artifacts_metadata.py b/tools/collect_artifacts_metadata.py new file mode 100644 index 0000000000..2757afb4a0 --- /dev/null +++ b/tools/collect_artifacts_metadata.py @@ -0,0 +1,55 @@ +import os +import json +import subprocess +import urllib.request +import urllib.error + + +def url_exists(url): + req = urllib.request.Request(url, method="HEAD") + try: + resp = urllib.request.urlopen(req, timeout=10) + except urllib.error.URLError: + return False + return resp.status == 200 + + +job_data = json.loads(os.environ["JOB_DATA"]) +job_result = job_data["result"] +print(f"Build job result: {job_result}") +assert job_result == "success" + +manifest_data = {} +for output_name, output_data in job_data["outputs"].items(): + prefix, _, slug = output_name.partition("-") + if prefix != "artifact" or not slug: + print(f"Ignoring output '{output_name}'...") + continue + artifact_data = json.loads(output_data) + + print("Checking if package actually exists...", end="") + url = artifact_data["file_url"] + package_exists = url_exists(url) + if not package_exists: + print(f"fail ({url})") + continue + print("ok") + + manifest_data[slug] = artifact_data + +print(json.dumps(manifest_data, indent=2, sort_keys=True)) + +assert manifest_data + +with open("manifest.json", mode="w") as fp: + json.dump(manifest_data, fp, indent=2, sort_keys=True) + +if os.getenv("CI") == "true": + git_branch = ( + subprocess.check_output(("git", "rev-parse", "--abbrev-ref", "HEAD")) + .decode() + .strip() + ) + deploy_dir = os.environ["DEPLOY_DESTPATH"].format(git_branch=git_branch) + with open(os.environ["GITHUB_ENV"], mode="a") as fp: + fp.write(f"DEPLOY_DIR={deploy_dir}\n") |