image: python:3.10-buster

variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

cache:
  paths:
    - .cache/pip
    - venv/ # makes the virtual env available for jobs

stages:
  - venv update # Keep the cached virtual env up to date with dependencies
  - tests and linting # Run test/linting for frontend and backend

update:
  before_script:
    - python -V
  image: python:3.10-buster
  stage: venv update
  script:
    - make clean
    - make install

backend lint:
  before_script:
    - python -V
  image: python:3.10-buster
  stage: tests and linting
  script:
    - make lint

backend test:
  before_script:
    - python -V
  image: python:3.10-buster
  stage: tests and linting
  script:
    - make test
  coverage: /^TOTAL.*\s+(\d+\%)$/
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage.xml

backend build:
  before_script:
    - python -V
  image: python:3.10-buster
  stage: tests and linting
  script:
    - pip install poetry
    - poetry build

frontend test:
  image: node:16-alpine
  stage: tests and linting
  script:
    - cd frontend
    - npm install -g npm@latest
    - npm ci
    - npm run coverage:ci
  coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'

frontend lint:
  image: node:16-alpine
  stage: tests and linting
  script:
    - cd frontend
    - npm install -g npm@latest
    - npm ci
    - npm run lint

frontend build:
  image: node:16-alpine
  stage: tests and linting
  script:
    - cd frontend
    - npm install -g npm@latest
    - NODE_ENV=production
    - npm ci
    - npm run build:no-env