image: python:3.9-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
  - build # Build

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

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

backend test:
  before_script:
    - python -V
  image: python:3.9-buster
  stage: tests and linting
  script:
    - make test
  artifacts:
    reports:
      cobertura: coverage.xml

backend build:
  before_script:
    - python -V
  image: python:3.9-buster
  stage: build
  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: build
  script:
    - cd frontend
    - npm install -g npm@latest
    - NODE_ENV=production
    - npm ci 
    - npm run build:no-env
