# automatically generated by auxilium
image: {{ aux.ci.docker_image }}
{% if aux.ci.runner == "normal" -%}
services:
-   name: docker:dind
{%- endif %}

stages:
{% if aux.ci.mechanism == "monolith" -%}
-   mono
{% if "docs" not in aux.meta.disabled -%}
-   deploy
{%- endif %}
{%- else -%}
-   pre-build
-   build
-   run
-   release
-   deploy
{%- endif %}

variables:
    ROOT: $CI_BUILDS_DIR/root
    DOCKER_DIR: devops/docker
    DOCKER_CACHING:
        value: 'yes'
        description: 'Using the registry to cache images while building (yes/no).'
    DOCKER_LAYER_CACHING:
        value: 'yes'
        description: 'Using layers to cache while building an image (yes/no).'
    GIT_DEPTH: 2
    GIT_CLONE_PATH: $CI_BUILDS_DIR/root
    PROJECT_REGISTRY: $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME

workflow:
    rules:
    -   if: $CI_PIPELINE_SOURCE == "merge_request_event"
    -   if: $CI_PIPELINE_SOURCE == "push"
    -   if: $CI_PIPELINE_SOURCE == "schedule"
    -   if: $CI_PIPELINE_SOURCE == "web"

before_script:
-   echo -e "\e[0Ksection_start:`date +%s`:before_script[collapsed=true]\r\e[0Kbefore_script"
-   docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
-   'echo CI_PIPELINE_SOURCE: $CI_PIPELINE_SOURCE'
-   'echo CI_COMMIT_BRANCH: \"$CI_COMMIT_BRANCH\"'
-   'echo CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: \"$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME\"'
{%- if aux.ci.mechanism in ["mixed", "gitlab"] %}
-   export IMG_TAG="$CI_COMMIT_BRANCH$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
-   'echo IMG_TAG: \"$IMG_TAG\"'
{%- endif %}
{%- if aux.ci.mechanism in ["monolith", "mixed"] %}
-   apk add python3 > /dev/null
-   apk add py3-pip > /dev/null
-   pip3 install requests > /dev/null
-   apk add git > /dev/null
{%- endif %}
-   echo -e "\e[0Ksection_end:`date +%s`:before_script\r\e[0K"

{% if aux.ci.mechanism == "monolith" -%}
include:
-   local: devops/CI/01-rules.yml

monolith:
    stage: mono
    rules:
    -   !reference [.r-push-no-mr]
    -   !reference [.r-mr]
    -   !reference [.r-web]
    -   !reference [.r-pipeline]
    -   when: never
    script:
    -   python3 devops/CI/python_ci.py
{% include 'coverage.jinja2' %}
{% include 'tags.jinja2' %}
{%- if "docs" not in aux.meta.disabled %}
    artifacts:
        paths:
        -   devops/cache/docs/html
pages:
    rules:
    -   !reference [.r-release-push]
    -   when: never
    stage: deploy
    script:
    -   mkdir -p public
    -   cp -r devops/cache/docs/html/* public/
{% include 'tags.jinja2' %}
    artifacts:
        paths:
        -   public
    dependencies:
    -   monolith
{%- endif -%}
{%- else -%}
include:
-   local: devops/CI/01-rules.yml
-   local: devops/CI/02-template.yml
-   local: devops/CI/03-build.yml
-   local: devops/CI/04-run.yml
{%- endif %}
