Skip to content

Commit

Permalink
ci(link-checker): use lychee instead of MLC (#34)
Browse files Browse the repository at this point in the history
This PR changes
[`mdbook-docs.yml`](../blob/master/.github/workflows/mdbook-docs.yml#L35)
workflow to use https://github.com/lycheeverse/lychee ("Fast, async,
stream-based link checker written in Rust") via
https://github.com/lycheeverse/lychee-action instead of MLC
(`markdown-link-check`).

The lychee config file
([`lychee.toml`](../blob/lychee-link-checker/docs-hub/lychee.toml))
closely mirrors the settings from existing
[`mlc.mdbook.json`](../blob/master/docs-hub/mlc.mdbook.json), and thus
should work with any and all Markdown files. I opted to leave
`mlc.next.json` as-is for now, because it uses extra configuration.

Reasoning for the change:
- main reason - `markdown-link-check` operates on individual files
(e.g., `find . -name *md -exec markdown-link-check {};`). This means
that the errors are reported in the middle of the job output, which is
quite long. Thus, it is difficult to find the actual error message.
`lychee` uses globs like `**/*.md` natively (handled by `lychee-action`
under the hood), meaning that there's a single report for all links in
the repo's Markdown, with errors clearly visible. It looks like this by
default (1 link failing on purpose):
```
  179/179 ━━━━━━━━━━━━━━━━━━━━ Finished extracting links                                                                                                                                                                                             Issues found in 1 input. Find details below.

[docs/src/connecting/external-node.md]:
✗ [403] https://faucet-beta-5.fuel.network/ | Failed: Network error: Forbidden

🔍 179 Total (in 1s) ✅ 177 OK 🚫 1 Error 💤 1 Excluded
```
- `lychee` can use GHA cache to avoid checking the same links on
repeated CI runs - this is configured in this PR
- it's much faster than MLC, written in Rust and well-maintained (+ for
security)
  • Loading branch information
Br1ght0ne authored Jul 2, 2024
1 parent 19a8e82 commit 3b40a26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/mdbook-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ jobs:
- name: Run pre-command
if: inputs.pre-command != ''
run: ${{ inputs.pre-command }}
- uses: gaurav-nelson/[email protected]
- name: Restore lychee cache
uses: actions/cache@v3
with:
config-file: 'workflow/docs-hub/mlc.mdbook.json'
path: .lycheecache
key: cache-lychee-${{ github.ref_name }}
restore-keys: cache-lychee-
- uses: lycheeverse/lychee-action@v1
with:
args: '--config workflow/docs-hub/lychee.toml'

markdown-lint:
name: Markdown Lint
Expand Down
20 changes: 20 additions & 0 deletions docs-hub/lychee.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Enable link caching. This can be helpful to avoid checking the same links on
# multiple runs.
cache = true

# Discard all cached requests older than this duration.
max_cache_age = "1d"

# Comma-separated list of accepted status codes for valid links.
accept = ["200", "206", "405"]

# Exclude URLs and mail addresses from checking (supports regex).
exclude = [
'faucet-beta-5.fuel.network',
'fuellabs.github.io/block-explorer-v2',
]

# Exclude all private IPs from checking.
# Equivalent to setting `exclude_private`, `exclude_link_local`, and
# `exclude_loopback` to true.
exclude_all_private = true

0 comments on commit 3b40a26

Please sign in to comment.