---
name: "Master branch verification"

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  tests:
    name: "Python ${{ matrix.python-version }}"
    runs-on: "ubuntu-latest"
    env:
      USING_COVERAGE: '3.8'
      USING_DOCS: '3.7'
      USING_DIST: '3.9'

    strategy:
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9", "pypy3"]

    steps:
      - uses: "actions/checkout@v2"
      - uses: "actions/setup-python@v2"
        with:
          python-version: "${{ matrix.python-version }}"
      - name: "Install dependencies"
        run: |
          set -xe
          python -VV
          python -m site
          python -m pip install --upgrade pip setuptools wheel
          python -m pip install --upgrade coverage[toml] virtualenv tox tox-gh-actions
      - name: "Run tox targets for ${{ matrix.python-version }}"
        run: tox
      - name: "Get coverage"
        if: "contains(env.USING_COVERAGE, matrix.python-version)"
        run: |
          set -xe
          tox -e coverage-report
      - name: "Upload coverage to Codecov"
        if: "contains(env.USING_COVERAGE, matrix.python-version)"
        uses: "codecov/codecov-action@v1"
        with:
          fail_ci_if_error: true
      - name: "Build package"
        if: "contains(env.USING_DIST, matrix.python-version)"
        id: build
        run: |
          set -xe
          python setup.py sdist bdist_wheel
      - name: "Upload dist artifacts"
        if: "contains(env.USING_DIST, matrix.python-version)"
        uses: actions/upload-artifact@v2
        with:
          name: package-dist
          path: dist/
      - name: "Upload docs artifacts"
        if: "contains(env.USING_DOCS, matrix.python-version)"
        uses: actions/upload-artifact@v2
        with:
          name: docs_html
          path: docs/_build/html
#      - name: "Publish package to TestPyPI"
#        if: "contains(env.TESTPYPI_PUBLISH, matrix.python-version)"
#        uses: pypa/gh-action-pypi-publish@v1.3.1
#        with:
#          skip_existing: true
#          user: __token__
#          password: ${{ secrets.TESTPYPI_TOKEN }}
#          repository_url: https://test.pypi.org/legacy/
