name: publish PyPI and TestPyPI

on:
  push:
    branches:
    - master
    - rc

jobs:
  build-linux:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash -l {0}
    strategy:
      matrix:
        python-version: ["3.10", ]

    steps:
    - uses: actions/checkout@v4
    # Use conda-incubator/setup-miniconda for precise control of conda infrastructure
    - uses: conda-incubator/setup-miniconda@v3
      with:
        auto-update-conda: true
        channels: conda-forge
        channel-priority: strict
        python-version: ${{ matrix.python-version }}
    - name: Make sdist
      run: |
        conda activate test
        conda install --yes python=${{ matrix.python-version }}
        conda install --yes "libblas=*=*openblas" openblas cmake c-compiler numpy
        ./get_nanoversion.sh
        cat __nanoversion__.txt
        python setup.py sdist
    - name: Publish package to TestPyPI
      if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/rc')
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        user: __token__
        password: ${{ secrets.TEST_PYPI_API_TOKEN }}
        repository_url: https://test.pypi.org/legacy/
    - name: Publish package to PyPI
      if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/master')
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        user: __token__
        password: ${{ secrets.PYPI_API_TOKEN }}
