Verified Commit 1427d671 authored by Adrian DC's avatar Adrian DC
Browse files

ci(gitlab-ci): isolate 'pages' and 'pdf' to 'pages.yml' template

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent d4e58f82
Loading
Loading
Loading
Loading

.gitlab-ci.d/pages.yml

0 → 100644
+80 −0
Changes for .gitlab-ci.d/pages.yml: 80 added lines, 0 removed lines.
Original line number Diff line number Diff line
spec:
  inputs:
    stage:
      default: test
      description: 'Defines the pages stage (Default: test)'
    image:
      default: undefined:latest
      description: 'Specify the pages image (Default: undefined:latest)'
---

.pages:
  stage: $[[ inputs.stage ]]
  image: $[[ inputs.image ]]
  variables:
    CI_LOCAL_NETWORK: 'host'
    DOCS_PREPARE_WATCH_FILES: ./docs/.* ./docs/* ./mkdocs.yml ./README.md
    MKDOCS_EXPORTER_PDF_ENABLED: 'true'
    MKDOCS_EXPORTER_PDF_OUTPUT: 'undefined'
  script:
    # Fetch all tags
    - |
      if [ -z "${CI_LOCAL:-}" ]; then
        git fetch --tags --unshallow || true
      fi
    # Set PDF output version
    - export MKDOCS_EXPORTER_PDF_OUTPUT="${MKDOCS_EXPORTER_PDF_OUTPUT%.pdf}-$(git describe --abbrev=7 --always --tags).pdf"
    # Run locally without PDF
    - |
      if [ ! -z "${CI_LOCAL:-}" ] && [ ! "${CI_JOB_NAME:-}" = 'pdf' ]; then
        export MKDOCS_EXPORTER_PDF_ENABLED='false'
      fi
    # Validate network interfaces
    - |
      if [ ! -z "${CI_LOCAL:-}" ] && hostname -I | tr ' ' '\n' | grep '.' | wc -l | grep -q '^0$\|^1$'; then
        set +x
        echo ' '
        echo -n ' [INFO] Network addresses: '
        hostname -I
        echo ' '
        echo ' [ERROR] Incompatible local CI version detected or missing host network interfaces...'
        echo ' '
        exit 1
      fi
    # Prepare documentation
    - |
      if [ ! -z "${CI_LOCAL:-}" ]; then
        find ${DOCS_PREPARE_WATCH_FILES} -not -path ./docs/assets/stylesheets/variables.scss -type f | entr -n sh ./docs/prepare.sh &
        echo -n "${!}" >./docs/.serve.pid
        sleep 2
      else
        sh ./docs/prepare.sh
      fi
    # Generate documentation
    - |
      if [ ! -z "${CI_LOCAL:-}" ]; then
        network_ip=$(hostname -I | cut -d' ' -f1)
        mkdocs serve --dev-addr "${network_ip}:8001" --clean --config-file ./mkdocs.yml --verbose
      else
        mkdocs build --clean --config-file ./mkdocs.yml --verbose
      fi
  after_script:
    # Cleanup documentation
    - |
      if [ -e ./docs/.serve.pid ]; then
        cat ./docs/.serve.pid | xargs -r kill >/dev/null 2>&1 || true
      fi
    - sh ./docs/prepare.sh --clean
  artifacts:
    expire_in: 1 hour
    paths:
      - public

.pdf:
  extends:
    - .pages
  stage: $[[ inputs.stage ]]
  artifacts:
    expire_in: 1 hour
    paths:
      - public/$MKDOCS_EXPORTER_PDF_OUTPUT*.pdf
+11 −65
Changes for .gitlab-ci.yml: 11 added lines, 65 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@ include:
  - component: gitlab.com/RadianDevCore/tools/pre-commit-crocodile/commits@5.0.0
    inputs:
      stage: prepare
  - local: .gitlab-ci.d/pages.yml
    inputs:
      stage: deploy
      image: registry.gitlab.com/radiandevcore/tools/gitlab-projects-settings/gitlab-projects-settings:pages

stages:
  - development
@@ -837,7 +841,7 @@ deploy:trial:
    - if: $CI_LOCAL
  when: manual

.pages:
.pages:rules:
  rules:
    changes:
      - '.gitlab-ci.yml'
@@ -849,8 +853,8 @@ deploy:trial:
      - 'requirements/**/*'

