image: ubuntu:22.04

stages:
  - unit_tests
  - integration_tests

workflow:
  rules:
    - if: $CI_MERGE_REQUEST_IID
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

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

cache:
  paths:
    - .cache/pip
    - palm_env

before_script:
  - echo -e "\e[0Ksection_start:`date +%s`:apt_section[collapsed=true]\r\e[0KInstalling apt dependencies"
  - apt-get update
  - apt-get install -y python3-pip git
  - echo -e "\e[0Ksection_end:`date +%s`:apt_section\r\e[0K"
  - echo -e "\e[0Ksection_start:`date +%s`:pip_section[collapsed=true]\r\e[0KInstalling pip dependencies"
  - python3 --version
  - python3 -m pip install virtualenv
  - virtualenv palm_env
  - source palm_env/bin/activate
  - python3 -m pip install --editable .
  - echo -e "\e[0Ksection_end:`date +%s`:pip_section\r\e[0K"

unit_tests:
  stage: unit_tests
  tags:
    - cpus1
  script:
    - echo -e "\e[0Ksection_start:`date +%s`:unit_test_section[collapsed=false]\r\e[0KExecuting unit tests"
    - pytest -v tests/unit_tests
    - echo -e "\e[0Ksection_end:`date +%s`:unit_test_section\r\e[0K"

integration_tests:
  stage: integration_tests
  tags:
    - cpus1
  script:
    - echo -e "\e[0Ksection_start:`date +%s`:integration_test_section[collapsed=false]\r\e[0KExecuting palm_meteo_test"
    - tests/integration_tests/all_tests.sh
    - echo -e "\e[0Ksection_end:`date +%s`:integration_test_section\r\e[0K"

