forked from 2600hz/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-ref-docs.bash
executable file
·66 lines (50 loc) · 1.65 KB
/
check-ref-docs.bash
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
#!/usr/bin/env bash
set -e
pushd "$(dirname "$0")" >/dev/null
ROOT=$(readlink -f "$(pwd -P)"/..)
errors=0
missing=""
REF_DIRS=$(find $ROOT/core $ROOT/applications -name "ref" -type d)
for REF_DIR in $REF_DIRS; do
for REF_DIFF in $(git --no-pager diff --name-only HEAD -- $REF_DIR); do
DOC=$(dirname $(dirname $REF_DIFF))/$(basename $REF_DIFF)
DOC_DIFF=$(git --no-pager diff --name-only HEAD -- $DOC)
if [ -f $DOC ] && [ -z $DOC_DIFF ]; then
missing="$missing $DOC:1: "$'\n'
errors=1
fi
done
done
if [ $errors = 1 ]; then
echo "The following .md files are missing changes from their ref doc:"
echo $missing
popd >/dev/null
exit $errors
fi
missing=""
declare -A ref_map
# maps ref doc name to doc name when not the same
ref_map=([vmboxes.md]=voicemail.md \
[conferences.md]=conference.md \
[whitelabel.md]=whitelabeling.md \
[user_auth.md]=user_authentication.md \
[api_auth.md]=api_authentication.md \
)
for REF_DIR in $REF_DIRS; do
for REF in $(find $REF_DIR -name "*.md"); do
DOC=$(dirname $(dirname $REF))/$(basename $REF)
if [ ${ref_map[$(basename $REF)]} ]; then DOC=$(dirname $(dirname $REF))/${ref_map[$(basename $REF)]}; fi
if [ ! -f "$DOC" ]; then
missing="$missing $DOC - creating it from $REF"$'\n'
cp -a $REF $DOC
errors=1
fi
done
done
if [ $errors = 1 ]; then
echo "The following docs were auto-created from their ref versions:"
echo "$missing"
popd >/dev/null
exit $errors
fi
popd >/dev/null