-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
78 lines (62 loc) · 2.33 KB
/
build.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
#!/bin/bash
getLatestTag() {
REPO="ssh://git@github.com/CommerceExperts/$1"
git -c 'versionsort.suffix=-' \
ls-remote --exit-code --refs --sort='version:refname' --tags "$REPO" '*.*.*' \
| tail --lines=1 \
| cut --delimiter='/' --fields=3
}
TARGET_BRANCH="gh-pages"
publish() {
cd _build/html/
git add --all .
git commit -m "Update docs with build $BUILD_ID" && git push -u origin "$TARGET_BRANCH" || echo "no changes"
}
substModuleVersions() {
dir="$1"
modules=(smartquery smartsuggest)
for module in ${modules[*]};
do
# variable substitution
TAG="$(getLatestTag "$module")"
VERSION="${TAG/v/}"
declare -x $(echo "$module" | tr '[:lower:]' '[:upper:]')_VERSION="$VERSION"
find "$dir/$module"/ -type f -name '*.rst' | while read file; do cp "$file" "$file.orig"; <"$file.orig" envsubst > "$file"; rm "$file.orig"; done
done
}
# build
cd docs/
resetBuildDir() {
# clear potential old build
sudo -n chown -R "$(whoami)": _build/
rm -rf _build/html
mkdir -p _build/html
# the very same repository, just a different branch is checkoud in this subdirectory
git clone --depth 1 --single-branch --branch="$TARGET_BRANCH" -v git@github.com:CommerceExperts/searchhub-docs.git _build/html
}
resetBuildDir
# - replace placeholders, like version numbers etc:
substModuleVersions .
# substitute dynamic values in config.py
YEAR="$(date +%Y)"
file=conf.py; cp "$file" "$file.orig"; <"$file.orig" envsubst > "$file"; rm "$file.orig"
# docker login
AWS_CMD="$(which aws || echo "$HOME/.local/bin/aws")"
$($AWS_CMD ecr get-login --no-include-email --region eu-central-1)
docker run --rm -u root -v "$(pwd)":/docs 399621189843.dkr.ecr.eu-central-1.amazonaws.com/util/sphinx-docs:5.3.0 make html
if [ "$?" -ne 0 ]; then echo "could not generate docs"; exit 1; fi
sudo -n chown -R "$(whoami)": _build/
# fix final docs:
# - add CNAME files
echo -n "docs.searchhub.io" > _build/html/CNAME
# - special case to make 404 page work for all missing links
if [ -e "_build/html/404.html" ]; then
sed -i 's#<head>#<head>\n <base href="/">\n#' _build/html/404.html
else
find _build/ -name 404.html -print0 | xargs -0 -L1 sed -i 's#<head>#<head>\n <base href="/searchhub-docs/">\n#'
fi
# publish if requested
if [[ "$1" == "publish" ]]; then
publish
fi
git checkout .