Commit ea463df4 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'feat/add-link-checker' into 'master'

feat(link-checker): add links checker with lychee

Closes #5

See merge request to-be-continuous/mkdocs!37
parents 26a2eae6 35fba5d2
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -41,7 +41,17 @@ This job performs MkDocs **build**. It uses the following variable:
:warning: The built documentation is generated in the `${MKD_WORKSPACE_DIR}/${MKD_SITE_DIR}` folder.
Be sure to update `MKD_SITE_DIR` if you change the output directory (via the `MKD_BUILD_ARGS` variable or the `mkdocs.yml` file).

## Publication
### `mkdocs-lychee` job

This job checks links with [lychee](https://github.com/lycheeverse/lychee). It uses the following variable:

| Name                    | description                                       | default value     |
| ----------------------- | ------------------------------------------------- | ----------------- |
| `MKD_LYCHEE_ENABLED`    | Set to `true` to enable this job                  | _none_ (disabled) |
| `MKD_LYCHEE_IMAGE`      | The Docker image used to run [lychee](https://github.com/lycheeverse/lychee) | `registry.hub.docker.com/lycheeverse/lychee:latest` |
| `MKD_LYCHEE_ARGS`       | [lychee arguments](https://github.com/lycheeverse/lychee#commandline-parameters) to execute | `docs/` |

## Publishing

:warning: this template is not a deployment template and it only builds a MkDocs project.

+21 −0
Original line number Diff line number Diff line
@@ -49,6 +49,27 @@
      "advanced": true
    }
  ],
  "features": [
    {
      "id": "lychee",
      "name": "lychee",
      "description": "Checks broken links and emails with [lychee](https://github.com/lycheeverse/lychee)",
      "enable_with": "MKD_LYCHEE_ENABLED",
      "variables": [
        {
          "name": "MKD_LYCHEE_IMAGE",
          "description": "The Docker image used to run [lychee](https://github.com/lycheeverse/lychee)",
          "default": "registry.hub.docker.com/lycheeverse/lychee:latest",
          "advanced": true
        },
        {
          "name": "MKD_LYCHEE_ARGS",
          "description": "[lychee arguments](https://github.com/lycheeverse/lychee#commandline-parameters) to execute",
          "default": "docs/"
        }
      ]
    }
  ],
  "variants": [
    {
      "id": "pages",
+59 −22
Original line number Diff line number Diff line
@@ -21,6 +21,25 @@ workflow:
      when: never
    - when: always

# test job prototype: implement adaptive pipeline rules
.test-policy:
  rules:
    # on tag: auto & failing
    - if: $CI_COMMIT_TAG
    # on ADAPTIVE_PIPELINE_DISABLED: auto & failing
    - if: '$ADAPTIVE_PIPELINE_DISABLED == "true"'
    # on production or integration branch(es): auto & failing
    - if: '$CI_COMMIT_REF_NAME =~ $PROD_REF || $CI_COMMIT_REF_NAME =~ $INTEG_REF'
    # early stage (dev branch, no MR): manual & non-failing
    - if: '$CI_MERGE_REQUEST_ID == null && $CI_OPEN_MERGE_REQUESTS == null'
      when: manual
      allow_failure: true
    # Draft MR: auto & non-failing
    - if: '$CI_MERGE_REQUEST_TITLE =~ /^Draft:.*/'
      allow_failure: true
    # else (Ready MR): auto & failing
    - when: on_success

variables:
  # variabilized tracking image
  TBC_TRACKING_IMAGE: "$CI_REGISTRY/to-be-continuous/tools/tracking:master"
@@ -32,11 +51,15 @@ variables:
  MKD_SITE_DIR: "site"
  MKD_PREBUILD_SCRIPT: "mkdocs-pre-build.sh"

  MKD_LYCHEE_IMAGE: "registry.hub.docker.com/lycheeverse/lychee:latest"
  MKD_LYCHEE_ARGS: "docs/"

# ==================================================
# Stages definition
# ==================================================
stages:
  - build
  - test

.mkdocs-scripts: &mkdocs-scripts |
  # BEGSCRIPT
@@ -54,28 +77,6 @@ stages:
      echo -e "[\\e[1;91mERROR\\e[0m] $*"
  }

  function prepare_mkdocs() {
    cd "${MKD_WORKSPACE_DIR}"

    if [[ -f "${MKD_REQUIREMENTS_FILE}" ]]; then
      log_info "installing requirements from file ${MKD_REQUIREMENTS_FILE}"
      # shellcheck disable=SC2086
      pip install -r "${MKD_REQUIREMENTS_FILE}" ${PIP_OPTS}
    elif [[ "${MKD_REQUIREMENTS}" ]]; then
      log_info "installing requirements from variable 'MKD_REQUIREMENTS': ${MKD_REQUIREMENTS}"
      # shellcheck disable=SC2086
      pip install ${MKD_REQUIREMENTS} ${PIP_OPTS}
    else
      log_info "no requirement defined"
    fi

    if [[ -f "${MKD_PREBUILD_SCRIPT}" ]]; then
      log_info "--- \\e[32mpre-build hook\\e[0m (\\e[33;1m${MKD_PREBUILD_SCRIPT}\\e[0m) found: execute"
      chmod +x "${MKD_PREBUILD_SCRIPT}"
      "./${MKD_PREBUILD_SCRIPT}"
    fi
  }

  function install_ca_certs() {
    certs="$1"

@@ -202,6 +203,26 @@ stages:
    log_info "... done"
  }

  function prepare_mkdocs() {
    if [[ -f "${MKD_REQUIREMENTS_FILE}" ]]; then
      log_info "installing requirements from file ${MKD_REQUIREMENTS_FILE}"
      # shellcheck disable=SC2086
      pip install -r "${MKD_REQUIREMENTS_FILE}" ${PIP_OPTS}
    elif [[ "${MKD_REQUIREMENTS}" ]]; then
      log_info "installing requirements from variable 'MKD_REQUIREMENTS': ${MKD_REQUIREMENTS}"
      # shellcheck disable=SC2086
      pip install ${MKD_REQUIREMENTS} ${PIP_OPTS}
    else
      log_info "no requirement defined"
    fi

    if [[ -f "${MKD_PREBUILD_SCRIPT}" ]]; then
      log_info "--- \\e[32mpre-build hook\\e[0m (\\e[33;1m${MKD_PREBUILD_SCRIPT}\\e[0m) found: execute"
      chmod +x "${MKD_PREBUILD_SCRIPT}"
      "./${MKD_PREBUILD_SCRIPT}"
    fi
  }

  unscope_variables

  # ENDSCRIPT
@@ -223,6 +244,7 @@ mkdocs:
  before_script:
    - *mkdocs-scripts
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    - cd "${MKD_WORKSPACE_DIR}"
    - prepare_mkdocs
  script:
    - mkdocs build ${MKD_BUILD_ARGS}
@@ -232,3 +254,18 @@ mkdocs:
      - ${MKD_WORKSPACE_DIR}/${MKD_SITE_DIR}
    expire_in: 1 day

mkdocs-lychee:
  image:
    name: "$MKD_LYCHEE_IMAGE"
    entrypoint: [""]
  stage: test
  before_script:
    - *mkdocs-scripts
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    - cd "${MKD_WORKSPACE_DIR}"
  script:
    - lychee ${MKD_LYCHEE_ARGS}
  rules:
    - if: '$MKD_LYCHEE_ENABLED != "true"'
      when: never
    - !reference [.test-policy, rules]