# ===== DEFINE DEFAULT DOCKER IMAGE =====
image: dtuwindenergy/topfarm2:latest


# ===== TEST TOPFARM =====
test_topfarm:  # name the job what we like
  stage:  # build, test, deploy defined by default [2]
    test
  script:
  - pip install --upgrade git+https://gitlab.windenergy.dtu.dk/TOPFARM/PyWake.git
  - pip install -e .
  - mkdir -p /data/db
  - py.test
  tags:  # only runners with this tag can do the job [3]
  - python

  
# ===== TEST TOPFARM =====
test_topfarm_pep8:  # name the job what we like
  stage:  # build, test, deploy defined by default [2]
    test
  script:
  - pip install -e .
  - pycodestyle --ignore=E501,W504 --exclude="*Colonel*" topfarm
  tags:  # only runners with this tag can do the job [3]
  - python

# ===== TEST TOPFARM on Windows =====
test_topfarm_windows:  # name the job what we like
  variables:
    GIT_SUBMODULE_STRATEGY: normal
  stage:  # build, test, deploy defined by default [2]
    test
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  script:  # runs on windows machine due to tag below
  - conda init powershell
  - "if (test-path $PROFILE.CurrentUserAllHosts) { & $PROFILE.CurrentUserAllHosts}"
  - conda activate tf231
  - pip install --upgrade git+https://gitlab.windenergy.dtu.dk/TOPFARM/PyWake.git --no-deps
  - pip install -e .  --no-deps
  - python -m pytest --cov-report term-missing:skip-covered --cov=topfarm --cov-config .coveragerc --ignore=topfarm/cost_models/fuga/Colonel
  tags:  # tag for shared runner on windows machine
  - ANMH_old


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


# ===== BUILD DOCS AND PUSH TO PUBLIC WEBSITE =====
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 nbconvert --upgrade
  - pip install sphinx_rtd_theme
  - pip install git+https://github.com/vidartf/nbsphinx-link.git
  - pip install -e .
  - cd docs; make html
  - cd ../; mv docs/build/html public/
  artifacts:  # required for GitLab pages [1]
    paths:
    - public
  only:  # only run for these branches
  - master
  - /^test_doc.*/ 

  tags:  # only runners with this tag can do the job [3]
  - python

# ===== BUILD WHEELS AND UPLOAD TO PYPI =====
pypi:
  stage:  
    deploy
  only:
    - tags
#    - master
  script:
    - python3 -m pip install -U setuptools wheel
    - python3 setup.py sdist bdist_wheel
    - python3 -m pip install -U twine
    # - twine upload --repository-url https://test.pypi.org/legacy/ dist/* -u $TWINE_USERNAME -p $TWINE_PASSWORD # for testing purposes
    - twine upload dist/* -u $TWINE_USERNAME -p $TWINE_PASSWORD
  tags:  
    - python


# [1] GitLab page: https://docs.gitlab.com/ee/ci/yaml/#pages
# [2] CI stages: https://docs.gitlab.com/ee/ci/yaml/#stages
# [3] Tags: https://docs.gitlab.com/ee/ci/yaml/#tags
