Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add ci job to check local link issues #329

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -91,4 +91,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