#image: python:latest
image: continuumio/miniconda3

stages:
  - build
  - test
  - analyses

.dependencies_cache:
   cache:
       paths:
       - $CI_PROJECT_DIR/envs
       policy: pull

before_script:
  - python3 -V # Print out python version for debugging
  - eval "$(conda shell.bash hook)"
  - source ~/.bashrc
  - conda env list

navipy_install:
  tags:
  - GPU
  - Neurobiologie
  stage: build
  
  script:
  - apt-get update -y # Because ffmpeg is not found otherwise
  - apt-get install ffmpeg libsm6 libxext6  -y # for liggl
  - apt-get install -y -qq blender
  - bash autoinstall_blendnavipy.sh blender_navipy $CI_PROJECT_DIR/envs
  - eval "$(conda shell.bash hook)" # We reinit because new env
  - conda activate $CI_PROJECT_DIR/envs/blender_navipy
  - conda install flake8
  - conda install coverage
  - conda install pytest
  - conda install pytest-cov
  - pip install opencv-python
  - python navipy/scripts/config_matplotlib_server.py # because no interactive backend
  extends: .dependencies_cache
  cache:
    policy: pull-push

flake8:
  tags:
  - GPU
  - Neurobiologie
  stage: test
  dependencies:
  - navipy_install
  extends: .dependencies_cache
  script:
  - conda activate $CI_PROJECT_DIR/envs/blender_navipy
  - echo $CONDA_PREFIX
  - python3 -m flake8 navipy

coverage:
  tags:
  - GPU
  - Neurobiologie
  stage: analyses
  dependencies: 
  - navipy_install
  extends: .dependencies_cache
  script:
  - apt-get update -y; apt-get install -y -qq blender
  - apt-get install -y ffmpeg
  - conda activate $CI_PROJECT_DIR/envs/blender_navipy
  - echo $CONDA_PREFIX
  - python navipy/scripts/blendunittest.py
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  
  artifacts:
   reports:
     coverage_report:
        coverage_format: cobertura
        path : './coverage.xml'

coverage_noblend:
  tags:
  - GPU
  - Neurobiologie
  stage: analyses
  dependencies: 
  - navipy_install
  extends: .dependencies_cache
  script:
  - conda activate $CI_PROJECT_DIR/envs/blender_navipy
  - echo $CONDA_PREFIX
  - echo $PWD
  - ls
  - pytest ./ --cov-config=.coveragerc --cov --cov-report term --cov-report xml:coverage_noblend.xml
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  
  artifacts:
   reports:
     coverage_report:
        coverage_format: cobertura
        path : './coverage_noblend.xml'


doc_build:
  tags:
  - GPU
  - Neurobiologie
  stage: analyses
  dependencies:
  - navipy_install
  - coverage  
  extends: .dependencies_cache
  script:
  - apt-get update -y; apt-get install -y -qq pandoc
  - apt-get install -y make
  - conda activate $CI_PROJECT_DIR/envs/blender_navipy
  - echo $CONDA_PREFIX
  - cd doc ; make html

  artifacts:
    paths:
    - doc/build
    
    expire_in: 1 week
