Commit f1a662bf authored by Alexandre Burgoni's avatar Alexandre Burgoni
Browse files

Add Links_Checker job

parent 8ce31861
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
# 🔗 Links Checker

## Description


## How to use it

1. My first step into the job
2. Add the corresponding URL to your `.gitlab-ci.yml` file (see [Getting
   started](/getting-started)). Example:

    ```yaml
    include:
      - remote: 'https://jobs.r2devops.io/links_checker.yml'
    ```

3. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
4. Well done, your job is ready to work ! 😀

## Job details

* Job name: `links_checker`
* Docker image:
[`peterevans/liche:1.1.1`](https://hub.docker.com/r/peterevans/liche){:target="_blank"}
* Default stage: `static_tests`
* When: `always`

### Variables

| Name | Description | Default |
| ---- | ----------- | ------- |
| ` ` <img width=450/> |  | ` ` |

### Artifacts

We use [Junit](https://junit.org/junit5/){:target="_blank"}'s XML report to display error report
directly in pipeline `Test` tab and in merge request widget.
+6 −0
Original line number Diff line number Diff line
name: links_checker
description: Helping you find broken links it will do.
default_stage: static_tests
icon: 🔗
maintainer: Protocole
license: MIT
+66 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

stages:
  - static_tests

links_checker:
  image: 
      name: peterevans/liche:1.1.1
      entrypoint: [""]
  stage: static_tests
  variables:
      LICHE_DIRECTORY: ""
      LICHE_FILES: ""
      LICHE_EXCLUDE: ""
      LICHE_WRITE_OK: "true"
      LICHE_OPTIONS: ""
      FAIL_ON_ERROR: "false"
      REPORT_OUTPUT: "junit-report.xml"
  script:
      - apk add --update nodejs npm curl && npm install junit-report-builder
      - add_option() { export LICHE_OPTIONS="${LICHE_OPTIONS} ${1}"; }
      - |
          generate_report() {
              cat linkchecker_logs
              echo "EOF" >> linkchecker_logs
              curl -s -O https://gitlab.com/r2devops/hub/-/snippets/2044617/raw/master/main.cjs
              node main.cjs "${CI_PROJECT_DIR}" "linkchecker_logs" "${REPORT_OUTPUT}"
          }

      - | 
          if [ ! -z ${LICHE_DIRECTORY} ]; then 
              if [ ! -d ${LICHE_DIRECTORY} ]; then
                  echo "Directory specified ${LICHE_DIRECTORY} does not exist, exit"
                  exit 1
              fi
              add_option "-r ${CI_PROJECT_DIR}/${LICHE_DIRECTORY}"; 
          fi
      - |
          if [ ! -z "${LICHE_FILES}" ]; then
              for i in ${LICHE_FILES}; do
                  if [ ! -f ${i} ]; then
                      echo "File ${i} does not exist, exit";
                      exit 1;
                  fi

                  add_option "${CI_PROJECT_DIR}/${i}"
              done
          fi
      - if [ ! -z ${LICHE_EXCLUDE} ]; then add_option "-x \"${LICHE_EXCLUDE}\""; fi
      - if [ ${LICHE_WRITE_OK} = "true" ]; then add_option "-v"; fi

      - |
          if liche ${LICHE_OPTIONS} > linkchecker_logs 2>&1; then
              echo "No errors so far in in the checked files";
              generate_report;
          else
              generate_report;
              echo "Errors found in checked files";
              if [ ${FAIL_ON_ERROR} = "true" ]; then exit 1; fi
          fi
  artifacts:
      when: always
      paths:
          - ${CI_PROJECT_DIR}/${REPORT_OUTPUT}
      reports:
          junit: ${CI_PROJECT_DIR}/${REPORT_OUTPUT}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
* Initial version
 No newline at end of file