forgot quotes.
[releng.git] / jjb / doctor / docu-build.sh
index d549506..ffb1311 100644 (file)
@@ -2,24 +2,46 @@
 set -e
 set -o pipefail
 
-design_docs_dir="design_docs"
-build_dir="build"
-project="$(git remote -v | head -n1 | awk '{{print $2}}' | sed -e 's,.*:\(.*/\)\?,,' -e 's/\.git$//')"
 export PATH=$PATH:/usr/local/bin/
 
+echo
+echo "Build"
+echo "-----"
+echo
+
 make
 
-# upload all built files
-files=(
-    $build_dir/$design_docs_dir
-    $build_dir/requirements/html
-    $build_dir/requirements/latex/*.pdf
-)
-
-for file in "${{files[@]}}"; do
-    gsutil cp -L gsoutput.txt $file gs://artifacts.opnfv.org/$project/
-    gsutil setmeta -h "Cache-Control:private, max-age=0, no-transform" \
-       gs://artifacts.opnfv.org/$project/$file
-    cat gsoutput.txt
-    rm -f gsoutput.txt
-done
+echo
+echo "Upload"
+echo "------"
+echo
+
+# NOTE: make sure source parameters for GS paths are not empty.
+[[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
+[[ $GERRIT_PROJECT =~ .+ ]]
+[[ $GERRIT_BRANCH =~ .+ ]]
+
+gs_path_review="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
+if [[ $GERRIT_BRANCH = "master" ]] ; then
+    gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT"
+else
+    gs_path_branch="artifacts.opnfv.org/$GERRIT_PROJECT/${{GERRIT_BRANCH##*/}}"
+fi
+
+if [[ $JOB_NAME =~ "verify" ]] ; then
+    gsutil cp -r build/* "gs://$gs_path_review/"
+    echo
+    echo "Document is available at http://$gs_path_review"
+else
+    gsutil cp -r build/design_docs "gs://$gs_path_branch/"
+    gsutil cp -r build/requirements/html "gs://$gs_path_branch/"
+    gsutil cp -r build/requirements/latex/*.pdf "gs://$gs_path_branch/"
+    echo
+    echo "Latest document is available at http://$gs_path_branch"
+
+    if gsutil ls "gs://$gs_path_review" > /dev/null 2>&1 ; then
+        echo
+        echo "Deleting Out-of-dated Documents..."
+        gsutil rm -r "gs://$gs_path_review"
+    fi
+fi