name: Publish to TestPyPI

on: 
  push:
    tags:
      # Only run on tags that look like version number, alpha, beta, or rc
      - '[0-9]+.[0-9]+'
      - '[0-9]+.[0-9]+[ab][0-9]+'
      - '[0-9]+.[0-9]+rc[0-9]+'
      - '[0-9]+.[0-9]+_[ab][0-9]+'
      - '[0-9]+.[0-9]+_rc[0-9]+'
      - '[0-9]+.[0-9]+.[0-9]+'
      - '[0-9]+.[0-9]+.[0-9]+[ab][0-9]+'
      - '[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
      - '[0-9]+.[0-9]+.[0-9]+_[ab][0-9]+'
      - '[0-9]+.[0-9]+.[0-9]+_rc[0-9]+'
    

jobs:
  build:
    name: Build distribution
    # Only run on main branch
    # if: endsWith(github.ref, 'main')
    runs-on: ubuntu-latest

    steps:
    - name: Check out repository code
      uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: "3.x"
    - name: Install dependencies for testing
      run: |
        python -m pip install --upgrade pip
        pip install .[test]
    - name: Test with Pytest
      run: |
        pip install pytest 
        pytest -v -s tests/
    - name: Install pypa/build
      run: >-
        python3 -m
        pip install
        build
        --user
    - name: Build a binary wheel and a source tarball
      run: python3 -m build
    - name: Store the distribution packages
      uses: actions/upload-artifact@v3
      with:
        name: python-package-distributions
        path: dist/



  publish-to-testpypi:
    name: Publish to TestPyPI
    needs:
    - build
    runs-on: ubuntu-latest

    environment:
      name: testpypi
      url: https://test.pypi.org/p/acgc

    permissions:
      id-token: write  # IMPORTANT: mandatory for trusted publishing

    steps:
    - name: Download all the dists
      uses: actions/download-artifact@v3
      with:
        name: python-package-distributions
        path: dist/
    - name: Upload to TestPyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://test.pypi.org/legacy/
