Upload release artifacts to staging bucket folder `release-artifacts/ `. These will be used when we later actually publish the release.
(ctx: Context, salt_version: str, artifacts_path: pathlib.Path)
| 41 | }, |
| 42 | ) |
| 43 | def upload_artifacts(ctx: Context, salt_version: str, artifacts_path: pathlib.Path): |
| 44 | """ |
| 45 | Upload release artifacts to staging bucket folder `release-artifacts/<salt-version>`. |
| 46 | |
| 47 | These will be used when we later actually publish the release. |
| 48 | """ |
| 49 | ctx.info("Preparing upload ...") |
| 50 | s3 = boto3.client("s3") |
| 51 | to_delete_paths: list[dict[str, str]] = [] |
| 52 | remote_path = f"release-artifacts/{salt_version}" |
| 53 | try: |
| 54 | ret = s3.list_objects( |
| 55 | Bucket=tools.utils.STAGING_BUCKET_NAME, |
| 56 | Prefix=remote_path, |
| 57 | ) |
| 58 | if "Contents" in ret: |
| 59 | objects = [] |
| 60 | for entry in ret["Contents"]: |
| 61 | if entry["Key"].endswith(".release-backup-done"): |
| 62 | continue |
| 63 | objects.append({"Key": entry["Key"]}) |
| 64 | to_delete_paths.extend(objects) |
| 65 | except ClientError as exc: |
| 66 | if "Error" not in exc.response: |
| 67 | raise |
| 68 | if exc.response["Error"]["Code"] != "404": |
| 69 | raise |
| 70 | |
| 71 | if to_delete_paths: |
| 72 | with tools.utils.create_progress_bar() as progress: |
| 73 | bucket_uri = f"s3://{tools.utils.STAGING_BUCKET_NAME}/{remote_path}" |
| 74 | task = progress.add_task(f"Deleting '{bucket_uri}'", total=1) |
| 75 | try: |
| 76 | ret = s3.delete_objects( |
| 77 | Bucket=tools.utils.STAGING_BUCKET_NAME, |
| 78 | Delete={"Objects": objects}, |
| 79 | ) |
| 80 | except ClientError: |
| 81 | log.exception("Failed to delete '%s'", bucket_uri) |
| 82 | finally: |
| 83 | progress.update(task, advance=1) |
| 84 | |
| 85 | ctx.info("Uploading release artifacts ...") |
| 86 | to_upload_paths: list[pathlib.Path] = [] |
| 87 | copy_exclusions = [ |
| 88 | ".json", |
| 89 | ] |
| 90 | for fpath in artifacts_path.iterdir(): |
| 91 | if fpath.suffix in copy_exclusions: |
| 92 | continue |
| 93 | to_upload_paths.append(fpath) |
| 94 | |
| 95 | try: |
| 96 | for fpath in to_upload_paths: |
| 97 | upload_path = f"{remote_path}/{fpath.name}" |
| 98 | size = fpath.stat().st_size |
| 99 | ctx.info(f" {upload_path}") |
| 100 | with tools.utils.create_progress_bar(file_progress=True) as progress: |