Commit 832829b5 authored by Alexandre Burgoni's avatar Alexandre Burgoni
Browse files

Update Link Checker job doc / job

parent c74f2ec8
Loading
Loading
Loading
Loading
+50 −2
Original line number Diff line number Diff line
@@ -6,9 +6,12 @@ Using this job you will be able to detect most (see [here](#types-of-link-verifi

It uses the tool [`Liche`](https://github.com/raviqqe/liche){:target="_blank"} in [Go](https://golang.org/){:target="_blank"} to test and find the links in your documents. In its default state, this job will analyze your whole project for eligible files to verify.

!!! warning
    This job may generate a lot errors about local broken links in your document if you are using **absolute paths** or **rewriting urls**. See [Absolute paths and rewriting urls](#absolute-paths-and-rewriting-urls)

## How to use it

1. Have `.md` or `.html` files in your project
1. Have `.md`, `.html` or `.htm` files in your project
2. Add the corresponding URL to your `.gitlab-ci.yml` file (see [Getting
   started](/getting-started)). Example:

@@ -33,17 +36,62 @@ It uses the tool [`Liche`](https://github.com/raviqqe/liche){:target="_blank"} i

| Name | Description | Default |
| ---- | ----------- | ------- |
| `LICHE_DIRECTORY` <img width=450/> | Path to the directory to be scanned | ` ` |
| `LICHE_DIRECTORY` <img width=450/> | Path to the directory to be scanned | `/` |
| `LICHE_FILES` | A list of files (separated with spaces) to scan. It can be used with `LICHE_DIRECTORY` | ` ` |
| `LICHE_EXCLUDE` | A [regular expression](https://en.wikipedia.org/wiki/Regular_expression){:target="_blank"} | ` ` |
| `LICHE_PRINT_OK` | In addition to broken links, it will add not-broken links in the report (see [artifacts](#artifacts)) | `true` |
| `LICHE_RECURSIVE` | When `LICHE_DIRECTORY` is filled it will search for files recursively  | `true` |
| `FAIL_ON_BROKEN` | Make your pipeline fails when a broken link is found | `false` |
| `ROOT_DIRECTORY` | Used for absolute paths, it define the root of HTML projects | ` ` |
| `LICHE_OPTIONS` | Additional options (see [options](https://github.com/raviqqe/liche){:target="_blank"}) | ` ` |
| `REPORT_OUTPUT` | Report file's name | `junit-report.xml` |

### Types of link verified

This tool will check for links in a specific context, and so in your project some links may not be checked. However,
here is (a non-exhaustive) list of what `Liche` can or can't identify:

**In HTML files (`.html`, `.htm`):**
```HTML
Can identify:

* <a href="https://www.google.com"></a>
* <a href="portfolio.html"></a>
* <a href="mailto:contact@google.com"></a>
* <img src="../images/logo.png"/>
* <img src="logo.png"/>

Can't identify:

* <div onClick="redirect('https://www.google.com')"></div>
* <script type="text/javascript">
      window.location.href = "https://www.google.com" 
  </script>
...
```

**In Markdown files (`.md`):**
```md

Can identify:

* [Gitlab](https://gitlab.com)
* [R2DevOps](https://r2devops.io){:target="_blank"}
* # New post [posts](https://pastebin.com)

Can't identify:

* # My title link : https://www.google.com
* https://www.google.com
```

### Absolute paths and rewriting urls

If you are using absolute paths in your HTML documents, be sure to fill the variable `ROOT_DIRECTORY`. By default, if you use `LICHE_DIRECTORY`, `ROOT_DIRECTORY`  will be filled with the same path.

If you use URL rewriting in your static website, using this job, most of the internal links will be considered as broken. To avoid that, you can define that you
only want to check external links, by using `LICHE_EXCLUSE` with the following value: `"^[^http]"` 

### Artifacts

We use [Junit](https://junit.org/junit5/){:target="_blank"}'s XML report to display error report
+6 −2
Original line number Diff line number Diff line
@@ -9,13 +9,14 @@ links_checker:
      entrypoint: [""]
  stage: static_tests
  variables:
      LICHE_DIRECTORY: ""
      LICHE_DIRECTORY: "/"
      LICHE_FILES: ""
      LICHE_EXCLUDE: ""
      LICHE_PRINT_OK: "true"
      LICHE_OPTIONS: ""
      LICHE_RECURSIVE: "true"
      FAIL_ON_BROKEN: "false"
      ROOT_DIRECTORY: ""
      REPORT_OUTPUT: "junit-report.xml"
  script:
      - apk add --update nodejs npm curl && npm install junit-report-builder
@@ -34,7 +35,10 @@ links_checker:
                  echo "Directory specified ${LICHE_DIRECTORY} does not exist, exit"
                  exit 1
              fi
              add_option "${CI_PROJECT_DIR}/${LICHE_DIRECTORY}"; 
              if [ -z ${ROOT_DIRECTORY} ]; then
                  export ROOT_DIRECTORY=${LICHE_DIRECTORY}
              fi
              add_option "${CI_PROJECT_DIR}/${LICHE_DIRECTORY} -d ${CI_PROJECT_DIR}/${ROOT_DIRECTORY}"; 
          fi
      - |
          if [ ! -z "${LICHE_FILES}" ]; then