-
Notifications
You must be signed in to change notification settings - Fork 11
/
check-readme
executable file
·58 lines (46 loc) · 1.27 KB
/
check-readme
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
#!/bin/bash
# Check that the README links to all files of interest; a heuristic for keeping
# us honest about documenting the contents of this repo.
set -euo pipefail
shopt -s extglob
delim=$'\x1f' # ASCII unit separator
main() {
compare | report
}
compare() {
comm --output-delimiter="$delim" \
<(files-of-interest | sort) \
<(relative-links README.md | sort)
}
report() {
local failed=0
while IFS="$delim" read -r missing unknown found; do
if [[ -n $missing ]]; then
echo "missing link to: $missing" >&2
: $((failed++))
elif [[ -n $unknown ]]; then
echo "link to unknown file: $unknown" >&2
: $((failed++))
elif [[ -n $found ]]; then
echo "found: $found"
fi
done
return "$failed"
}
files-of-interest() {
git ls-files | grep -vxFf <(files-to-ignore)
}
files-to-ignore() {
git ls-files \
.gitignore \
'**/.gitignore' \
README.md \
'images/*' \
actions/setup-ssh/!(*.yaml|README.md) \
actions/setup-debugger/!(*.yaml|README.md) \
actions/shellcheck/!(*.yaml|README.md)
}
relative-links() {
grep -oP '\[.+?\]\(.+?\)' "$@" | grep -oP '(?<=\()(?!(https?|mailto)://).+?(?=\))'
}
main "$@"