# docker packages
image: registry.gitlab.com/islandoftex/images/texlive:TL2021-historic


workflow:
  # avoid to trigger pipeline for each commit
  # pipeline should be triggered using https://forge.nemo-ocean.eu/nemo/doc/manuals/-/pipelines/new
  rules:
    - if: $CI_PIPELINE_SOURCE == 'web'
    - if: $CI_PIPELINE_SOURCE == 'schedule'
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_COMMIT_TITLE =~ /(?i).*\[ci\].*/


variables:
  MANUALS:
    description: "Manual(s) to be built"
    value: "all"
    options:
      - "all"
      - "NEMO"
      - "SI3"
      - "TOP"
  # input version for release (available only when pipeline is run manually)
  DRAFT_MODE:
    description: "Enable/disable latex draft mode (faster rendering without figures)"
    value: "yes"
    options:
      - "yes"
      - "no"
  DEBUG_MODE:
    description: "Print or not latex compilation details in log file for debugging"
    value: "no"
    options:
      - "yes"
      - "no"
  VERSION:
    value: ""
    description: "Set version release number for manuals"
  GIT_SUBMODULE_STRATEGY: recursive


before_script:
  - if [[ ${DRAFT_MODE} == "no" ]]; then BUILD_OPT="-p"; fi
  - if [[ ${DEBUG_MODE} == "yes" ]]; then BASH_OPT="-x"; fi


NEMO manual:
  tags:
    - docker
  stage: build
  rules:
    - if: ($MANUALS == "NEMO" || $MANUALS == "all")
  script:
    - bash ${BASH_OPT} manual_build.sh ${BUILD_OPT} -r ${VERSION:-CI_COMMIT_REF_NAME} NEMO
  artifacts:
    paths:
      - NEMO_manual.pdf
    expire_in: 15 mins


SI3 manual:
  tags:
    - docker
  stage: build
  rules:
    - if: ($MANUALS == "SI3" || $MANUALS == "all")
  script:
    - bash ${BASH_OPT} manual_build.sh ${BUILD_OPT} -r ${VERSION:-CI_COMMIT_REF_NAME} SI3
  artifacts:
    paths:
      - SI3_manual.pdf
    expire_in: 15 mins


TOP manual:
  tags:
    - docker
  stage: build
  rules:
    - if: ($MANUALS == "TOP" || $MANUALS == "all")
  script:
    - bash ${BASH_OPT} manual_build.sh ${BUILD_OPT} -r ${VERSION:-CI_COMMIT_REF_NAME} TOP
  artifacts:
    paths:
      - TOP_manual.pdf
    expire_in: 15 mins


# generic job (needs to be parallelized)
.build_manual:
  tags:
    - docker
  stage: build
  script:
    - bash ${BASH_OPT} manual_build.sh ${BUILD_OPT} -r ${VERSION:-$CI_COMMIT_REF_NAME} ${MANUALS}
  artifacts:
    paths:
      - ./*_manual.pdf
    expire_in: 15 mins