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##*/}}/"
46 # NOTE: make sure source parameters for GS paths are not empty.
47 [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
48 [[ $GERRIT_PROJECT =~ .+ ]]
49 [[ $GERRIT_BRANCH =~ .+ ]]
51 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"
56 gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT/${{GERRIT_BRANCH##*/}}"
59 for dir in "${{directories[@]}}"; do
61 echo "#############################"
62 echo "UPLOADING DOCS in ${{dir##*/}}"
63 echo "#############################"
67 if [[ $JOB_NAME =~ "verify" ]] ; then
69 #upload artifacts for verify job
70 gsutil cp -r docs/output/"${{dir##*/}}/" "gs://$gs_path_review/"
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
79 for x in $(gsutil ls gs://$gs_path_review/"${{dir##*/}}" | grep html);
81 gsutil setmeta -h "Content-Type:text/html" \
82 -h "Cache-Control:private, max-age=0, no-transform" \
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"
93 for x in $(gsutil ls gs://$gs_path_branch/"${{dir}}" | grep html);
95 gsutil setmeta -h "Content-Type:text/html" \
96 -h "Cache-Control:private, max-age=0, no-transform" \
100 #Clean up review when merging
101 if gsutil ls "gs://$gs_path_review" > /dev/null 2>&1 ; then
103 echo "Deleting Out-of-dated Documents..."
104 gsutil rm -r "gs://$gs_path_review"