image: python:3.9

services:
  - mysql:5.7

variables:
  MYSQL_DATABASE: "test"
  MYSQL_ROOT_PASSWORD: "mysql"
  MYSQL_USER: "django"
  MYSQL_PASSWORD: "mysql"
  MYSQL_HOST: "mysql"

cache:
  paths:
    - ~/.cache/pip/

before_script:
  - python -V  # Print out python version for debugging
  - apt-get -qq update
  - apt-get -qq install -y python3-virtualenv python3 python3-dev python3-pip gettext default-mysql-client default-libmysqlclient-dev
  - export DJANGO_SETTINGS_MODULE=AKPlanning.settings_ci
  - ./Utils/setup.sh --prod
  - mysql --version

check:
  script:
    - ./Utils/check.sh --all

check-migrations:
  script:
    - source venv/bin/activate
    - ./manage.py makemigrations --dry-run --check

test:
  script:
    - source venv/bin/activate
    - echo "GRANT ALL on *.* to '${MYSQL_USER}';"| mysql -u root --password="${MYSQL_ROOT_PASSWORD}" -h mysql
    - pip install pytest-cov unittest-xml-reporting
    - coverage run --source='.' manage.py test --settings AKPlanning.settings_ci
  after_script:
    - source venv/bin/activate
    - coverage report
    - coverage xml
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml
      junit: unit.xml
