My done was in the wrong place
[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
40 directories=()
41 while read -d $'\n'; do
42           directories+=("$REPLY")
43         done < <(find docs/ -name 'index.rst' -printf '%h\n' | sort -u )
44
45         for dir in "${{directories[@]}}"; do
46           echo
47           echo "#############################"
48           echo "UPLOADING DOCS in ${{dir##*/}}"
49           echo "#############################"
50           echo
51
52           gs_path_review="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
53           if [[ $GERRIT_BRANCH = "master" ]] ; then
54               gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT"
55           else
56               gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT/${{GERRIT_BRANCH##*/}}"
57           fi
58
59           if [[ $JOB_NAME =~ "verify" ]] ; then
60               gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_review/"
61               # post link to gerrit as comment
62               gerrit_comment="$(echo '"Document is available at 'http://$gs_path_review/"${{dir##*/}}"/index.html' for review"')"
63               echo "$gerrit_comment"
64               ssh -p 29418 gerrit.opnfv.org gerrit review -p $GERRIT_PROJECT -m \
65               "$gerrit_comment" $GERRIT_PATCHSET_REVISION
66           else
67               gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_branch/"
68
69               echo "Latest document is available at http://$gs_path_branch/index.html"
70
71               if gsutil ls "gs://$gs_path_review" > /dev/null 2>&1 ; then
72                   echo
73                   echo "Deleting Out-of-dated Documents..."
74                   gsutil rm -r "gs://$gs_path_review"
75               fi
76           fi
77
78
79 done