3 export PATH=$PATH:/usr/local/bin/
6 SRC_DIR=${SRC_DIR:-docs}
7 INDEX_RST=${INDEX_RST:-index.rst}
8 BUILD_DIR=${BUILD_DIR:-build}
9 OUTPUT_DIR=${OUTPUT_DIR:-output}
10 RELENG_DIR=${RELENG_DIR:-releng}
11 GERRIT_COMMENT=${GERRIT_COMMENT:-}
15 from docutils import core, nodes
18 with open('index.rst', 'r') as file:
20 doctree = core.publish_doctree(data,
21 settings_overrides={'report_level': 5,
23 if isinstance(doctree[0], nodes.title):
26 for c in doctree.children:
27 if isinstance(c, nodes.section):
33 revision="$(git rev-parse --short HEAD)"
34 rev_full="$(git rev-parse HEAD)"
35 version="$(git describe --abbrev=0 2> /dev/null || echo draft) ($revision)"
36 project="$(basename $(git rev-parse --show-toplevel))"
37 html_notes="\n Revision: $rev_full\n\n Build date: |today|"
38 default_conf='releng/docs/etc/conf.py'
39 opnfv_logo='releng/docs/etc/opnfv-logo.png'
41 function add_html_notes() {
45 if grep -q -e ' _sha1_' "$_src"/*.rst ; then
46 # TODO: remove this, once old templates were removed from all repos.
48 echo "Warn: '_sha1_' was found in $_dir , use the latest document template."
49 echo " See https://wiki.opnfv.org/documentation/tools ."
51 sed -i "s/ _sha1_/ $git_sha1/g" "$_src"/*.rst
53 sed -i -e "\$a\\\n.. only:: html\n$html_notes" "$_src"/*.rst
56 function add_config() {
61 if ! grep -q -e "^$_param = " "$_conf" ; then
62 echo "Adding '$_param' into $_conf ..."
63 echo "$_param = $_val" >> "$_conf"
68 if [[ ! -d "$RELENG_DIR" ]] ; then
69 echo "Error: $RELENG_DIR dir not found. See https://wiki.opnfv.org/documentation/tools ."
73 find $SRC_DIR -name $INDEX_RST -printf '%h\n' | while read dir
76 src="$BUILD_DIR/src/$name"
77 build="$BUILD_DIR/$name"
78 output="$OUTPUT_DIR/$name"
82 echo "#################${dir//?/#}"
83 echo "Building DOCS in $dir"
84 echo "#################${dir//?/#}"
87 mkdir -p "$BUILD_DIR/src"
88 [[ -e "$src" ]] && rm -rf "$src"
91 add_html_notes "$src" "$dir"
93 [[ ! -f "$conf" ]] && cp "$default_conf" "$conf"
94 title=$(cd $src; python -c "$get_title_script")
95 latex_conf="[('index', '$name.tex', \"$title\", 'OPNFV', 'manual'),]"
96 add_config "$conf" 'latex_documents' "$latex_conf"
97 add_config "$conf" 'release' "u'$version'"
98 add_config "$conf" 'version' "u'$version'"
99 add_config "$conf" 'project' "u'$project'"
100 add_config "$conf" 'copyright' "u'$(date +%Y), OPNFV'"
101 cp -f $opnfv_logo "$src/opnfv-logo.png"
105 sphinx-build -b html -t html -E "$src" "$output"
107 # Note: PDF creation may fail in project doc builds.
108 # We allow this build job to be marked as succeeded with
109 # failure in PDF creation, but leave message to fix it.
110 # Any failure has to be fixed before OPNFV B release.
112 sphinx-build -b latex -t pdf -E "$src" "$build" && \
113 make -C "$build" LATEXOPTS='--interaction=nonstopmode' all-pdf
115 mv "$build/$name.pdf" "$output"
117 msg="Error: PDF creation for $dir has failed, please fix source rst file(s)."
121 [[ -n "$GERRIT_COMMENT" ]] && echo "$msg" >> "$GERRIT_COMMENT"