|
| 1 | +import json |
| 2 | +import os |
| 3 | +import pathlib |
| 4 | +import sys |
| 5 | +import tarfile |
| 6 | +import urllib.request |
| 7 | + |
| 8 | +if len(sys.argv) < 2: |
| 9 | + print("Specify artifact job name and artifact deployment name to download") |
| 10 | + sys.exit(1) |
| 11 | + |
| 12 | +artifact_job_name = sys.argv[1] |
| 13 | +artifact_file_name = sys.argv[2].format( |
| 14 | + version=os.environ.get("APPVEYOR_BUILD_VERSION") |
| 15 | +) |
| 16 | + |
| 17 | +build_jobs = {} |
| 18 | + |
| 19 | + |
| 20 | +def download_job_artifact(job_id, file_name, dest_file): |
| 21 | + url = f"https://ci.appveyor.com/api/buildjobs/{job_id}/artifacts/{file_name}" |
| 22 | + print(f"Downloading {url}...") |
| 23 | + urllib.request.urlretrieve(url, dest_file) |
| 24 | + |
| 25 | + |
| 26 | +def get_build_job_ids(): |
| 27 | + account_name = os.environ.get("APPVEYOR_ACCOUNT_NAME") |
| 28 | + project_slug = os.environ.get("APPVEYOR_PROJECT_SLUG") |
| 29 | + build_id = os.environ.get("APPVEYOR_BUILD_ID") |
| 30 | + url = f"https://ci.appveyor.com/api/projects/{account_name}/{project_slug}/builds/{build_id}" |
| 31 | + print(f"Fetching build details at {url}") |
| 32 | + req = urllib.request.Request(url) |
| 33 | + req.add_header("Content-type", "application/json") |
| 34 | + project = json.loads(urllib.request.urlopen(req).read().decode()) |
| 35 | + for job in project["build"]["jobs"]: |
| 36 | + build_jobs[job["name"]] = job["jobId"] |
| 37 | + |
| 38 | + |
| 39 | +current_dir = pathlib.Path(os.getcwd()) |
| 40 | +print("current_dir", current_dir) |
| 41 | + |
| 42 | +get_build_job_ids() |
| 43 | + |
| 44 | +# create "web" directory |
| 45 | +dist_path = current_dir.joinpath("python_dist") |
| 46 | +dist_path.mkdir(exist_ok=True) |
| 47 | +tar_path = current_dir.joinpath(artifact_file_name) |
| 48 | +download_job_artifact(build_jobs[artifact_job_name], artifact_file_name, tar_path) |
| 49 | +with tarfile.open(tar_path, "r:gz") as tar: |
| 50 | + tar.extractall(str(dist_path)) |
| 51 | +os.remove(tar_path) |
0 commit comments