Skip to content

Commit 0229ae4

Browse files
authored
Merge pull request #329 from nervosnetwork/local-link-checker
ci: add ci job to check local link issues
2 parents 7248f62 + ca00b95 commit 0229ae4

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
set -u
5+
[ -n "${DEBUG:-}" ] && set -x || true
6+
7+
function gherr() {
8+
local line="$1"
9+
local file="${line%%:*}"
10+
local lineno="${line#*:}"
11+
lineno="${lineno%%:*}"
12+
local matching="${line#*:*:}"
13+
echo "::error file=${file#./},line=$lineno::Broken link $matching"
14+
}
15+
16+
function check() {
17+
local line dir link target failed=0
18+
19+
while read line; do
20+
dir="$(dirname "${line%%:*}")"
21+
link="${line#*:*:}"
22+
23+
case "$link" in
24+
//*)
25+
# ignore http links
26+
;;
27+
/*)
28+
fail "Not a valid local link"
29+
;;
30+
../*)
31+
target="$(dirname "$dir")${link#..}"
32+
if ! [ -f "$target" ]; then
33+
failed=1
34+
gherr "$line"
35+
fi
36+
;;
37+
*)
38+
# relative to current directory
39+
target="$dir/${link#./}"
40+
if ! [ -f "$target" ]; then
41+
failed=1
42+
gherr "$line"
43+
fi
44+
;;
45+
esac
46+
done
47+
48+
exit "$failed"
49+
}
50+
51+
find . -name '*.md' -print0 | xargs -0 /usr/bin/grep -Hno '[^(): ][^():]*\.md' | check
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Local Link Checker
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
pull_request:
8+
9+
jobs:
10+
local-link-checker:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: run checker
17+
run: .github/scripts/local-link-checker.sh
18+
19+
- name: info for fixing
20+
if: ${{ failure() }}
21+
run: echo "::error::Broken local links found, please use ./.github/scripts/local-link-checker.sh to check locally"

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ _book
33
.DS_Store
44
*.pdf
55
*.patch
6-
*.sh

rfcs/0034-vm-syscalls-2/0034-vm-syscalls-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ The arguments used here are:
9090
* [2]: [CKB VM version selection][2]
9191
9292
[1]: ../0014-vm-cycle-limits/0014-vm-cycle-limits.md
93-
[2]: ../0232-ckb-vm-version-selection/0232-ckb-vm-version-selection.md
93+
[2]: ../0032-ckb-vm-version-selection/0032-ckb-vm-version-selection.md

0 commit comments

Comments
 (0)