server:setup:
  image: python
  stage: setup
  only:
    refs:
      - dev
      - merge_requests
    changes:
      - server/**/*
  artifacts:
    paths:
      - server/env
    expire_in: 15 min
    untracked: true
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - server/env
  script:
    - python --version
    - pip install virtualenv
    - cd server/
    - python -m venv env
    - source env/bin/activate
    - pip install -r requirements.txt

server:test:
  image: python
  stage: test
  needs: ["server:setup"]
  only:
    refs:
      - dev
      - merge_requests
    changes:
      - server/**/*
  script:
    - cd server
    - source env/bin/activate
    - pytest --cov app tests/
    - coverage xml
    - python coverage_report.py
  artifacts:
    reports:
      cobertura: server/coverage.xml
