steps:
  - input: "Provide Release version here"
    id: input-release-version
    fields:
      - text: "What is the release version?"
        key: release-version

  - label: "Build and upload wheel"
    depends_on: ~
    key: "build-wheel"
    agents:
      queue: cpu_queue_release
    commands:
      - "curl -LsSf https://astral.sh/uv/install.sh | sh"
      - 'export PATH="$HOME/.local/bin:$PATH"'
      - "uv venv --python=3.12 && source .venv/bin/activate"
      - "uv pip install --upgrade build"
      - "python3 -m build"
      - "bash .buildkite/scripts/upload-nightly-wheels.sh"

  - label: "Generate and upload wheel indices"
    depends_on: "build-wheel"
    allow_dependency_failure: true
    agents:
      queue: small_cpu_queue_release
    commands:
      - "bash .buildkite/scripts/generate-and-upload-nightly-index.sh"

  - block: "Upload release wheels to PyPI"
    depends_on: "build-wheel"
    key: block-upload-release-wheels

  - label: "Upload release wheels to PyPI"
    depends_on:
      - block-upload-release-wheels
      - input-release-version
    key: upload-release-wheels
    agents:
      queue: small_cpu_queue_release
    commands:
      - "bash .buildkite/scripts/publish-release-wheels-pypi.sh"

  - block: "Unblock to build release Docker images"
    depends_on: ~
    key: block-build-release-images

  - group: "Build release Docker images"
    key: "build-release-images"
    depends_on: block-build-release-images
    allow_dependency_failure: true
    steps:
      - label: "Build release image - x86_64"
        key: build-release-image-x86
        depends_on: ~
        agents:
          queue: cpu_queue_release
        commands:
          - "aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/q9t5s3a7"
          - |
            DOCKER_BUILDKIT=1 docker build \
              --build-arg max_jobs=16 \
              --tag public.ecr.aws/q9t5s3a7/vllm-omni-release-repo:$BUILDKITE_COMMIT-$(uname -m) \
              --progress plain \
              -f docker/Dockerfile.cuda .
          - "docker push public.ecr.aws/q9t5s3a7/vllm-omni-release-repo:$BUILDKITE_COMMIT-$(uname -m)"
          # re-tag to default image tag and push, just in case arm64 build fails
          - "docker tag public.ecr.aws/q9t5s3a7/vllm-omni-release-repo:$BUILDKITE_COMMIT-$(uname -m) public.ecr.aws/q9t5s3a7/vllm-omni-release-repo:$BUILDKITE_COMMIT"
          - "docker push public.ecr.aws/q9t5s3a7/vllm-omni-release-repo:$BUILDKITE_COMMIT"
        env:
          DOCKER_BUILDKIT: "1"

      - label: "Build release image - aarch64"
        key: build-release-image-arm64
        depends_on: ~
        agents:
          queue: arm64_cpu_queue_release
        commands:
          - "aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/q9t5s3a7"
          - |
            DOCKER_BUILDKIT=1 docker build \
              --build-arg max_jobs=16 \
              --tag public.ecr.aws/q9t5s3a7/vllm-omni-release-repo:$BUILDKITE_COMMIT-$(uname -m) \
              --progress plain \
              -f docker/Dockerfile.cuda .
          - "docker push public.ecr.aws/q9t5s3a7/vllm-omni-release-repo:$BUILDKITE_COMMIT-$(uname -m)"
        env:
          DOCKER_BUILDKIT: "1"

  - block: "Publish release images to DockerHub"
    key: block-publish-release-images
    depends_on:
      - build-release-image-x86
      - build-release-image-arm64
      - input-release-version

  - label: "Publish release images to DockerHub"
    depends_on:
      - block-publish-release-images
    key: publish-release-images-dockerhub
    agents:
      queue: small_cpu_queue_release
    commands:
      - "bash .buildkite/scripts/publish-release-images.sh"
    plugins:
      - docker-login#v3.0.0:
          username: vllmbot
          password-env: DOCKERHUB_TOKEN
    env:
      DOCKER_BUILDKIT: "1"
      DOCKERHUB_USERNAME: "vllmbot"
