trigger:
  - master
  - develop

jobs:
  - job: setup_env
    displayName: "Setup"
    strategy:
      matrix:
        Debian10:
          AGENT_NAME: "azpipelines-deb10"

    pool:
      name: linux-vms
      demands:
        - agent.name -equals $(AGENT_NAME)

    steps:
      - script: |
          sudo -u postgres psql -c 'DROP DATABASE IF EXISTS pipeline'
          sudo -u postgres psql -c 'DROP DATABASE IF EXISTS test_pipeline'
          sudo -u postgres psql -c 'CREATE DATABASE pipeline'

          rm -rf /myagent/_work/1/s/api/env
          cd /myagent/_work/1/s/api
          python3.8 -m venv env
          source env/bin/activate
          cd /myagent/_work/1/s/api/tacticalrmm
          pip install --no-cache-dir --upgrade pip
          pip install --no-cache-dir setuptools==52.0.0 wheel==0.36.2
          pip install --no-cache-dir -r requirements.txt -r requirements-test.txt -r requirements-dev.txt
        displayName: "Install Python Dependencies"

      - script: |
          cd /myagent/_work/1/s/api
          source env/bin/activate
          cd /myagent/_work/1/s/api/tacticalrmm
          coverage run manage.py test -v 2
          if [ $? -ne 0 ]; then
              exit 1
          fi
        displayName: "Run django tests"

      - script: |
          cd /myagent/_work/1/s/api
          source env/bin/activate
          black --exclude migrations/ --check tacticalrmm
          if [ $? -ne 0 ]; then
              exit 1
          fi
        displayName: "Codestyle black"

      - script: |
          cd /myagent/_work/1/s/api
          source env/bin/activate
          cd /myagent/_work/1/s/api/tacticalrmm
          export CIRCLE_BRANCH=$BUILD_SOURCEBRANCH
          coveralls
        displayName: "coveralls"
        env:
          CIRCLECI: 1
          CIRCLE_BUILD_NUM: $(Build.BuildNumber)
