name: CI

on: [push, pull_request]

jobs:
  lint:
    timeout-minutes: 10
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.7]
        toxenv: [flake8, mypy, docs]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: python -m pip install tox
    - name: Run tox ${{ matrix.toxenv }}
      run: tox -e ${{ matrix.toxenv }}

  test:
    timeout-minutes: 10
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        python-version: [3.6, 3.7, 3.8, 3.9, "3.10-dev"]
        include:
        - python-version: 3.8
          os: macos-latest
        - python-version: 3.8
          os: windows-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: python -m pip install tox
    - name: Test
      run: tox -e py
    - name: Upload coverage report
      uses: codecov/codecov-action@v1

  deploy:
    timeout-minutes: 10
    runs-on: ubuntu-latest
    needs: [lint, test]
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0  # required for setuptools_scm
    - name: Build wheels
      uses: pypa/cibuildwheel@v2.1.2
      with:
        output-dir: dist/
      env:
        CIBW_BUILD: "cp3*-manylinux_x86_64"
        CIBW_MANYLINUX_X86_64_IMAGE: manylinux2010
        CIBW_ENVIRONMENT: "CFLAGS=-g0"
        CIBW_TEST_COMMAND: "cutadapt --help"
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.7
    - name: Make sdist
      run: |
        python -m pip install build
        python -m build --sdist
        ls -l dist/
    - name: Publish dev release to test PyPI
      if: contains(github.ref, '.dev')
      uses: pypa/gh-action-pypi-publish@v1.4.2
      with:
        user: __token__
        password: ${{ secrets.test_pypi_password }}
        repository_url: https://test.pypi.org/legacy/
    - name: Publish to PyPI
      if: "!contains(github.ref, '.dev')"
      uses: pypa/gh-action-pypi-publish@v1.4.2
      with:
        user: __token__
        password: ${{ secrets.pypi_password }}
