# automatically generated by auxilium
image: {% if aux.ci.use_adaux_img == True %}{{ aux.versions.ci_adaux_image }}{% else %}{{ aux.versions.ci_precursor_image }}{% endif %}

stages:
{% if aux.ci.mechanism == "monolith" -%}
-   mono
{% if "docs" not in aux.meta.disable -%}
-   deploy
{%- endif %}
{%- endif %}

variables:
    ROOT: $CI_BUILDS_DIR/root
    DOCKER_DIR: devops/docker
    GIT_DEPTH: 2
    GIT_CLONE_PATH: $CI_BUILDS_DIR/root
    PROJECT_REGISTRY: $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
    {%- for x, v in aux.ci.variables.items() %}
    {{ x }}:
        value: {{ v.value }}
        description: "{{ v.description }}"
        {%- if "options" in v %}
        options:
        {%- for o in v.options %}
        -   {{ o }}
        {%- endfor -%}
        {%- endif %}
    {%- endfor %}

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

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'
{%- if aux.ci.mechanism in ["monolith"] %}
{%- if aux.ci.use_adaux_img == False %}
-   . ~/venv/bin/activate
-   pip install {% if aux.project.slug == "adaux" %}-e "$GIT_CLONE_PATH" --config-settings editable_mode=strict{% else %}{{ aux.versions.adaux }}{% endif %} > /dev/null
{%- endif %}
{%- 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
{% for key in aux.ci.used_rules %}
{{ key }}:
    stage: mono
    rules:
    {% for rule in aux.ci.used_rules[key] -%}
    -   !reference [.r-{{ rule }}]
    {% endfor -%}
    {% for rule in aux.ci.used_tag_rules[key] -%}
    -   !reference [.r-{{ rule }}]
    {% endfor -%}
    -   when: never
{% include 'services.jinja2' %}
{% include 'needs.jinja2' %}
{% include 'variables.jinja2' %}
    script:
    -   adaux ci gitlab --job {{ key }}
    allow_failure:
        exit_codes:
        -   42  # draft mr exit
{% include 'coverage.jinja2' %}
{% include 'tags.jinja2' %}
{%- if "docs" not in aux.meta.disable %}
    artifacts:
        paths:
        -   devops/cache/docs/html
{% endif %}
{%- endfor %}
{% if "docs" not in aux.meta.disable %}
pages:
    rules:
    -   !reference [.r-release-push]
    -   when: never
    stage: deploy
{% set key = "pages" %}{% include 'services.jinja2' %}
{% set key = "pages" %}{% include 'needs.jinja2' %}
{% set key = "pages" %}{% include 'variables.jinja2' %}
    script:
    -   mkdir -p public
    -   cp -r devops/cache/docs/html/* public/
{% set key = "pages" %}{% include 'tags.jinja2' %}
    artifacts:
        paths:
        -   public
    dependencies:
    -   default
{%- endif -%}
{%- endif %}
