Repository navigation
72 lines (62 loc) · 2.12 KB
/
Copy pathdocumentation.yml
File metadata and controls
72 lines (62 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Documentation
on:
push:
branches: [main]
paths:
- '**.md'
- '.github/workflows/documentation.yml'
pull_request:
paths:
- '**.md'
- '.github/workflows/documentation.yml'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: documentation-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
markdown:
name: Check local documentation links
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 2
- name: Check Markdown links and whitespace
shell: python
run: |
from pathlib import Path
import re
import sys
from urllib.parse import unquote
files = [
path for path in Path('.').rglob('*.md')
if '.git' not in path.parts
]
link_pattern = re.compile(r'(?<!!)\[[^\]]*\]\(([^)]+)\)')
errors = []
for source in files:
text = source.read_text(encoding='utf-8')
for raw_target in link_pattern.findall(text):
target = raw_target.strip().strip('<>')
if not target or target.startswith(('#', 'http://', 'https://', 'mailto:')):
continue
target = unquote(target.split('#', 1)[0])
target = target.split(' ', 1)[0]
candidate = (source.parent / target).resolve()
candidates = [candidate]
if candidate.suffix == '':
candidates.append(candidate.with_suffix('.md'))
if not any(path.exists() for path in candidates):
errors.append(f'{source}: missing local link {raw_target}')
if errors:
print('\n'.join(errors), file=sys.stderr)
raise SystemExit(1)
print(f'Checked {len(files)} Markdown files and their local links.')
- name: Check whitespace errors
shell: bash
run: |
if git rev-parse --verify --quiet HEAD^ >/dev/null; then
git diff --check HEAD^ HEAD
fi