forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-documentation
executable file
·92 lines (81 loc) · 2.38 KB
/
test-documentation
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
set -e
color_message() {
local color_code="$1" message="$2"
printf '\e[%sm%s\e[0m\n' "$color_code" "$message" >&2
}
loglevel=()
usage() {
cat <<EOF
usage:
--help, -h show this help message and exit
--loglevel=LEVEL, -L LEVEL log level (default: ERROR)
--skip-check-links skip checking of links
--skip-external-links skip checking of external links
EOF
}
args="$(getopt -o hL: --long help,loglevel:,skip-check-links,skip-external-links -- "$@")" \
|| {
usage >&2
exit 1
}
eval "set -- $args"
while true; do
case "$1" in
-h | --help)
usage
exit 0
;;
-L | --loglevel)
loglevel=("$1" "$2")
shift 2
;;
--skip-check-links)
skip_check_links=1
shift
;;
--skip-external-links)
skip_external_links=1
shift
;;
--)
shift
break
;;
*) exit 1 ;;
esac
done
cd "$(dirname "$0")"/../docs
# collapse_navigation is set to False in conf.py to improve sidebar navigation for users.
# However, we must change its value to True before we begin testing links.
# Otherwise, sphinx would generate a large number of links we don't need to test.
# The crawler would take a very long time to finish and TravisCI would fail as a result.
make clean html O='-D html_theme_options.collapse_navigation=True'
err=0
check() {
if "$@"; then
color_message 92 "Passed!"
else
color_message 91 "Failed!"
err=1
fi
}
color_message 94 "Validating HTML..."
check java -jar ../node_modules/vnu-jar/build/dist/vnu.jar \
--filterfile ../tools/documentation.vnufilter \
--skip-non-html \
_build/html
if [ -n "$skip_check_links" ]; then
color_message 94 "Skipped testing links in documentation."
else
cd ../tools/documentation_crawler
if [ -n "$skip_external_links" ]; then
color_message 94 "Testing only internal links in documentation..."
check scrapy crawl_with_status documentation_crawler -a skip_external=set "${loglevel[@]}"
# calling crawl directly as parameter needs to be passed
else
color_message 94 "Testing links in documentation..."
check scrapy crawl_with_status documentation_crawler "${loglevel[@]}"
fi
fi
exit "$err"