forked from RedHatQE/pylero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_docs.sh
executable file
·131 lines (114 loc) · 3.22 KB
/
gen_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
#!/bin/bash
# Temporary until CI is setup to build documentation dynamically
# Use this script to generate documentataion locally, run './gen_docs.sh -h'
# from root of the directory for more info
# Backoff from any failure
set -euo pipefail
trap 'handle_error $? $LINENO' EXIT
handle_error(){
if [ "$1" != "0" ]; then
printf "Cleanup of any failures\n"
printf "Error %s occured on %s, cleaning docs if generated\n" "$1" "$2"
if [[ $(pwd) =~ doc$ ]]; then
make clean
else
rm -rf _build/*
fi
if [[ $(pwd) =~ pylero$ ]]; then
make clean -C doc/
else
rm -rf doc/_build/*
fi
fi
}
usage()
{
echo
echo "Generate documentation using Sphinx locally and remove 'username(-n)',"
echo "'url(-u)', 'project(-p)' reference from docs"
echo
echo "Usage: ./gen_docs.sh [options]"
echo "options:"
echo " n Name of the Polarion user."
echo " u URL of Polarion local instance."
echo " p Project of Polarion local instance."
echo " h Print this help."
echo
}
if [[ $# -eq 0 ]] ; then
usage 1>&2
exit 1
fi
# Install sphinx if not installed
if ! command -v sphinx-build 1>/dev/null; then
echo "'sphinx-build' is required but not found in PATH, do you wish to install (Sphinx v3.4.3) via Pip?"
select yn in "Yes" "No"; do
case $yn in
Yes ) pip install sphinx==3.4.3; break;;
No ) echo "Can't procced without sphinx-build"; exit 1;;
esac
done
fi
options=":n:u:p:h"
name=""
url=""
project=""
while getopts $options opt; do
case ${opt} in
n )
name=$OPTARG
;;
u )
url=$OPTARG
;;
p )
project=$OPTARG
;;
h )
usage
exit;;
\? )
printf "\nInvalid Option: -%s\n" "$OPTARG" 1>&2
usage 1>&2
exit;;
: )
printf "\nInvalid option: %s requires an argument\n" "$OPTARG" 1>&2
usage 1>&2
exit;;
esac
done
shift $((OPTIND -1))
if [ -z "$name" ] || [ -z "$url" ] || [ -z "$project" ]; then
printf "\nMissing -n or -u or -p\n" 1>&2
usage 1>&2
exit 1
fi
# Copy Pylero configuration file to doc directory
[ -e "$HOME"/.pylero ] && cp "$HOME"/.pylero .pylero
[ -e .pylero ] && cp .pylero doc/.pylero
# Generate documentaion
cd doc/
make clean
make html
cd - 1>/dev/null
# Replace all internal references
build_dir="doc/_build/html"
rm -rf doc/_build/doctrees
echo
echo Reference of "'$name'" will be changed to 'POLARION_USERNAME' in below files
grep -riln "$name" $build_dir | tee /dev/tty | xargs sed -i "s|$name|POLARION_USERNAME|gi"
echo
echo Reference of "'$url'" will be changed to 'POLARION_URL' in below files
if grep -riln "$url" $build_dir; then
grep -riln "$url" $build_dir | tee /dev/tty | xargs sed -i "s|$url|POLARION_URL|gi"
fi
echo
echo Reference of "'$project'" will be changed to 'POLARION_PROJECT' in below files
grep -riln "$project" $build_dir | tee /dev/tty | xargs sed -i "s|$project|POLARION_PROJECT|gi"
echo
# Need to have 'docs' folder for serving from github pages
rm -rf docs
shopt -s dotglob; mv -f $build_dir docs
ln -fsvr docs "doc/_build/"
touch docs/.nojekyll
echo "Done! Docs can be served from 'docs' folder"