-
Notifications
You must be signed in to change notification settings - Fork 11
/
package-report.sh
executable file
·90 lines (76 loc) · 2.69 KB
/
package-report.sh
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
#!/usr/bin/env bash
##
## Generates a report to help us ensure we have a documentation folder for each package and that each documentation
## folder has an index.html file. Has non-zero exit code if there are any errors.
##
# Takes two lists of words and echos the words that are in the first list which are missing in the second list.
# Usage: missing_words "word1 word2 word3" "word2 word3 word4"
function missing_words() {
local words1=($1)
local words2=($2)
local missing_words=()
for word1 in "${words1[@]}"; do
local found=false
for word2 in "${words2[@]}"; do
if [ "$word1" == "$word2" ]; then
found=true
break
fi
done
if [ "$found" == false ]; then
missing_words+=("$word1")
fi
done
echo "${missing_words[@]}"
}
HAS_ERRORS=false
# Use 'ls -d' to get a list of directories in the packages and docs folders. It retains the subfolder structure that we
# care about (e.g. ui/package-name). Could use find, but this is maybe a little easier to reason about.
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd $BASE_DIR/packages/
UI_PACKAGES=$(ls -d ui/*/)
CORE_PACKAGES=$(ls -d core/*/)
cd $BASE_DIR/docs/
CORE_DOCS=$(ls -d core/*/)
UI_DOCS=$(ls -d ui/*/)
# Get a list of packages which are missing a corresponding documentation folder.
MISSING_DOCS=$(missing_words "$CORE_PACKAGES" "$CORE_DOCS")
MISSING_DOCS+=$(missing_words "$UI_PACKAGES" "$UI_DOCS")
if [ ! -z $MISSING_DOCS ]; then
echo ""
echo "The following packages are missing documentation folders:"
for MISSING_DOC in "${MISSING_DOCS[@]}"; do
echo " $MISSING_DOC"
done
HAS_ERRORS=true
fi
# Inverse of the above (probably a mistake): Get a list of documentation folders which are missing a corresponding package.
MISSING_PACKAGES=$(missing_words "$CORE_DOCS" "$CORE_PACKAGES")
MISSING_PACKAGES+=$(missing_words "$UI_DOCS" "$UI_PACKAGES")
if [ ! -z "$MISSING_PACKAGES" ]; then
echo ""
echo "The following documentation folders are missing corresponding package folders (or may be misplaced):"
for MISSING_PACKAGE in "${MISSING_PACKAGES[@]}"; do
echo " $MISSING_PACKAGE"
done
HAS_ERRORS=true
fi
# See if any docs are missing an index.html file
MISSING_INDEX_HTML=()
for DOC_SUBDIR in $CORE_DOCS $UI_DOCS; do
if [ ! -f $BASE_DIR/docs/$DOC_SUBDIR/index.html ]; then
MISSING_INDEX_HTML+=($DOC_SUBDIR)
fi
done
if [ ! -z $MISSING_INDEX_HTML ]; then
echo ""
echo "The following documentation folders are missing an index.html file:"
for MISSING_INDEX_HTML_ITEM in "${MISSING_INDEX_HTML[@]}"; do
echo " $MISSING_INDEX_HTML_ITEM"
done
HAS_ERRORS=true
fi
# Non-zero exit in case we want to use this in a CI pipeline.
if [ "$HAS_ERRORS" == true ]; then
exit 1
fi