Fix all the ugly formatting that I left in due to end of day fatigue.
[releng.git] / jjb / releng / docu-build-new.sh
1 #!/bin/bash
2 set -e
3 set -o pipefail
4
5 export PATH=$PATH:/usr/local/bin/
6
7 clean() {{
8 if [[ -d docs/output ]]; then
9 rm -rf docs/output
10 echo "cleaning up output directory"
11 fi
12 }}
13
14 trap clean EXIT TERM INT SIGTERM SIGHUP
15
16 directories=()
17 while read -d $'\n'; do
18   directories+=("$REPLY")
19 done < <(find docs/ -name 'index.rst' -printf '%h\n' | sort -u )
20
21 for dir in "${{directories[@]}}"; do
22   echo
23   echo "#############################"
24   echo "Building DOCS in ${{dir##*/}}"
25   echo "#############################"
26   echo
27
28   if [[ ! -d docs/output/"${{dir##*/}}/" ]]; then
29     mkdir -p docs/output/"${{dir##*/}}/"
30   fi
31
32   sphinx-build -b html -E -c docs/etc/ ""$dir"/" docs/output/"${{dir##*/}}/"
33 done
34
35 # NOTE: make sure source parameters for GS paths are not empty.
36 [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
37 [[ $GERRIT_PROJECT =~ .+ ]]
38 [[ $GERRIT_BRANCH =~ .+ ]]
39 gs_path_review="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
40
41 for dir in "${{directories[@]}}"; do
42   echo
43   echo "#############################"
44   echo "UPLOADING DOCS in ${{dir##*/}}"
45   echo "#############################"
46   echo
47
48   if [[ $GERRIT_BRANCH = "master" ]] ; then
49     gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT"
50   else
51     gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT/${{GERRIT_BRANCH##*/}}"
52   fi
53
54   if [[ $JOB_NAME =~ "verify" ]] ; then
55     gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_review/"
56     # post link to gerrit as comment
57     gerrit_comment="$(echo '"Document is available at 'http://$gs_path_review/"${{dir##*/}}"/index.html' for review"')"
58     echo "$gerrit_comment"
59     ssh -p 29418 gerrit.opnfv.org gerrit review -p $GERRIT_PROJECT -m \
60     "$gerrit_comment" $GERRIT_PATCHSET_REVISION
61
62   else
63
64     gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_branch/"
65     echo "Latest document is available at http://$gs_path_branch/index.html"
66
67     #Clean up review when merging
68     if gsutil ls "gs://$gs_path_review" > /dev/null 2>&1 ; then
69       echo
70       echo "Deleting Out-of-dated Documents..."
71       gsutil rm -r "gs://$gs_path_review"
72     fi
73
74   fi
75
76 done