name: Tests

on:
  push:
    branches-ignore:
      - master
  pull_request:
    branches:
      - master
      - '*.*.*'
  schedule:
    - cron:  '0 8 * * 1'

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.5, 3.6, 3.7, 3.8, 3.9]

    steps:
      - uses: actions/checkout@v2

      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      - name: Setup the WIMS server
        run: |
          docker run -itd --cpuset-cpus=$(($(cat /proc/cpuinfo | grep -e "processor\s*:\s*\d*" | wc -l) - 1)) -p 7777:80 --name wims-minimal qcoumes/wims-minimal
          docker exec -i wims-minimal ./bin/apache-config
          docker exec -i wims-minimal service apache2 restart

      - name: Install Tox and any other packages
        run: |
          pip install tox

      - name: Run Tox
        run: tox -e py

      - name: Upload coverage to Codecov
        if: matrix.python-version == 3.8
        uses: codecov/codecov-action@v1
        with:
          file: ./coverage.xml
