before_script:
    # Install requirements for empyre:
    - conda env create -q # -q: quiet/ no progressbar, because it spams the log!
    - conda init bash
    - source ~/.bashrc
    - conda activate empyre
    - conda info --envs
    # Install jutil via deploy token access:  # TODO: still needed?
    #- pip install git+https://empyre:"$JUTIL_DEPLOY_TOKEN"@jugit.fz-juelich.de/j.ungermann/jutil.git

stages:
    - test
    - deploy

test_style:
    stage: test
    image: continuumio/miniconda3:latest
    script:
        # -m: only run tests marked with "flake8"
        - pyroma .  # Checks setup.py for cheese!
        - python setup.py test --addopts "--flake8 -m flake8"

test_function:
    stage: test
    image: continuumio/miniconda3:latest
    script:
        # Execute all tests and also check coverage with --cov:
        - python setup.py test --addopts "--cov"
    artifacts:
        paths:
            - .coverage
        expire_in: 1 week

test_docs:
    stage: test
    image: continuumio/miniconda3:latest
    script:
        # -f: Force overwriting of any existing generated files.
        # -e: Put documentation for each module on its own page.
        # -o: Directory to place the output files. If it does not exist, it is created.
        # last parameter: module path
        - sphinx-apidoc -f -e -o docs/api src/empyre
        # Build the documentation from 'docs' and put into 'build/sphinx':
        - sphinx-build docs build/sphinx
    artifacts:
        paths:
            - build/sphinx
        expire_in: 1 week

test_install:
    stage: test
    image: continuumio/miniconda3:latest
    before_script: []  # before_script not needed here!
    script:
        - pip install .[all]

pages:
    stage: deploy
    image: busybox
    before_script: []  # before_script not needed here!
    script:
        - mkdir public
        - cp -r build/sphinx/* public/
        # -r: recursive, also copies subfolders!
    artifacts:
        paths:
            - public
    rules:
       - if:  '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_TAG =~ /^\d+\.\d+(\.\d+)?$/'

pypi:
    stage: deploy
    image: continuumio/miniconda3:latest
    before_script: []  # before_script not needed here!
    script:
        - pip install twine
        - python setup.py sdist bdist_wheel
        - twine upload -u __token__ -p $PYPI_ACCESS_TOKEN dist/*  # -u user -p password upload_source
    rules:  # similar to only/except, but newer!
        # Job is executed if branch is master AND if a tag is building which matches the regular expression!
        # ONLY executes if commit to master has a tag, ^:start, $:end, valid example: "1.2.3", no "-dev" at the end!
        - if: '$CI_COMMIT_TAG =~ /^\d+\.\d+(\.\d+)?$/'