name: Publish Nightly Version to PyPI

on:
  workflow_dispatch:
  schedule:
    - cron:  '0 0 * * 6' # release on every Sunday 00:00 UTC time

jobs:
  build-n-publish:
    if: github.event_name == 'workflow_dispatch' || github.repository == 'hpcaitech/ColossalAI'
    name: Build and publish Python 🐍 distributions 📦 to PyPI
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
    - uses: actions/checkout@v2

    - uses: actions/setup-python@v2
      with:
        python-version: '3.8.14'

    - run: NIGHTLY=1 python setup.py sdist build

    # publish to PyPI if executed on the main branch
    - name: Publish package to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        user: __token__
        password: ${{ secrets.PYPI_API_TOKEN }}
        verbose: true
