forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-docs.sh
executable file
·213 lines (183 loc) · 6.07 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
###################################################################################
# This script generates a versioned docs website for Gloo Edge which can
# then be deployed to firebase
###################################################################################
set -ex
# Update this array with all versions of Gloo Edge to include in the versioned docs website.
declare -a versions=($(cat active_versions.json | jq -rc '."versions" | join(" ")'))
declare -a oldVersions=($(cat active_versions.json | jq -rc '."oldVersions" | join(" ")'))
latestVersion=$(cat active_versions.json | jq -r ."latest")
# verify that latestVersion is in versions
latestVersionInVersions=false
for version in "${versions[@]}"
do
if [ "$version" == "$latestVersion" ]; then
latestVersionInVersions=true
fi
done
if ! $latestVersionInVersions ; then
echo "latest version not in versions, update the versions in active_versions.json"
exit 1
fi
# Firebase configuration
firebaseJson=$(cat <<EOF
{
"hosting": {
"site": "gloo-edge",
"public": "public",
"ignore": [
"firebase.json",
"themes/**/*",
"content/**/*",
"**/.*",
"resources/**/*",
"examples/**/*"
],
"rewrites": [
{
"source": "/",
"destination": "/gloo-edge/latest/index.html"
},
{
"source": "/gloo-edge",
"destination": "/gloo-edge/latest/index.html"
}
]
}
}
EOF
)
# This script assumes that the working directory is in the docs folder
workingDir=$(pwd)
docsSiteDir=$workingDir/ci
tempContentDir=$docsSiteDir/temp
repoDir=$workingDir/gloo-temp
mkdir -p $docsSiteDir
mkdir -p $tempContentDir
echo $firebaseJson > $docsSiteDir/firebase.json
git clone https://github.com/solo-io/gloo.git $repoDir
export PATH=$workingDir/_output/.bin:$PATH
# Generates a data/Solo.yaml file with $1 being the specified version.
# Should end up looking like the follwing:
# LatestVersion: 1.5.8
# DocsVersion: /gloo-edge/1.3.32
# CodeVersion: 1.3.32
# DocsVersions:
# - master
# - 1.6.0-beta8
# - 1.5.8
# OldVersions:
# - 1.4.15
# - 1.3.32
function generateHugoVersionsYaml() {
yamlFile=$repoDir/docs/data/Solo.yaml
# Truncate file first.
echo "LatestVersion: $latestVersion" > $yamlFile
# /gloo-edge prefix is needed because the site is hosted under a domain name with suffix /gloo-edge
echo "DocsVersion: /gloo-edge/$1" >> $yamlFile
echo "CodeVersion: $1" >> $yamlFile
echo "DocsVersions:" >> $yamlFile
for hugoVersion in "${versions[@]}"
do
echo " - $hugoVersion" >> $yamlFile
done
echo "OldVersions:" >> $yamlFile
for hugoVersion in "${oldVersions[@]}"
do
echo " - $hugoVersion" >> $yamlFile
done
}
function generateSiteForVersion() {
version=$1
latestMasterTag=$2
echo "Generating site for version $version"
cd $repoDir
# Replace version with "latest" if it's the latest version. This enables URLs with "/latest/..."
if [[ "$version" == "$latestVersion" ]]
then
version="latest"
fi
git checkout "$latestMasterTag"
cd docs
# Generate data/Solo.yaml file with version info populated.
generateHugoVersionsYaml $version
# Replace the master's content directory with the version we're building
rm -r $repoDir/docs/content
mkdir $repoDir/docs/content
cp -a $tempContentDir/$version/. $repoDir/docs/content/
# Remove the file responsible for the "security scan too large" bug if necessary
guilty_path="./content/reference/security-updates"
if cat $guilty_path/enterprise/_index.md | grep -q "glooe-security-scan-0"; then
echo "$version contains the updated security scan template"
else
echo "$version does not contain the updated security scan template"
rm -rf $guilty_path
fi
# Generate the versioned static site.
make site-release
# If we are on the latest version, then copy over `404.html` so firebase uses that.
# https://firebase.google.com/docs/hosting/full-config#404
if [[ "$version" == "latest" ]]
then
cp site-latest/404.html $docsSiteDir/public/404.html
fi
cat site-latest/index.json | node $workingDir/search/generate-search-index.js > site-latest/search-index.json
# Copy over versioned static site to firebase content folder.
mkdir -p $docsSiteDir/public/gloo-edge/$version
cp -a site-latest/. $docsSiteDir/public/gloo-edge/$version/
# Discard git changes and vendor_any for subsequent checkouts
cd $repoDir
git reset --hard
rm -fr vendor_any
}
# Copies the /docs/content directory from the specified version ($1) and stores it in a temp location
function getContentForVersion() {
version=$1
latestMasterTag=$2
echo "Getting site content for version $version"
cd $repoDir
if [[ "$version" == "master" ]]
then
git checkout "$latestMasterTag"
else
git checkout tags/v"$version"
fi
# Replace version with "latest" if it's the latest version. This enables URLs with "/latest/..."
if [[ "$version" == "$latestVersion" ]]
then
version="latest"
fi
cp -a $repoDir/docs/content/. $tempContentDir/$version/
}
# We build docs for all active and old version of Gloo, on pull requests (and merges) to master.
# On pull requests to master by Solo developers, we want to run doc generation
# against the commit that will become the latest master commit.
# This will allow us to verify if the change we are introducing is valid.
# Therefore, we use the head SHA on pull requests by Solo developers
latestMasterTag="master"
if [[ "$USE_PR_SHA_AS_MASTER" == "true" ]]
then
latestMasterTag=$PULL_REQUEST_SHA
echo using $PULL_REQUEST_SHA, as this will be the next commit to master
fi
# Obtain /docs/content dir from all versions
for version in "${versions[@]}"
do
getContentForVersion $version $latestMasterTag
done
# Obtain /docs/content dir from all previous versions
for version in "${oldVersions[@]}"
do
getContentForVersion $version $latestMasterTag
done
# Generate docs for all versions
for version in "${versions[@]}"
do
generateSiteForVersion $version $latestMasterTag
done
# Generate docs for all previous versions
for version in "${oldVersions[@]}"
do
generateSiteForVersion $version $latestMasterTag
done