name: Build nightly wheels and publish to PyTorch Index

on:
  push:
    branches:
      - nightly
  workflow_dispatch:

permissions:
  id-token: write
  contents: read

jobs:
  generate-matrix:
    if: github.repository_owner == 'pytorch'
    uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
    with:
      package-type: wheel
      os: linux
      test-infra-repository: pytorch/test-infra
      test-infra-ref: main
      runner-fleet: osdc
      with-cpu: disable
      with-cuda: enable
      with-rocm: enable
      python-versions: '["3.11", "3.12"]'
  build:
    needs: generate-matrix
    name: ${{ matrix.repository }}
    uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main
    strategy:
      fail-fast: false
    with:
      repository: pytorch/torchtitan
      ref: ""
      test-infra-repository: pytorch/test-infra
      test-infra-ref: main
      package-name: torchtitan
      build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
      pre-script: .github/scripts/update_version.sh
      trigger-event: ${{ github.event_name }}
      build-platform: 'python-build-package'
