5 export PATH=$PATH:/usr/local/bin/
6 git_sha1="$(git rev-parse HEAD)"
9 if [[ -d docs/output ]]; then
11 echo "cleaning up output directory"
15 trap clean EXIT TERM INT SIGTERM SIGHUP
19 while read -r -d ''; do
21 done < <(find docs/ -type f -iname '*.rst' -print0)
22 for file in "${{files[@]}}"; do
23 sed -i "s/_sha1_/$git_sha1/g" $file
27 while read -d $'\n'; do
28 directories+=("$REPLY")
29 done < <(find docs/ -name 'index.rst' -printf '%h\n' | sort -u )
31 for dir in "${{directories[@]}}"; do
33 echo "#############################"
34 echo "Building DOCS in ${{dir##*/}}"
35 echo "#############################"
38 if [[ ! -d docs/output/"${{dir##*/}}/" ]]; then
39 mkdir -p docs/output/"${{dir##*/}}/"
42 sphinx-build -b html -E -c docs/etc/ ""$dir"/" docs/output/"${{dir##*/}}/"
45 # NOTE: make sure source parameters for GS paths are not empty.
46 [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
47 [[ $GERRIT_PROJECT =~ .+ ]]
48 [[ $GERRIT_BRANCH =~ .+ ]]
49 gs_path_review="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
51 for dir in "${{directories[@]}}"; do
53 echo "#############################"
54 echo "UPLOADING DOCS in ${{dir##*/}}"
55 echo "#############################"
58 if [[ $GERRIT_BRANCH = "master" ]] ; then
59 gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT"
61 gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT/${{GERRIT_BRANCH##*/}}"
64 if [[ $JOB_NAME =~ "verify" ]] ; then
66 #upload artifacts for verify job
67 gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_review/"
69 # post link to gerrit as comment
70 gerrit_comment="$(echo '"Document is available at 'http://$gs_path_review/"${{dir##*/}}"/index.html' for review"')"
71 echo "$gerrit_comment"
72 ssh -p 29418 gerrit.opnfv.org gerrit review -p $GERRIT_PROJECT -m \
73 "$gerrit_comment" $GERRIT_PATCHSET_REVISION
76 for x in $(gsutil ls gs://$gs_path_review/"${{dir##*/}}" | grep html);
78 gsutil setmeta -h "Content-Type:text/html" \
79 -h "Cache-Control:private, max-age=0, no-transform" \
85 #upload artifacts for merge job
86 gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_branch/"
87 echo "Latest document is available at http://$gs_path_branch/index.html"
90 for x in $(gsutil ls gs://$gs_path_branch/"${{dir}}" | grep html);
92 gsutil setmeta -h "Content-Type:text/html" \
93 -h "Cache-Control:private, max-age=0, no-transform" \
97 #Clean up review when merging
98 if gsutil ls "gs://$gs_path_review" > /dev/null 2>&1 ; then
100 echo "Deleting Out-of-dated Documents..."
101 gsutil rm -r "gs://$gs_path_review"