# Job to lint and test app
name: build

on:
  push:
  pull_request:
    branches: [ master ]
  workflow_dispatch:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.7
      uses: actions/setup-python@v1
      with:
        python-version: 3.7
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install pylint
    - name: Analysing the code with pylint
      run: |
        pylint --extension-pkg-whitelist=pygame --fail-under=5 visiomode/
    - uses: actions/cache@v2
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-:

  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.7
      - name: Run tests with coverage
        run: |
          pip install -e .
          pip install pytest
          pip install pytest-cov
          pytest --cov --cov-append --cov-report=xml
        env:
          REDIS_HOST: localhost
          REDIS_PORT: 6379
      - name: Upload coverage report to codecov
        uses: codecov/codecov-action@v1
        with:
          token: ${{ secrets.CODECOV_TOKEN }} 
          fail_ci_if_error: true 
          verbose: true  
