image: continuumio/anaconda3

stages:
  - test
  - test_plugins
  - deploy

# ===== TEST PyWake debian=====
test_PyWake:  # name the job what we like
  image: continuumio/anaconda3
  stage:  # build, test, deploy defined by default [2]
    test
  script:
  - pip install -e .[test] --timeout 1800 --default-timeout=1800
  - pytest
  tags:  # only runners with this tag can do the job [3]
  - ci-ubuntu

  
# ===== Check code style =====
check_code_style:  # name the job what we like
  stage:  # build, test, deploy defined by default [2]
    test
  script:
  - pip install -e .
  - pycodestyle --ignore=E501,W504,E741 py_wake
  tags:  # only runners with this tag can do the job [3]
  - python

# ===== TEST PyWake on Windows =====
test_PyWake_windows:  # name the job what we like
  stage:  # build, test, deploy defined by default [2]
    test
  script:  # runs on windows machine due to tag below
  - conda init powershell
  - "if (test-path $PROFILE.CurrentUserAllHosts) { & $PROFILE.CurrentUserAllHosts}"
  - conda activate py38
  - pip install -e .[test]
  - pytest --cov-report term-missing:skip-covered --cov=py_wake --cov-config .coveragerc
  tags:  # tag for shared runner on windows machine
  - ANMH_old

# ===== Trigger PyWakePark pipeline =====
trigger_pywake_park_test:
  stage: test_plugins
  variables:
    TRIGGER_BRANCH: $CI_COMMIT_REF_NAME
  trigger:
    project: TOPFARM/cuttingedge/pywake/pywake_park
    strategy: depend
  only:
    - schedules

# ===== Trigger PyWakeEllipSys pipeline =====
trigger_pywake_ellipsys_test:
  stage: test_plugins
  variables:
    TRIGGER_BRANCH: $CI_COMMIT_REF_NAME
  trigger:
    project: TOPFARM/cuttingedge/pywake/pywake_ellipsys
    strategy: depend
  only:
    - schedules

# ===== Trigger TriggerHub pipeline =====
trigger_hub_test:
  stage: test
  variables:
    TRIGGER_BRANCH: $CI_COMMIT_REF_NAME
  trigger:
    project: TOPFARMPrivate/triggerhub/pywaketriggers
    strategy: depend

# ===== build documentation =====
pages:  # "pages" is a job specifically for GitLab pages [1]
  stage:  # build, test, deploy defined by default [2]
    deploy
  script:  # use sphinx to build docs, move to public page
  - apt-get update
  - apt-get -y install make pandoc
  - pip install --upgrade pip
  - pip install pypandoc
  - pip install sphinx --upgrade
  - pip install nbsphinx --upgrade
  - pip install -e .[test]
  - cd docs/validation_report
  - python generate_validation_figures.py
  - cd report
  - apt-get install -y texlive-latex-extra
  - pdflatex validation_report.tex
  - bibtex validation_report.aux
  - pdflatex validation_report.tex
  - pdflatex validation_report.tex
  - cd ../../
  - pwd
  - make html
  #- make latexpdf
  - cd ../; mv docs/build/html public/
  artifacts:  # required for GitLab pages [1]
    paths:
    - public
  only:  # only run for these branches
  - /^test_doc.*/ 
  - master
  tags:  # only runners with this tag can do the job [3]
  - ci-ubuntu


pypi_linux:
  stage:  
    deploy
  only:
    - tags
    - test_pypi
  script:
    - apt-get update
    - apt-get install pandoc
    - pip install --upgrade pip
    - pip install pypandoc
    - pip install -e .[test] --upgrade
    - python -c 'from git_utils import get_tag; get_tag(verbose=True)'
    - python -m pip install -U setuptools wheel
    - python setup.py sdist bdist_wheel
    - python -m pip install -U twine
    - python -c 'from git_utils import rename_dist_file; rename_dist_file()'
    - twine upload dist/* -u $TWINE_USERNAME -p $TWINE_PASSWORD
    #- twine upload --repository-url https://test.pypi.org/legacy/ dist/* -u $TWINE_USERNAME -p $TWINE_PASSWORD # for testing purposes
  tags:  
  - ci-ubuntu

# current
# pypi_windows:
#   stage:  
#     deploy
#   only:
#     - tags
#     - test_pypi
#   script:
#     - c:/Anaconda3/envs/pyTopfarm/python.exe setup.py bdist_wheel
#     - twine upload dist/* -u %TWINE_USERNAME% -p %TWINE_PASSWORD%
#     #- twine upload --repository-url https://test.pypi.org/legacy/ dist/* -u %TWINE_USERNAME% -p %TWINE_PASSWORD% # for testing purposes
#   tags:  
#     - CPAV_old_PC