name: Release SGLang Kernel to PyPI

on:
  push:
    branches:
      - main
    paths:
      - sgl-kernel/python/sgl_kernel/version.py
  workflow_dispatch:

concurrency:
  group: release-pypi-kernel-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build-wheels:
    if: github.repository == 'sgl-project/sglang'
    runs-on: sgl-kernel-release-node
    strategy:
      matrix:
        python-version: ['3.9']
        cuda-version: ['12.4']

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: 'recursive'

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}

    - name: Build wheels for Python ${{ matrix.python-version }} and CUDA ${{ matrix.cuda-version }}
      run: |
        cd sgl-kernel
        chmod +x ./build.sh
        ./build.sh "${{ matrix.python-version }}" "${{ matrix.cuda-version }}"

    - name: Upload to pypi
      working-directory: sgl-kernel
      run: |
        pip install twine
        python3 -m twine upload dist/* -u __token__ -p ${{ secrets.PYPI_TOKEN }}
