-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ci job to check local link issues
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -u | ||
[ -n "${DEBUG:-}" ] && set -x || true | ||
|
||
function gherr() { | ||
local line="$1" | ||
local file="${line%%:*}" | ||
local lineno="${line#*:}" | ||
lineno="${lineno%%:*}" | ||
local matching="${line#*:*:}" | ||
echo "::error file=${file#./},line=$lineno::Broken link $matching" | ||
} | ||
|
||
function check() { | ||
local line dir link target failed=0 | ||
|
||
while read line; do | ||
dir="$(dirname "${line%%:*}")" | ||
link="${line#*:*:}" | ||
|
||
case "$link" in | ||
//*) | ||
# ignore http links | ||
;; | ||
/*) | ||
fail "Not a valid local link" | ||
;; | ||
../*) | ||
target="$(dirname "$dir")${link#..}" | ||
if ! [ -f "$target" ]; then | ||
failed=1 | ||
gherr "$line" | ||
fi | ||
;; | ||
*) | ||
# relative to current directory | ||
target="$dir/${link#./}" | ||
if ! [ -f "$target" ]; then | ||
failed=1 | ||
gherr "$line" | ||
fi | ||
;; | ||
esac | ||
done | ||
|
||
exit "$failed" | ||
} | ||
|
||
find . -name '*.md' -print0 | xargs -0 /usr/bin/grep -Hno '[^(): ][^():]*\.md' | check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Local Link Checker | ||
|
||
on: | ||
push: | ||
branches: | ||
- "*" | ||
pull_request: | ||
|
||
jobs: | ||
local-link-checker: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: run checker | ||
run: .github/scripts/local-link-checker.sh | ||
|
||
- name: info for fixing | ||
if: ${{ failure() }} | ||
run: echo "Run ./.github/scripts/local-link-checker.sh to check locally" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,3 @@ _book | |
.DS_Store | ||
*.patch | ||
*.sh |