stages:
  - build
  - test
  - deploy


webui:
  stage: build
  image: node:14
  cache:
    paths:
      - webui/node_modules/
  before_script:
    - cd webui/
    - npm install
  script:
    - npm run build
  artifacts:
    expire_in: 1 day
    paths:
      - webui/dist/


.python_test_template: &python_test_definition
  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - .cache/pip
      - env/
  before_script:
    - python -V
    - python -m venv env
    - source env/bin/activate
    - apt-get update
    - apt-get install -y libgl1-mesa-glx
    - pip install -r requirements.txt
    - pip install -r requirements.dev.txt
  script:
    - make run_coverage
    - make run_pylint

tests_3.6:
  stage: test
  image: python:3.6
  only:
    - master
  <<: *python_test_definition

tests_3.7:
  stage: test
  image: python:3.7
  only:
    - master
  <<: *python_test_definition

tests_3.8:
  stage: test
  image: python:3.8
  only:
    - master
  <<: *python_test_definition

tests_3.9:
  stage: test
  image: python:3.9
  <<: *python_test_definition
  after_script:
    - source env/bin/activate
    - coverage report -m

tests_3.10:
  stage: test
  image: python:3.10-rc
  allow_failure: true
  only:
    - master
  <<: *python_test_definition


bundle:
  stage: deploy
  image: alpine
  script:
    - mv webui/dist dist
    - rm -rf webui
    - mv dist webui
  artifacts:
    expire_in: 30 days
    paths:
      - settings.json
      - app.py
      - pycs/
      - webui/
      - labels
      - models
