|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright Advanced Micro Devices, Inc. |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +"""Publish ROCm release files from an artifacts bucket to release buckets. |
| 6 | +
|
| 7 | +These release file types are supported: |
| 8 | +
|
| 9 | +- [x] tarballs |
| 10 | +- [ ] python packages |
| 11 | +- [ ] native linux packages |
| 12 | +- [ ] native windows packages |
| 13 | +
|
| 14 | +Example with ``--run-id 12345 --platform linux --release-type dev``: |
| 15 | +
|
| 16 | + s3://therock-dev-artifacts/12345-linux/tarballs/therock-dist-linux-gfx94X-dcgpu-7.10.0.tar.gz |
| 17 | + -> s3://therock-dev-tarball/v4/tarball/therock-dist-linux-gfx94X-dcgpu-7.10.0.tar.gz |
| 18 | +
|
| 19 | +Test usage: |
| 20 | + python build_tools/github_actions/publish_rocm_to_release_buckets.py \\ |
| 21 | + --run-id 12345 --platform linux --release-type dev --dry-run |
| 22 | +""" |
| 23 | + |
| 24 | +import argparse |
| 25 | +import logging |
| 26 | +import platform as platform_module |
| 27 | +import sys |
| 28 | +from pathlib import Path |
| 29 | + |
| 30 | +_BUILD_TOOLS_DIR = Path(__file__).resolve().parent.parent |
| 31 | +sys.path.insert(0, str(_BUILD_TOOLS_DIR)) |
| 32 | + |
| 33 | +from _therock_utils.s3_buckets import get_release_bucket_config |
| 34 | +from _therock_utils.storage_backend import StorageBackend, create_storage_backend |
| 35 | +from _therock_utils.storage_location import StorageLocation |
| 36 | +from _therock_utils.workflow_outputs import WorkflowOutputRoot |
| 37 | + |
| 38 | +logger = logging.getLogger(__name__) |
| 39 | + |
| 40 | + |
| 41 | +def publish_tarballs( |
| 42 | + artifacts_root: WorkflowOutputRoot, |
| 43 | + release_type: str, |
| 44 | + backend: StorageBackend, |
| 45 | +) -> int: |
| 46 | + """Copy tarballs from the artifacts bucket to the release tarball bucket. |
| 47 | +
|
| 48 | + Example: |
| 49 | + s3://therock-dev-artifacts/12345-linux/tarballs/ |
| 50 | + -> s3://therock-dev-tarball/v4/tarball/ |
| 51 | +
|
| 52 | + Returns: |
| 53 | + Number of tarballs copied. |
| 54 | + """ |
| 55 | + source = artifacts_root.tarballs() |
| 56 | + dest_bucket = get_release_bucket_config(release_type, "tarball") |
| 57 | + dest = StorageLocation(dest_bucket.name, "v4/tarball") |
| 58 | + |
| 59 | + logger.info("Tarballs: %s -> %s", source.s3_uri, dest.s3_uri) |
| 60 | + count = backend.copy_directory(source, dest, include=["*.tar.gz"]) |
| 61 | + logger.info("Copied %d tarballs", count) |
| 62 | + if count == 0: |
| 63 | + raise FileNotFoundError(f"No tarballs found at {source.s3_uri}") |
| 64 | + |
| 65 | + |
| 66 | +def main(argv: list[str]) -> None: |
| 67 | + parser = argparse.ArgumentParser( |
| 68 | + description="Publish ROCm release files to release buckets" |
| 69 | + ) |
| 70 | + parser.add_argument("--run-id", required=True, help="Source workflow run ID") |
| 71 | + parser.add_argument( |
| 72 | + "--platform", |
| 73 | + default=platform_module.system().lower(), |
| 74 | + choices=["linux", "windows"], |
| 75 | + help="Platform (default: current system)", |
| 76 | + ) |
| 77 | + parser.add_argument( |
| 78 | + "--release-type", |
| 79 | + required=True, |
| 80 | + choices=["dev", "nightly", "prerelease"], |
| 81 | + help="Release type (determines source and destination buckets)", |
| 82 | + ) |
| 83 | + parser.add_argument( |
| 84 | + "--dry-run", action="store_true", help="Print plan without copying" |
| 85 | + ) |
| 86 | + args = parser.parse_args(argv) |
| 87 | + |
| 88 | + artifacts_root = WorkflowOutputRoot.from_workflow_run( |
| 89 | + run_id=args.run_id, platform=args.platform, release_type=args.release_type |
| 90 | + ) |
| 91 | + backend = create_storage_backend(dry_run=args.dry_run) |
| 92 | + |
| 93 | + publish_tarballs(artifacts_root, args.release_type, backend) |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == "__main__": |
| 97 | + logging.basicConfig(level=logging.INFO) |
| 98 | + main(sys.argv[1:]) |
0 commit comments