-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-docs.sh
executable file
·141 lines (122 loc) · 2.99 KB
/
build-docs.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash -eux
AUTHOR="Maximilian Blochberger"
AUTHOR_URL="https://github.com/blochberger"
GITHUB_URL="https://github.com/blochberger/Keychain"
MODULE="Keychain"
README="README.md"
VERSION=$(git describe --always)
LAST_COMMIT=$(git log -1 --format='%H')
GITHUB_FILE_PREFIX="${GITHUB_URL}/blob/${LAST_COMMIT}"
OUTPUT_DIR="gh-pages"
JAZZY_THEME="fullwidth"
COMMIT=false
RUN_TESTS=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--commit)
COMMIT=true
shift
;;
--test)
RUN_TESTS=true
shift
;;
-h|--help)
echo "Usage: [--test] [--commit] [-h|--help]" >&2
exit 0
;;
*)
echo "Usage: [--test] [--commit] [-h|--help]" >&2
echo "Unknown option: ${key}" >&2
exit 1
;;
esac
done
# Check requirements
if ! [ -x "$(command -v jazzy)" ]; then
echo "Did not find 'jazzy'. Please install with: gem install --user-install jazzy" >&2
exit 1
fi
if ! [ -x "$(command -v xcov)" ]; then
echo "Did not find 'xcov'. Please install with: gem install --user-install xcov" >&2
exit 1
fi
# Generate documentation
for SDK in macos iphone; do
for MIN_ACL in public private internal; do
OUTPUT="${OUTPUT_DIR}/${SDK}/${MIN_ACL}"
jazzy\
--clean\
--use-safe-filenames\
--theme="${JAZZY_THEME}"\
--author="${AUTHOR}"\
--author_url="${AUTHOR_URL}"\
--github_url="${GITHUB_URL}"\
--github-file-prefix="${GITHUB_FILE_PREFIX}"\
--readme="${README}"\
--module="${MODULE}"\
--module-version="${VERSION}"\
--sdk="${SDK}"\
--min-acl="${MIN_ACL}"\
--output="${OUTPUT}"
done # MIN_ACL
done # SDK
# Execute unit tests and create test coverage badge
if [ ${RUN_TESTS} = true ]; then
function build {
xcodebuild\
-quiet\
-sdk macosx\
-project "${MODULE}.xcodeproj"\
-scheme "${MODULE}_macOS"\
-enableCodeCoverage YES\
-derivedDataPath "build"\
clean\
test
}
if [ -x "$(command -v xcpretty)" ]; then
set -o pipefail
build | xcpretty
else
build
fi
XCCOVREPORT=$(find build/Logs/Test -name '*.xccovreport' | tail -1)
xcrun xccov view --json "$XCCOVREPORT" > build/coverage.json
COVERAGE=$(
python3 "extract_coverage.py" "${MODULE}.framework" < build/coverage.json
)
# See https://github.com/realm/jazzy/blob/a02fe0a86e02e5e0d67e96a05d5040478a8a36a3/lib/jazzy/doc_builder.rb#L239-L253
if [[ ${COVERAGE} -lt 10 ]]; then
COLOR='red'
elif [[ ${COVERAGE} -lt 30 ]]; then
COLOR='orange'
elif [[ ${COVERAGE} -lt 60 ]]; then
COLOR='yellow'
elif [[ ${COVERAGE} -lt 85 ]]; then
COLOR='yellowgreen'
elif [[ ${COVERAGE} -lt 90 ]]; then
COLOR='green'
else
COLOR='brightgreen'
fi
curl\
--progress-bar\
--output "${OUTPUT_DIR}/macos/coverage.svg"\
"https://img.shields.io/badge/coverage-${COVERAGE}%25-${COLOR}.svg"
xcov\
--html_report\
--scheme "${MODULE}_macOS"\
--output_directory "${OUTPUT_DIR}/macos/coverage"
fi
# Commit results
if [ ${COMMIT} = true ]; then
(
cd "${OUTPUT_DIR}"
git add iphone macos
git commit -m "Update documentation to ${VERSION}"
)
fi
# Cleanup
rm -rf build