Okay, this should fix the path problems
[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 git_sha1="$(git rev-parse HEAD)"
7
8 clean() {{
9 if [[ -d docs/output ]]; then
10 rm -rf docs/output
11 echo "cleaning up output directory"
12 fi
13 }}
14
15 trap clean EXIT TERM INT SIGTERM SIGHUP
16
17 #set git_sha1
18 files=()
19 while read -r -d ''; do
20   files+=("$REPLY")
21 done < <(find docs/ -type f -iname '*.rst' -print0)
22 for file in "${{files[@]}}"; do
23   sed -i "s/_sha1_/$git_sha1/g" $file
24 done
25
26 directories=()
27 while read -d $'\n'; do
28   directories+=("$REPLY")
29 done < <(find docs/ -name 'index.rst' -printf '%h\n' | sort -u )
30
31 for dir in "${{directories[@]}}"; do
32   echo
33   echo "#############################"
34   echo "Building DOCS in ${{dir##*/}}"
35   echo "#############################"
36   echo
37
38   if [[ ! -d docs/output/"${{dir##*/}}/" ]]; then
39     mkdir -p docs/output/"${{dir##*/}}/"
40   fi
41
42   sphinx-build -b html -E -c docs/etc/ ""$dir"/" docs/output/"${{dir##*/}}/"
43
44 done
45
46 # NOTE: make sure source parameters for GS paths are not empty.
47 [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
48 [[ $GERRIT_PROJECT =~ .+ ]]
49 [[ $GERRIT_BRANCH =~ .+ ]]
50
51 gs_path_review="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
52
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 for dir in "${{directories[@]}}"; do
60   echo
61   echo "#############################"
62   echo "UPLOADING DOCS in ${{dir##*/}}"
63   echo "#############################"
64   echo
65
66
67   if [[ $JOB_NAME =~ "verify" ]] ; then
68
69     #upload artifacts for verify job
70     gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_review/"
71
72     # post link to gerrit as comment
73     gerrit_comment="$(echo '"Document is available at 'http://$gs_path_review/"${{dir##*/}}"/index.html' for review"')"
74     echo "$gerrit_comment"
75     ssh -p 29418 gerrit.opnfv.org gerrit review -p $GERRIT_PROJECT -m \
76     "$gerrit_comment" $GERRIT_PATCHSET_REVISION
77
78     #set cache to 0
79     for x in $(gsutil ls gs://$gs_path_review/"${{dir##*/}}" | grep html);
80     do
81       gsutil setmeta -h "Content-Type:text/html" \
82       -h "Cache-Control:private, max-age=0, no-transform" \
83       "$x"
84     done
85
86   else
87
88     #upload artifacts for merge job
89     gsutil cp -r docs/output/"${{dir##*/}}" "gs://$gs_path_branch/docs/"
90     echo "Latest document is available at http://$gs_path_branch/docs/"${{dir##*/}}"/index.html"
91
92     #set cache to 0
93     for x in $(gsutil ls gs://$gs_path_branch/"${{dir}}" | grep html);
94     do
95       gsutil setmeta -h "Content-Type:text/html" \
96       -h "Cache-Control:private, max-age=0, no-transform" \
97       "$x"
98     done
99
100     #Clean up review when merging
101     if gsutil ls "gs://$gs_path_review" > /dev/null 2>&1 ; then
102       echo
103       echo "Deleting Out-of-dated Documents..."
104       gsutil rm -r "gs://$gs_path_review"
105     fi
106
107   fi
108
109 done