Skip to content

Commit

Permalink
Merge pull request #329 from nervosnetwork/local-link-checker
Browse files Browse the repository at this point in the history
ci: add ci job to check local link issues
  • Loading branch information
janx authored Feb 6, 2023
2 parents 7248f62 + ca00b95 commit 0229ae4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
51 changes: 51 additions & 0 deletions .github/scripts/local-link-checker.sh
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
21 changes: 21 additions & 0 deletions .github/workflows/local-link-checker.yaml
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 "::error::Broken local links found, please use ./.github/scripts/local-link-checker.sh to check locally"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ _book
.DS_Store
*.pdf
*.patch
*.sh
2 changes: 1 addition & 1 deletion rfcs/0034-vm-syscalls-2/0034-vm-syscalls-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ The arguments used here are:
* [2]: [CKB VM version selection][2]
[1]: ../0014-vm-cycle-limits/0014-vm-cycle-limits.md
[2]: ../0232-ckb-vm-version-selection/0232-ckb-vm-version-selection.md
[2]: ../0032-ckb-vm-version-selection/0032-ckb-vm-version-selection.md

0 comments on commit 0229ae4

Please sign in to comment.