-
Notifications
You must be signed in to change notification settings - Fork 41
/
gendoc.sh
executable file
·196 lines (173 loc) · 6.61 KB
/
gendoc.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash -eu
shopt -s expand_aliases
function clone_or_pull {
remote=$1
dir="${ZITI_DOC_GIT_LOC}/${2}"
if [[ -n ${3:-} ]]; then
local BRANCH="${3}"
else
local BRANCH="main"
fi
if [ -d "${dir}" ]; then
pushd "${dir}" >/dev/null
git checkout "${BRANCH}"
git pull
popd >/dev/null
else
git clone "${remote}" --branch "${BRANCH}" --single-branch "${dir}" --depth 1
fi
}
set -e
script_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "$script_root"
: ${SKIP_GIT:=no}
: ${SKIP_LINKED_DOC:=no}
: ${SKIP_CLEAN:=no}
ZITI_DOC_GIT_LOC="${script_root}/docusaurus/_remotes"
SDK_ROOT_TARGET="${script_root}/docusaurus/static/docs/reference/developer/sdk"
: ${ZITI_DOCUSAURUS:=yes}
echo "- processing opts"
while getopts ":glcs" OPT; do
case ${OPT} in
g ) # skip git
echo "- skipping creating and updating Git working copies"
SKIP_GIT="yes"
;;
l ) # skip linked doc gen
echo "- skipping linked doc generation"
SKIP_LINKED_DOC="yes"
;;
c ) # skip clean steps
echo "- skipping clean step that deletes Git working copies"
SKIP_CLEAN="yes"
;;
s ) # INCLUDE stargazer stuff
echo "- fetching stargazer data as well"
ADD_STARGAZER_DATA="yes"
;;
*)
echo "WARN: ignoring option ${OPT}" >&2
;;
esac
done
echo "- done processing opts"
if [[ "${SKIP_GIT}" == no ]]; then
echo "updating dependencies by rm/checkout"
mkdir -p "${ZITI_DOC_GIT_LOC}"
if [[ "${SKIP_CLEAN}" == no ]]; then
rm -rf ${ZITI_DOC_GIT_LOC}/ziti-*
fi
git config --global --add safe.directory $(pwd)
clone_or_pull "https://github.com/openziti/ziti" "ziti-cmd" >/dev/null
clone_or_pull "https://github.com/openziti/ziti-sdk-csharp" "ziti-sdk-csharp" >/dev/null
clone_or_pull "https://github.com/openziti/ziti-sdk-c" "ziti-sdk-c" >/dev/null
clone_or_pull "https://github.com/openziti/ziti-android-app" "ziti-android-app" >/dev/null
clone_or_pull "https://github.com/openziti/ziti-sdk-swift" "ziti-sdk-swift" >/dev/null
clone_or_pull "https://github.com/openziti/ziti-tunnel-sdk-c" "ziti-tunnel-sdk-c" >/dev/null
clone_or_pull "https://github.com/openziti/helm-charts" "helm-charts" >/dev/null
clone_or_pull "https://github.com/openziti-test-kitchen/kubeztl" "kubeztl" >/dev/null
fi
if [[ "${SKIP_CLEAN}" == no ]]; then
if test -d "${SDK_ROOT_TARGET}"; then
# specifically using ../ziti-doc just to remove any chance to rm something unintended
echo removing previous build at: rm -r "${SDK_ROOT_TARGET}"
rm -r "${SDK_ROOT_TARGET}" || true
fi
fi
if [[ "${SKIP_LINKED_DOC}" == no ]]; then
commands_to_test=(doxygen wget)
# verify all the commands required in the automation exist before trying to run the full suite
for cmd in "${commands_to_test[@]}"; do
# checking all commands are on the path before continuing...
result="$(type ${cmd} &>/dev/null && echo "Found" || echo "Not Found")"
if [[ "Not Found" == "${result}" ]]; then
missing_requirements+=" * ${cmd}\n"
fi
done
# are requirements ? if yes, stop here and help 'em out
if [[ -n "${missing_requirements:-}" ]]; then
echo " "
echo "The commands listed below are required to be on the path for this script to function properly."
echo "Please ensure the commands listed are on the path and then try again."
printf "\n${missing_requirements}"
echo " "
echo "If any of these commands are declared as aliases ensure your alias is"
echo "declared inside of ~/.bash_aliases - or modify this script to add the aliases you require"
exit 1
fi
if [[ "${ZITI_DOCUSAURUS}" == yes ]]; then
echo "=================================================="
#echo "csharp: building the c# sdk docs"
#
CSHARP_SOURCE="${ZITI_DOC_GIT_LOC}/ziti-sdk-csharp/docs"
CSHARP_TARGET="${SDK_ROOT_TARGET}/csharp"
echo "Copying csharp SDK docs"
echo " from: ${CSHARP_SOURCE}"
echo " to: ${CSHARP_TARGET}"
echo " "
mkdir -p "${CSHARP_TARGET}"
cp -r "${CSHARP_SOURCE}/"* "${CSHARP_TARGET}"
fi
if test -f "${ZITI_DOC_GIT_LOC}/ziti-sdk-c/Doxyfile"; then
pushd "${ZITI_DOC_GIT_LOC}/ziti-sdk-c" >/dev/null
doxygen
CLANG_SOURCE="${ZITI_DOC_GIT_LOC}/ziti-sdk-c/api"
CLANG_TARGET="${SDK_ROOT_TARGET}/clang"
echo " "
echo "Copying C SDK doc"
echo " from: ${CLANG_SOURCE}"
echo " to: ${CLANG_TARGET}"
echo " "
mkdir -p "${CLANG_TARGET}"
cp -r "${CLANG_SOURCE}/"* "${CLANG_TARGET}"
echo " "
echo "Removing"
echo " ${ZITI_DOC_GIT_LOC}/ziti-sdk-c/api"
rm -rf "${ZITI_DOC_GIT_LOC}/ziti-sdk-c/api"
popd >/dev/null
else
echo "ERROR: CSDK Doxyfile not located"
fi
if test -f "${ZITI_DOC_GIT_LOC}/ziti-sdk-swift/CZiti.xcodeproj/project.pbxproj"; then
SWIFT_API_TARGET="${SDK_ROOT_TARGET}/swift"
mkdir -p "${SWIFT_API_TARGET}"
pushd "${SWIFT_API_TARGET}" >/dev/null
swift_tgz="https://github.com/openziti/ziti-sdk-swift/releases/latest/download/ziti-sdk-swift-docs.tgz"
echo " "
echo "Copying Swift docs"
echo " from: ${swift_tgz}"
echo " to: ${SWIFT_API_TARGET}"
echo " "
echo " via: wget -q -O - ${swift_tgz} | tar -zxv"
pwd
#wget -q -O - "${swift_tgz}" | tar -zxvC "${SWIFT_API_TARGET}"
wget -q -O - "${swift_tgz}" | tar -zxv
find "${SWIFT_API_TARGET}" -name "EnrollmentResponse*"
popd >/dev/null
fi
fi
if [[ "${ADD_STARGAZER_DATA-}" == "yes" ]]; then
echo "collecting stargazer data before building the site... "
echo " - this requires the npm module cvstojson"
echo " - this requires you to have a GITHUB_TOKEN environment variable exported"
./gh-stats.sh
fi
pushd ${ZITI_DOC_GIT_LOC}/.. >/dev/null
echo "running 'yarn install' in ${PWD}"
yarn install --frozen-lockfile
echo "running 'yarn build' in ${PWD}"
yarn build
popd >/dev/null
echo " "
if test -e "${script_root}/docusaurus/build/landing.html"; then
echo "landing.html detected. overwriting index.html with landing.html"
cp "${script_root}/docusaurus/build/index.html" "${script_root}/docusaurus/build/index.original.html"
cp "${script_root}/docusaurus/build/landing.html" "${script_root}/docusaurus/build/index.html"
sed -i -e 's|https://openziti.io/|/|g' "${script_root}/docusaurus/build/index.html"
sed -i -e 's|link\.setAttribute("href", "https://openziti\.io/|link.setAttribute("href", "/|g' "${script_root}/docusaurus/build/index.html"
echo "landing.html sed commands run"
echo "landing.html overwritten to index.html. index.html is now index.original.html"
fi
echo " "
echo "------------------------"
echo "gendoc complete"