pages:
  stage: deploy
  image: registry.gitlab.com/radiandevcore/tools/gitlab-projects-settings/gitlab-projects-settings:pages
  extends:
    - .pages
  needs:
    - job: registry:pages
      artifacts: false
@@ -871,81 +875,23 @@ pages:
      artifacts: false
      optional: true
  variables:
    CI_LOCAL_NETWORK: 'host'
    COVERAGE_FILE: !reference [.coverage-scripts, variables, COVERAGE_COMMON_FILE]
    COVERAGE_FOLDER: !reference [.coverage-scripts, variables, COVERAGE_FOLDER]
    COVERAGE_RCFILE: !reference [.coverage-scripts, variables, COVERAGE_RCFILE]
    MKDOCS_EXPORTER_PDF_ENABLED: 'true'
    DOCS_PREPARE_WATCH_FILES: ./config/* ./docs/.* ./docs/* ./mkdocs.yml ./README.md
    MKDOCS_EXPORTER_PDF_OUTPUT: 'gitlab-projects-settings'
  script:
    # Fetch all tags
    - |
      if [ -z "${CI_LOCAL:-}" ]; then
        git fetch --tags --unshallow || true
      fi
    # Set PDF output version
    - export MKDOCS_EXPORTER_PDF_OUTPUT="${MKDOCS_EXPORTER_PDF_OUTPUT%.pdf}-$(git describe --abbrev=7 --always --tags).pdf"
    # Run locally without PDF
    - |
      if [ ! -z "${CI_LOCAL:-}" ] && [ ! "${CI_JOB_NAME:-}" = 'pdf' ]; then
        export MKDOCS_EXPORTER_PDF_ENABLED='false'
      fi
    # Validate network interfaces
    - |
      if [ ! -z "${CI_LOCAL:-}" ] && hostname -I | tr ' ' '\n' | grep '.' | wc -l | grep -q '^0$\|^1$'; then
        set +x
        echo ' '
        echo -n ' [INFO] Network addresses: '
        hostname -I
        echo ' '
        echo ' [ERROR] Incompatible local CI version detected or missing host network interfaces...'
        echo ' '
        exit 1
      fi
    # Prepare documentation
    - |
      if [ ! -z "${CI_LOCAL:-}" ]; then
        find ./config/* ./docs/.* ./docs/* ./mkdocs.yml ./README.md -not -path ./docs/assets/stylesheets/variables.scss -type f | entr -n sh ./docs/prepare.sh &
        echo -n "${!}" >./docs/.serve.pid
        sleep 2
      else
        sh ./docs/prepare.sh
      fi
    # Generate documentation
    - |
      if [ ! -z "${CI_LOCAL:-}" ]; then
        network_ip=$(hostname -I | cut -d' ' -f1)
        mkdocs serve --dev-addr "${network_ip}:8001" --clean --config-file ./mkdocs.yml --verbose
      else
        mkdocs build --clean --config-file ./mkdocs.yml --verbose
      fi
  after_script:
    # Cleanup documentation
    - |
      if [ -e ./docs/.serve.pid ]; then
        cat ./docs/.serve.pid | xargs -r kill >/dev/null 2>&1 || true
      fi
    - sh ./docs/prepare.sh --clean
  artifacts:
    expire_in: 1 hour
    paths:
      - public
  rules:
    - if: $CI_COMMIT_TAG || $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
      changes: !reference [.pages, rules, changes]
      changes: !reference ['.pages:rules', rules, changes]
    - if: $CI_COMMIT_BRANCH && $CI_COMMIT_REF_PROTECTED
      changes: !reference [.pages, rules, changes]
      changes: !reference ['.pages:rules', rules, changes]
      allow_failure: true
      when: manual

pdf:
  extends:
    - pages
  artifacts:
    expire_in: 1 hour
    paths:
      - public/$MKDOCS_EXPORTER_PDF_OUTPUT*.pdf
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH
      changes: !reference [.pages, rules, changes]
      changes: !reference ['.pages:rules', rules, changes]