findbrokenlinks 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- findbrokenlinks-1.0.0/LICENSE +21 -0
- findbrokenlinks-1.0.0/PKG-INFO +600 -0
- findbrokenlinks-1.0.0/README.md +557 -0
- findbrokenlinks-1.0.0/pyproject.toml +79 -0
- findbrokenlinks-1.0.0/setup.cfg +4 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/__init__.py +1 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/__main__.py +4 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/__init__.py +27 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/antibot.py +157 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/base.py +77 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/http_status.py +29 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/network_error.py +71 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/redirect_chain.py +27 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/redirect_to_home.py +40 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/soft_404_pattern.py +97 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/checks/soft_404_probe.py +127 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/cli.py +580 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/config.py +54 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/crawler.py +399 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/extractors/__init__.py +0 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/extractors/base.py +11 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/extractors/html.py +84 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/fetcher.py +210 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/gha.py +622 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/models.py +65 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/patterns/builtin.yaml +55 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/rate_limiter.py +39 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/__init__.py +22 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/base.py +120 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/csv_reporter.py +33 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/grouped_json_reporter.py +82 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/html_reporter.py +86 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/json_reporter.py +50 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/jsonlines_reporter.py +28 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/junit_reporter.py +59 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/markdown_reporter.py +51 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/sarif_reporter.py +167 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/reporters/tsv_reporter.py +41 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/robots.py +51 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/scope.py +67 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks/targets.py +138 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks.egg-info/PKG-INFO +600 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks.egg-info/SOURCES.txt +75 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks.egg-info/dependency_links.txt +1 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks.egg-info/entry_points.txt +2 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks.egg-info/requires.txt +16 -0
- findbrokenlinks-1.0.0/src/findbrokenlinks.egg-info/top_level.txt +1 -0
- findbrokenlinks-1.0.0/tests/test_antibot.py +181 -0
- findbrokenlinks-1.0.0/tests/test_autodiscover.py +87 -0
- findbrokenlinks-1.0.0/tests/test_check_site.py +223 -0
- findbrokenlinks-1.0.0/tests/test_checks.py +349 -0
- findbrokenlinks-1.0.0/tests/test_cli_validation.py +273 -0
- findbrokenlinks-1.0.0/tests/test_content_type_guard.py +93 -0
- findbrokenlinks-1.0.0/tests/test_crawler_integration.py +53 -0
- findbrokenlinks-1.0.0/tests/test_cycles.py +88 -0
- findbrokenlinks-1.0.0/tests/test_exit_codes.py +172 -0
- findbrokenlinks-1.0.0/tests/test_extension.py +78 -0
- findbrokenlinks-1.0.0/tests/test_extractor.py +32 -0
- findbrokenlinks-1.0.0/tests/test_fetcher_error_classification.py +97 -0
- findbrokenlinks-1.0.0/tests/test_fetcher_headers.py +87 -0
- findbrokenlinks-1.0.0/tests/test_fetcher_ssl_chain_fallback.py +120 -0
- findbrokenlinks-1.0.0/tests/test_fetcher_streaming.py +65 -0
- findbrokenlinks-1.0.0/tests/test_fixture_site.py +26 -0
- findbrokenlinks-1.0.0/tests/test_gha.py +695 -0
- findbrokenlinks-1.0.0/tests/test_grouped_reporter.py +191 -0
- findbrokenlinks-1.0.0/tests/test_max_pages.py +63 -0
- findbrokenlinks-1.0.0/tests/test_output_templates.py +183 -0
- findbrokenlinks-1.0.0/tests/test_readme.py +103 -0
- findbrokenlinks-1.0.0/tests/test_release_script.py +170 -0
- findbrokenlinks-1.0.0/tests/test_reporters.py +114 -0
- findbrokenlinks-1.0.0/tests/test_sarif.py +219 -0
- findbrokenlinks-1.0.0/tests/test_scope.py +34 -0
- findbrokenlinks-1.0.0/tests/test_scope_leak.py +78 -0
- findbrokenlinks-1.0.0/tests/test_sitemap.py +110 -0
- findbrokenlinks-1.0.0/tests/test_soft404_probe_crawl.py +199 -0
- findbrokenlinks-1.0.0/tests/test_streaming.py +100 -0
- findbrokenlinks-1.0.0/tests/test_version.py +24 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 findbrokenlinks contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: findbrokenlinks
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Async broken-link crawler with pluggable checks and reporters
|
|
5
|
+
Author: findbrokenlinks contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/as-mnt/findbrokenlinks
|
|
8
|
+
Project-URL: Source, https://github.com/as-mnt/findbrokenlinks
|
|
9
|
+
Project-URL: Issues, https://github.com/as-mnt/findbrokenlinks/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/as-mnt/findbrokenlinks/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: broken links,link checker,crawler,soft 404,ci
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management :: Link Checking
|
|
23
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: httpx[http2]<1,>=0.27
|
|
28
|
+
Requires-Dist: beautifulsoup4>=4.12
|
|
29
|
+
Requires-Dist: lxml>=5.0
|
|
30
|
+
Requires-Dist: pyyaml>=6.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-httpx>=0.30; extra == "dev"
|
|
35
|
+
Requires-Dist: starlette>=0.37; extra == "dev"
|
|
36
|
+
Requires-Dist: uvicorn>=0.30; extra == "dev"
|
|
37
|
+
Requires-Dist: ruff; extra == "dev"
|
|
38
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
39
|
+
Requires-Dist: types-PyYAML>=6; extra == "dev"
|
|
40
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
41
|
+
Requires-Dist: twine>=6.1; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# findbrokenlinks
|
|
45
|
+
|
|
46
|
+
[](https://github.com/as-mnt/findbrokenlinks/actions/workflows/ci.yml)
|
|
47
|
+
[](https://pypi.org/project/findbrokenlinks/)
|
|
48
|
+
[](https://www.python.org/downloads/)
|
|
49
|
+
[](https://github.com/as-mnt/findbrokenlinks/blob/main/LICENSE)
|
|
50
|
+
|
|
51
|
+
Async crawler that finds links on a website whose behavior in a browser would
|
|
52
|
+
**not match user expectations**: 404s, network failures, redirects to weird
|
|
53
|
+
places, "soft 404" pages where a CMS returns 200 but says "not found".
|
|
54
|
+
|
|
55
|
+
Built around pluggable **checks** and **reporters** — adding a new control or
|
|
56
|
+
output format means dropping a file with an `@register` decorator. No core
|
|
57
|
+
edits needed.
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- **Crawl modes**: `page` (single page), `internal` (same domain), or
|
|
62
|
+
`internal+external` (recurse internal, validate external) — `--mode`.
|
|
63
|
+
- **Seven built-in checks** — flag HTTP errors, network failures, redirect
|
|
64
|
+
chains, redirects to the home page, two soft-404 detectors (regex patterns +
|
|
65
|
+
baseline probing), and an anti-bot block detector so WAF challenges from
|
|
66
|
+
Cloudflare / DataDome / PerimeterX / Imperva / Akamai / DDoS-Guard
|
|
67
|
+
and login walls (401) don't masquerade as broken links.
|
|
68
|
+
- **Polite-but-well-formed HTTP**: keeps an honest `User-Agent`, but pairs
|
|
69
|
+
it with standard `Accept` and `Accept-Language` headers so WAFs don't
|
|
70
|
+
treat us as malformed traffic.
|
|
71
|
+
- **Doesn't parse JS as HTML**: bodies are only HTML/plaintext; JS, CSS,
|
|
72
|
+
JSON aren't read, and HTMLExtractor double-checks `Content-Type` before
|
|
73
|
+
invoking bs4 — so JavaScript string literals can't become fake findings.
|
|
74
|
+
- **Nine output formats**: `csv`, `tsv`, `json`, `jsonl`, `html`, `markdown`,
|
|
75
|
+
`junit` (XML), `sarif`, `grouped-json`. Emit multiple at once with `--format a,b,c`.
|
|
76
|
+
- **`grouped-json` reporter** collapses findings by `final_url` — one record
|
|
77
|
+
per distinct broken target with the source-page list preserved as a count
|
|
78
|
+
plus a small sample. On a real crawl of a 7800-page site, a single broken
|
|
79
|
+
footer link generated 7800 findings; grouped-json compresses that to one
|
|
80
|
+
record (97% reduction in our test case).
|
|
81
|
+
- **Incremental report writing**: when a single streamable format is selected
|
|
82
|
+
(`csv`, `tsv`, `jsonl`), each finding is appended to the output as soon as it
|
|
83
|
+
is discovered — you can `tail -f` the report while the crawl runs.
|
|
84
|
+
- **Polite by default**: respects `robots.txt`, rate-limited (token bucket),
|
|
85
|
+
bounded concurrency, configurable timeouts and redirect caps.
|
|
86
|
+
- **Bandwidth-efficient**: streams responses — binary content (PDFs, archives,
|
|
87
|
+
images) is never downloaded, only its status code is checked. Text bodies
|
|
88
|
+
are capped (default 1 MB) so a runaway HTML page can't exhaust memory.
|
|
89
|
+
- **HTML coverage** beyond `<a href>`: also checks `<img src>`,
|
|
90
|
+
`<script src>`, `<link href>`.
|
|
91
|
+
- **Extensible**: new check = one file + `@register`. Same for report formats.
|
|
92
|
+
- **CI-friendly**: exit code `1` when a finding reaches `--fail-on` (default
|
|
93
|
+
`error`), `3` when the crawl itself failed, so CI can tell the two apart; JUnit output
|
|
94
|
+
slots into CI test reports (GitHub Actions, GitLab, Jenkins). SARIF output is
|
|
95
|
+
one result per check and broken target; for GitHub Code Scanning it needs
|
|
96
|
+
`--sarif-anchor`, see "CI integration" below.
|
|
97
|
+
- **GitHub Action**: one step that writes a job summary, annotates the top
|
|
98
|
+
broken targets and leaves a SARIF report for Code Scanning, see
|
|
99
|
+
"GitHub Action" below.
|
|
100
|
+
|
|
101
|
+
## Installation
|
|
102
|
+
|
|
103
|
+
Requires Python **3.11+**. From [PyPI](https://pypi.org/project/findbrokenlinks/):
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pipx install findbrokenlinks # CLI in its own venv
|
|
107
|
+
# or
|
|
108
|
+
pip install findbrokenlinks
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
In GitHub Actions, the action needs no installation step: see
|
|
112
|
+
[GitHub Action](https://github.com/as-mnt/findbrokenlinks#github-action).
|
|
113
|
+
|
|
114
|
+
From a clone, for development:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
git clone https://github.com/as-mnt/findbrokenlinks
|
|
118
|
+
cd findbrokenlinks
|
|
119
|
+
make install # .venv/ with the package in editable mode
|
|
120
|
+
# or
|
|
121
|
+
make install-dev # + pytest, ruff, mypy, starlette (for integration tests)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
In a clone the command is `.venv/bin/findbrokenlinks`.
|
|
125
|
+
|
|
126
|
+
## Quick start
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Crawl a site, internal pages + validate external links, TSV to stdout
|
|
130
|
+
findbrokenlinks https://example.com
|
|
131
|
+
|
|
132
|
+
# Single page mode, HTML report
|
|
133
|
+
findbrokenlinks https://example.com --mode page \
|
|
134
|
+
--format html -o report.html
|
|
135
|
+
|
|
136
|
+
# Streaming JSONL — findings appear in the file as soon as they are discovered
|
|
137
|
+
findbrokenlinks https://example.com --format jsonl -o report.jsonl &
|
|
138
|
+
tail -f report.jsonl | jq .
|
|
139
|
+
|
|
140
|
+
# Emit several formats at once
|
|
141
|
+
findbrokenlinks https://example.com \
|
|
142
|
+
--format csv,json,html,markdown --output-dir reports/
|
|
143
|
+
|
|
144
|
+
# Run as a Python module
|
|
145
|
+
python -m findbrokenlinks https://example.com --mode internal
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
In a clone, via Makefile shortcuts (override `URL=…` on the command line):
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
make run URL=https://example.com
|
|
152
|
+
make run-page URL=https://example.com
|
|
153
|
+
make run-internal URL=https://example.com
|
|
154
|
+
make run-html URL=https://example.com OUT_DIR=reports
|
|
155
|
+
make run-jsonl URL=https://example.com OUT_DIR=reports # streaming JSONL
|
|
156
|
+
make run-multi URL=https://example.com OUT_DIR=reports
|
|
157
|
+
make run-json URL=https://example.com FLAGS=--insecure # forward extra CLI flags
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## GitHub Action
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
- uses: as-mnt/findbrokenlinks@v1
|
|
164
|
+
with:
|
|
165
|
+
url: https://docs.example.org
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The step installs findbrokenlinks from the action's own checkout into a
|
|
169
|
+
separate virtualenv (the job's Python and `PATH` are left alone) and crawls the
|
|
170
|
+
site. It writes a job summary with the totals and the top broken targets,
|
|
171
|
+
`::error` and `::warning` annotations for those targets, and the `grouped-json`
|
|
172
|
+
and `sarif` reports. It fails when a finding reaches `fail-on`, with the CLI's
|
|
173
|
+
[exit codes](https://github.com/as-mnt/findbrokenlinks#exit-codes). It runs on
|
|
174
|
+
Linux and macOS runners, not on Windows.
|
|
175
|
+
|
|
176
|
+
`@v1` follows the latest 1.x release. For a fixed version, give a release tag
|
|
177
|
+
(`@v1.0.0`) or its commit SHA.
|
|
178
|
+
|
|
179
|
+
### Inputs
|
|
180
|
+
|
|
181
|
+
| Input | Default | |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `url` | required | Start URL, `http://` or `https://`. |
|
|
184
|
+
| `mode` | `internal+external` | `page`, `internal` or `internal+external`, as `--mode`. |
|
|
185
|
+
| `fail-on` | `error` | Lowest severity that fails the step: `error`, `warning` or `never`. |
|
|
186
|
+
| `formats` | | Extra report formats, comma- or space-separated (`csv`, `html`, `junit`, …). `grouped-json` and `sarif` are always written. |
|
|
187
|
+
| `args` | | Other CLI options, split the way a shell splits words (no variable expansion), e.g. `--depth 3 --rate-limit 2`. The options the inputs set are refused: `--format`, `--output`, `--output-dir`, `--mode`, `--fail-on`, `--sarif-anchor`. |
|
|
188
|
+
| `output-dir` | a new directory | Directory for the reports; `{host}`, `{date}`, `{time}` and `{ts}` are expanded. By default each run gets a new one, `$RUNNER_TEMP/findbrokenlinks/<host>` (then `<host>-2`, …). In a directory given here, the reports an earlier run left there, of any format, and its `summary.md` are removed first; other files stay. So do not give the repository root (`.`): its `summary.md` would be removed too. |
|
|
189
|
+
| `sarif-anchor` | the workflow's file | Repository file, relative to its root, that every SARIF result is attached to (at line 1) for Code Scanning, e.g. `mkdocs.yml`. By default, the file of the workflow that runs the action. |
|
|
190
|
+
| `python-version` | `3.12` | Python for the action's own virtualenv. |
|
|
191
|
+
| `summary` | `true` | Write the job summary. `summary.md` in `report-dir` is written either way. |
|
|
192
|
+
| `annotations` | `true` | Annotate the top targets. |
|
|
193
|
+
| `max-annotations` | `10` | How many targets to annotate at most. GitHub keeps 10 error and 10 warning annotations per step, so more than 20 changes nothing. |
|
|
194
|
+
|
|
195
|
+
### Outputs
|
|
196
|
+
|
|
197
|
+
| Output | |
|
|
198
|
+
|---|---|
|
|
199
|
+
| `exit-code` | `0`, `1`, `2` or `3`, the CLI's exit code. |
|
|
200
|
+
| `errors` | Number of error-level findings (links on pages). Empty when no report was written. |
|
|
201
|
+
| `warnings` | Number of warning-level findings. Empty when no report was written. |
|
|
202
|
+
| `broken-targets` | Number of distinct final URLs with an error. Empty when no report was written. |
|
|
203
|
+
| `report-dir` | Absolute path of the report directory, for `actions/upload-artifact`. |
|
|
204
|
+
| `sarif-file` | The SARIF report, for `github/codeql-action/upload-sarif`. Empty when not written. |
|
|
205
|
+
| `summary-file` | `summary.md`, the job summary as a file (for a pull request comment, say). |
|
|
206
|
+
|
|
207
|
+
### Examples
|
|
208
|
+
|
|
209
|
+
#### A published site, every week
|
|
210
|
+
|
|
211
|
+
```yaml
|
|
212
|
+
name: Links
|
|
213
|
+
on:
|
|
214
|
+
schedule:
|
|
215
|
+
- cron: "0 6 * * 1" # Mondays at 06:00 UTC
|
|
216
|
+
workflow_dispatch:
|
|
217
|
+
|
|
218
|
+
permissions:
|
|
219
|
+
contents: read
|
|
220
|
+
|
|
221
|
+
jobs:
|
|
222
|
+
links:
|
|
223
|
+
runs-on: ubuntu-latest
|
|
224
|
+
steps:
|
|
225
|
+
- uses: as-mnt/findbrokenlinks@v1
|
|
226
|
+
id: links
|
|
227
|
+
with:
|
|
228
|
+
url: https://docs.example.org
|
|
229
|
+
formats: html
|
|
230
|
+
- uses: actions/upload-artifact@v7
|
|
231
|
+
if: always() && steps.links.outputs.report-dir != ''
|
|
232
|
+
with:
|
|
233
|
+
name: link-report
|
|
234
|
+
path: ${{ steps.links.outputs.report-dir }}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
No checkout: the action does not read the repository. A broken link fails the
|
|
238
|
+
run, and GitHub notifies whoever last changed the `schedule`. The reports, the
|
|
239
|
+
HTML one among them, are an artifact of the run. In a public repository GitHub
|
|
240
|
+
turns scheduled workflows off after 60 days without activity in it.
|
|
241
|
+
|
|
242
|
+
#### A documentation site built in the same job
|
|
243
|
+
|
|
244
|
+
```yaml
|
|
245
|
+
name: Docs
|
|
246
|
+
on:
|
|
247
|
+
pull_request:
|
|
248
|
+
push:
|
|
249
|
+
branches: [main]
|
|
250
|
+
|
|
251
|
+
permissions:
|
|
252
|
+
contents: read
|
|
253
|
+
|
|
254
|
+
jobs:
|
|
255
|
+
links:
|
|
256
|
+
runs-on: ubuntu-latest
|
|
257
|
+
steps:
|
|
258
|
+
- uses: actions/checkout@v7
|
|
259
|
+
- uses: actions/setup-python@v7
|
|
260
|
+
with:
|
|
261
|
+
python-version: "3.12"
|
|
262
|
+
- run: pip install mkdocs
|
|
263
|
+
- run: mkdocs build
|
|
264
|
+
- name: Serve the site
|
|
265
|
+
run: |
|
|
266
|
+
python -m http.server 8000 --directory site &
|
|
267
|
+
curl --silent --retry 10 --retry-connrefused --retry-delay 1 \
|
|
268
|
+
--output /dev/null http://localhost:8000/
|
|
269
|
+
- uses: as-mnt/findbrokenlinks@v1
|
|
270
|
+
with:
|
|
271
|
+
url: http://localhost:8000/
|
|
272
|
+
mode: internal
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The server started in the background keeps running for the steps after it;
|
|
276
|
+
`curl` waits until it answers. `mode: internal` checks the site's own pages and
|
|
277
|
+
links and leaves external ones to the weekly run: a pull request should not fail
|
|
278
|
+
because another site is down. It also leaves alone the links to the published
|
|
279
|
+
site, such as `<link rel="canonical">` with `site_url` set in `mkdocs.yml`: a
|
|
280
|
+
page new in the pull request is not published yet.
|
|
281
|
+
|
|
282
|
+
#### Alerts in Code Scanning
|
|
283
|
+
|
|
284
|
+
```yaml
|
|
285
|
+
name: Links
|
|
286
|
+
on:
|
|
287
|
+
schedule:
|
|
288
|
+
- cron: "0 6 * * 1"
|
|
289
|
+
workflow_dispatch:
|
|
290
|
+
|
|
291
|
+
permissions:
|
|
292
|
+
contents: read
|
|
293
|
+
security-events: write
|
|
294
|
+
|
|
295
|
+
jobs:
|
|
296
|
+
links:
|
|
297
|
+
runs-on: ubuntu-latest
|
|
298
|
+
steps:
|
|
299
|
+
- uses: actions/checkout@v7
|
|
300
|
+
- uses: as-mnt/findbrokenlinks@v1
|
|
301
|
+
id: links
|
|
302
|
+
with:
|
|
303
|
+
url: https://docs.example.org
|
|
304
|
+
fail-on: never
|
|
305
|
+
- uses: github/codeql-action/upload-sarif@v4
|
|
306
|
+
with:
|
|
307
|
+
sarif_file: ${{ steps.links.outputs.sarif-file }}
|
|
308
|
+
category: findbrokenlinks/docs.example.org
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Each check and broken target is one alert, attached to line 1 of the workflow
|
|
312
|
+
file (or of `sarif-anchor`); the message has the URL and a sample of the pages
|
|
313
|
+
that link to it. An alert stays the same alert from run to run and is closed by
|
|
314
|
+
the first run that no longer finds it. `fail-on: never` keeps the run green, the
|
|
315
|
+
alerts being the result; the step still fails when the crawl does (exit code 3),
|
|
316
|
+
and then the upload is skipped: a partial report would close alerts it did not
|
|
317
|
+
get to. `category` keeps these results apart from other analyses, CodeQL's for
|
|
318
|
+
one; give each site its own. Code Scanning is free for public repositories; a
|
|
319
|
+
private one needs GitHub Code Security.
|
|
320
|
+
|
|
321
|
+
## CLI reference
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
findbrokenlinks <URL> [options] URL: http:// or https:// with a host (and a port 1-65535)
|
|
325
|
+
|
|
326
|
+
Scope:
|
|
327
|
+
--mode {page,internal,internal+external} default: internal+external
|
|
328
|
+
--depth N default: 0 (unlimited)
|
|
329
|
+
--max-pages N default: 10000 (0 = unlimited);
|
|
330
|
+
safety cap against unbounded URL spaces
|
|
331
|
+
(session IDs, calendars, search facets)
|
|
332
|
+
--use-sitemap seed from /sitemap.xml
|
|
333
|
+
|
|
334
|
+
Network:
|
|
335
|
+
--rate-limit RPS default: 5
|
|
336
|
+
--concurrency N default: 10
|
|
337
|
+
--timeout SECONDS default: 15
|
|
338
|
+
--max-redirects N default: 10
|
|
339
|
+
--max-body-bytes N default: 1048576 (1 MB) — cap on text bodies;
|
|
340
|
+
non-text responses are never downloaded
|
|
341
|
+
--user-agent UA default: findbrokenlinks/<version> (+https://github.com/as-mnt/findbrokenlinks)
|
|
342
|
+
--ignore-robots
|
|
343
|
+
--insecure, -k disable TLS certificate verification (like curl -k).
|
|
344
|
+
NOTE: an incomplete chain (server missing its
|
|
345
|
+
intermediate CA) is already crawled by default and
|
|
346
|
+
reported as a NETWORK_ERROR *warning* — this flag is
|
|
347
|
+
for other cert problems (expired, self-signed, wrong
|
|
348
|
+
host) and suppresses ssl/ssl_chain findings entirely.
|
|
349
|
+
|
|
350
|
+
Checks:
|
|
351
|
+
--enable-checks code1,code2
|
|
352
|
+
--disable-checks code1,code2
|
|
353
|
+
--redirect-chain-threshold N default: 3
|
|
354
|
+
--patterns PATH user soft-404 patterns YAML (checked at startup)
|
|
355
|
+
--no-soft404-probe
|
|
356
|
+
--fail-on {error,warning,never}
|
|
357
|
+
lowest severity that makes the exit code 1
|
|
358
|
+
(default: error); never: exit 0 whatever is found
|
|
359
|
+
|
|
360
|
+
Output:
|
|
361
|
+
--format fmt[,fmt...] csv|tsv|json|jsonl|html|markdown|junit|sarif|grouped-json
|
|
362
|
+
(default: tsv); streaming formats: csv, tsv, jsonl
|
|
363
|
+
--output PATH, -o PATH default: stdout (single format only). Supports
|
|
364
|
+
placeholders {host}, {date}, {time}, {ts}, {format}, {ext}.
|
|
365
|
+
--output-dir DIR directory for multi-format output. Defaults to
|
|
366
|
+
reports/{host}_{date}_{time}/ when omitted. Files
|
|
367
|
+
inside the dir are named {format}.{ext}.
|
|
368
|
+
--sarif-anchor PATH sarif: attach every result to line 1 of this file,
|
|
369
|
+
relative to the repository root (e.g. mkdocs.yml);
|
|
370
|
+
needed for GitHub Code Scanning
|
|
371
|
+
|
|
372
|
+
Misc:
|
|
373
|
+
-v / --verbose
|
|
374
|
+
--log-file PATH
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
## Built-in checks
|
|
378
|
+
|
|
379
|
+
| Code | Severity | Triggers when |
|
|
380
|
+
|---|---|---|
|
|
381
|
+
| `HTTP_ERROR` | error | response status ≥ 400 |
|
|
382
|
+
| `NETWORK_ERROR` | error / warning | DNS / TCP / TLS / timeout failure (error). Also **warning** when a page was crawled over a relaxed TLS chain — i.e. the server omitted its intermediate CA (`ssl_chain`); the crawl proceeds, the broken chain is flagged so you can ship `fullchain.pem`. |
|
|
383
|
+
| `REDIRECT_TO_HOME` | warning | redirect terminates at `/` (common soft-404 pattern) |
|
|
384
|
+
| `REDIRECT_CHAIN` | warning | redirect chain length >= `--redirect-chain-threshold` |
|
|
385
|
+
| `SOFT_404_PATTERN` | warning | 200 OK but page matches a "not found" regex |
|
|
386
|
+
| `SOFT_404_PROBE` | warning / info | 200 OK but body matches the host's known 404 baseline, or the link redirects where a nonexistent URL does (warning). **Info**, once per host: the home page itself matches the baseline, so bodies are not compared there. |
|
|
387
|
+
| `ANTIBOT_BLOCKED` | warning | 4xx/5xx response matches a known WAF / anti-bot signature (DataDome, PerimeterX, Cloudflare interstitial, Imperva, Akamai, generic "not a bot" / captcha text). Fires alongside `HTTP_ERROR` — disable one or the other to suit your triage. |
|
|
388
|
+
|
|
389
|
+
The probe-based detector requests a random nonexistent URL per host at startup
|
|
390
|
+
and remembers the response (status, normalized text, hash). Any 2xx response
|
|
391
|
+
whose body matches the baseline is flagged, and so is a link that redirects to
|
|
392
|
+
where the nonexistent URL ended up. A link to a home page (`/`) is not flagged
|
|
393
|
+
when it ends up on its own host, or where the home page of the host it ends up
|
|
394
|
+
on does: a `www.` alias, say. Another host's `/` that lands on a not-found page
|
|
395
|
+
is.
|
|
396
|
+
|
|
397
|
+
The probe also requests the home page (`/`). If it has the same body as the
|
|
398
|
+
nonexistent URL, bodies on that host tell a missing page from a real one in
|
|
399
|
+
nothing, so they are not compared: instead of a warning on every page you get
|
|
400
|
+
one `info` finding on the home page that says so. The redirect comparison still
|
|
401
|
+
works there.
|
|
402
|
+
|
|
403
|
+
> **Single-page apps (SPAs).** A client-rendered app (Next.js, React Router,
|
|
404
|
+
> etc.) typically serves the *same* `index.html` shell with `200 OK` for every
|
|
405
|
+
> path — including the homepage and genuinely nonexistent URLs — and renders the
|
|
406
|
+
> "not found" state in the browser via JavaScript. Since this crawler doesn't
|
|
407
|
+
> execute JS, every page looks identical at the HTTP layer, and broken internal
|
|
408
|
+
> links on such a host can't be detected by HTTP status alone. That is what the
|
|
409
|
+
> one `info` finding above tells you. Sites like `example.com`, which serve the
|
|
410
|
+
> same page with `404` for every unknown path, get the same finding.
|
|
411
|
+
> `--no-soft404-probe` turns the probe off altogether (no requests).
|
|
412
|
+
|
|
413
|
+
## Output
|
|
414
|
+
|
|
415
|
+
Every reporter produces the same fields per finding:
|
|
416
|
+
|
|
417
|
+
- `source_page` — page where the link was found
|
|
418
|
+
- `link_url` — the link's target URL
|
|
419
|
+
- `final_url` — where the request actually ended up after redirects
|
|
420
|
+
- `anchor` — link text or alt attribute
|
|
421
|
+
- `tag` — `a` / `img` / `script` / `link` / `seed`
|
|
422
|
+
- `status` — HTTP status (empty on network error)
|
|
423
|
+
- `redirect_chain` — list of intermediate URLs
|
|
424
|
+
- `issue_codes` — which checks fired
|
|
425
|
+
- `severity` — `error` / `warning` / `info`
|
|
426
|
+
- `details` — human-readable explanation
|
|
427
|
+
|
|
428
|
+
HTML and Markdown reports additionally **group findings by source page**.
|
|
429
|
+
|
|
430
|
+
`junit` and `sarif` leave out `info` findings. In them every entry asks for a
|
|
431
|
+
fix: a failed test, an alert in GitHub Code Scanning. An `info` finding is a
|
|
432
|
+
note about the site, such as "content is not compared on this host"
|
|
433
|
+
(`SOFT_404_PROBE`); the other formats keep it.
|
|
434
|
+
|
|
435
|
+
## Extending: add a new check
|
|
436
|
+
|
|
437
|
+
No core edits required. Create `src/findbrokenlinks/checks/my_check.py`:
|
|
438
|
+
|
|
439
|
+
```python
|
|
440
|
+
from findbrokenlinks.checks.base import Check, CheckContext, register
|
|
441
|
+
from findbrokenlinks.models import FetchResult, Issue, LinkRef
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
@register
|
|
445
|
+
class SlowResponseCheck(Check):
|
|
446
|
+
code = "SLOW_RESPONSE"
|
|
447
|
+
severity = "warning"
|
|
448
|
+
|
|
449
|
+
def evaluate(self, link: LinkRef, fetch: FetchResult, ctx: CheckContext) -> Issue | None:
|
|
450
|
+
if fetch.elapsed_ms > 5_000:
|
|
451
|
+
return Issue(self.code, self.severity, f"slow: {fetch.elapsed_ms:.0f}ms",
|
|
452
|
+
{"ms": fetch.elapsed_ms})
|
|
453
|
+
return None
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
That's it. The package auto-discovers every submodule under `checks/` on
|
|
457
|
+
import, so dropping the file is enough — no `__init__.py` edits required.
|
|
458
|
+
Your check is now available everywhere, and can be toggled via
|
|
459
|
+
`--enable-checks SLOW_RESPONSE` / `--disable-checks SLOW_RESPONSE`.
|
|
460
|
+
|
|
461
|
+
## Extending: add a new output format
|
|
462
|
+
|
|
463
|
+
Same pattern. Create `src/findbrokenlinks/reporters/my_reporter.py`:
|
|
464
|
+
|
|
465
|
+
```python
|
|
466
|
+
from findbrokenlinks.models import Finding
|
|
467
|
+
from findbrokenlinks.reporters.base import Reporter, register
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
@register
|
|
471
|
+
class MyReporter(Reporter):
|
|
472
|
+
name = "myfmt"
|
|
473
|
+
file_ext = "myx"
|
|
474
|
+
|
|
475
|
+
def render(self, findings: list[Finding]) -> str:
|
|
476
|
+
...
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
Drop the file under `reporters/` — same auto-discovery applies — and you
|
|
480
|
+
can now pass `--format myfmt`.
|
|
481
|
+
|
|
482
|
+
## Extending: custom soft-404 patterns
|
|
483
|
+
|
|
484
|
+
Built-in patterns live in `src/findbrokenlinks/patterns/builtin.yaml`. Add your
|
|
485
|
+
own without forking — pass `--patterns my_patterns.yaml`:
|
|
486
|
+
|
|
487
|
+
```yaml
|
|
488
|
+
- name: my_cms_404
|
|
489
|
+
target: title # title | h1 | body | raw
|
|
490
|
+
regex: '(?i)not here'
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
`target` picks the search surface:
|
|
494
|
+
|
|
495
|
+
- `title` / `h1` — text of those elements
|
|
496
|
+
- `body` — full page text after BeautifulSoup `get_text()` — markup stripped
|
|
497
|
+
- `raw` — the unaltered HTML body, including tags, attributes, and server
|
|
498
|
+
signatures that text extraction would erase
|
|
499
|
+
|
|
500
|
+
User patterns are merged with the built-in set (Composite).
|
|
501
|
+
|
|
502
|
+
## Architecture
|
|
503
|
+
|
|
504
|
+
```
|
|
505
|
+
seed URL ──► Crawler (asyncio.Queue + N workers)
|
|
506
|
+
│
|
|
507
|
+
├─► Fetcher ──► httpx.AsyncClient (rate-limited, robots-aware)
|
|
508
|
+
├─► HTMLExtractor (bs4 + lxml)
|
|
509
|
+
├─► Checks (Strategy + Registry, per-finding evaluation)
|
|
510
|
+
└─► Reporter (Strategy + Registry, multiple formats)
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
Design patterns used:
|
|
514
|
+
|
|
515
|
+
- **Strategy + Registry** — `Check` and `Reporter` ABCs with `@register`-driven
|
|
516
|
+
plug-in collections
|
|
517
|
+
- **Producer–Consumer / Worker Pool** — `asyncio.Queue` + N workers
|
|
518
|
+
- **Composite** — built-in + user soft-404 patterns merged
|
|
519
|
+
- **Factory** — `get_reporter(name)` resolves a format string
|
|
520
|
+
- **Pipeline** — Fetcher → Extractor → Checks → Reporter
|
|
521
|
+
- **Observer** — `on_finding` callback drives incremental report writing for
|
|
522
|
+
streaming formats (csv, tsv, jsonl)
|
|
523
|
+
|
|
524
|
+
See `docs/context.md` for the up-to-date design and rationale. `docs/plan.md` is
|
|
525
|
+
the day-0 approved plan, kept as a baseline against which to read the change log.
|
|
526
|
+
|
|
527
|
+
## Development
|
|
528
|
+
|
|
529
|
+
```bash
|
|
530
|
+
make install-dev # set up dev environment
|
|
531
|
+
make check # ← run before pushing: lint + typecheck + tests
|
|
532
|
+
# (mirrors the GitHub Actions pipeline)
|
|
533
|
+
make test # run the test suite (~10s)
|
|
534
|
+
make test-unit # unit tests only (skip live-server integration)
|
|
535
|
+
make test-integration # only the live-server integration test
|
|
536
|
+
make lint # ruff
|
|
537
|
+
make typecheck # mypy
|
|
538
|
+
make package # build sdist + wheel, twine check, smoke-test the
|
|
539
|
+
# wheel in a clean venv (mirrors CI job `package`)
|
|
540
|
+
make clean # nuke venv, caches, build artifacts, generated reports
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
Tests run against a local Starlette server with known-broken routes and a
|
|
544
|
+
static fixture site (`tests/fixtures/site/`) — no network access required for CI.
|
|
545
|
+
|
|
546
|
+
## CI integration
|
|
547
|
+
|
|
548
|
+
### Exit codes
|
|
549
|
+
|
|
550
|
+
| Code | Meaning |
|
|
551
|
+
|---|---|
|
|
552
|
+
| `0` | no finding at or above `--fail-on` (default `error`) |
|
|
553
|
+
| `1` | at least one finding at or above `--fail-on` |
|
|
554
|
+
| `2` | bad arguments: unknown option or format, a start URL that is not `http(s)://host…` or has a bad port, a malformed output path template, a `--log-file` that cannot be opened, invalid `--patterns` file, … |
|
|
555
|
+
| `3` | the crawl failed or is incomplete (a crash, or a URL the crawler could not process); the report, if written, is partial |
|
|
556
|
+
|
|
557
|
+
`3` takes precedence over `1`: an incomplete report can't vouch for the site.
|
|
558
|
+
`--fail-on warning` also fails on the warning-level checks: anti-bot blocks,
|
|
559
|
+
redirect chains, redirects to the home page, both soft-404 detectors and an
|
|
560
|
+
incomplete TLS certificate chain. `--fail-on never` keeps the job green and
|
|
561
|
+
leaves the verdict to the report.
|
|
562
|
+
|
|
563
|
+
On any CI, the CLI and its exit code are enough. In GitHub Actions, say:
|
|
564
|
+
|
|
565
|
+
```yaml
|
|
566
|
+
- run: pip install findbrokenlinks
|
|
567
|
+
- run: findbrokenlinks https://your-site.example --mode internal+external \
|
|
568
|
+
--format junit -o link-check.xml
|
|
569
|
+
- uses: mikepenz/action-junit-report@v4
|
|
570
|
+
if: always()
|
|
571
|
+
with:
|
|
572
|
+
report_paths: link-check.xml
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
Uploading the SARIF output to GitHub Code Scanning needs `--sarif-anchor PATH`.
|
|
576
|
+
Without it, results are located by page URL, and Code Scanning rejects the whole
|
|
577
|
+
upload when an `artifactLocation.uri` is an `http(s)://` URL rather than a
|
|
578
|
+
repository file (`SARIF URI scheme "https" did not match the checkout URI scheme
|
|
579
|
+
"file"`). With it, every result is attached to line 1 of that repository file
|
|
580
|
+
(`mkdocs.yml`, say), and the URLs are in the message. There is one result per
|
|
581
|
+
check and broken target, so a dead link in a site-wide footer is one alert, not
|
|
582
|
+
one per page. An alert keeps its identity from run to run through a fingerprint
|
|
583
|
+
of the check and the target: the message, the anchor file and its first line may
|
|
584
|
+
change. The GitHub Action does this by default, see
|
|
585
|
+
[Alerts in Code Scanning](https://github.com/as-mnt/findbrokenlinks#alerts-in-code-scanning).
|
|
586
|
+
|
|
587
|
+
## Documentation
|
|
588
|
+
|
|
589
|
+
- [`CHANGELOG.md`](https://github.com/as-mnt/findbrokenlinks/blob/main/CHANGELOG.md) — what changed, release by release
|
|
590
|
+
- [`docs/task.md`](https://github.com/as-mnt/findbrokenlinks/blob/main/docs/task.md) — original problem statement and decisions
|
|
591
|
+
- [`docs/plan.md`](https://github.com/as-mnt/findbrokenlinks/blob/main/docs/plan.md) — the implementation plan **as approved on day 0**
|
|
592
|
+
(historical snapshot — see `docs/context.md` for what actually ships)
|
|
593
|
+
- [`docs/context.md`](https://github.com/as-mnt/findbrokenlinks/blob/main/docs/context.md) — implementation snapshot, file layout,
|
|
594
|
+
how to extend each subsystem
|
|
595
|
+
- [`docs/roadmap.md`](https://github.com/as-mnt/findbrokenlinks/blob/main/docs/roadmap.md) — plan for 1.0.0: PyPI package and
|
|
596
|
+
GitHub Action
|
|
597
|
+
|
|
598
|
+
## License
|
|
599
|
+
|
|
600
|
+
MIT — see [LICENSE](https://github.com/as-mnt/findbrokenlinks/blob/main/LICENSE).
|