name: Run tests on pull requests

on: [pull_request]

jobs:
  run-tests:
    runs-on: ubuntu-latest
    name: Run test suite

    # https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
    defaults:
      run:
        shell: bash -l {0}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      # See: https://github.com/marketplace/actions/setup-miniconda
      - name: Setup miniconda
        uses: conda-incubator/setup-miniconda@v2
        with:
          auto-update-conda: true
          miniforge-variant: Mambaforge
          channels: conda-forge
          activate-environment: {{ project_name }}
          environment-file: environment.yml
          use-mamba: true

      - name: Run tests
        run: |
          conda activate {{ project_name }}
          pip install -e .
          pytest

      # https://github.com/codecov/codecov-action
      - name: Upload code coverage
        uses: codecov/codecov-action@v2
        with:
          # fail_ci_if_error: true # optional (default = false)
          verbose: true # optional (default = false)
