8681190e2453deb257601e60026587a50eefb274
[releng.git] / jjb / opnfvdocs / docu-build.sh
1 #!/bin/bash
2 set -e
3 set -o pipefail
4
5 project="$(git remote -v | head -n1 | awk '{{print $2}}' | sed -e 's,.*:\(.*/\)\?,,' -e 's/\.git$//')"
6 export PATH=$PATH:/usr/local/bin/
7
8 git_sha1="$(git rev-parse HEAD)"
9 docu_build_date="$(date)"
10
11 if [[ $JOB_NAME =~ "verify" ]] ; then
12       subdir="/$GERRIT_CHANGE_NUMBER"
13 else
14       subdir="$GS_PATHNAME"
15 fi
16
17 files=()
18 while read -r -d ''; do
19         files+=("$REPLY")
20 done < <(find * -type f -iname '*.rst' -print0)
21
22 for file in "${{files[@]}}"; do
23
24         file_cut="${{file%.*}}"
25         gs_cp_folder="${{file_cut}}"
26
27         # sed part
28         sed -i "s/_sha1_/$git_sha1/g" $file
29         sed -i "s/_date_/$docu_build_date/g" $file
30
31         # rst2html part
32         echo "rst2html $file"
33         rst2html $file | gsutil cp -L gsoutput.txt - \
34         gs://artifacts.opnfv.org/"$project""$subdir"/"$gs_cp_folder".html
35         gsutil setmeta -h "Content-Type:text/html" \
36                         -h "Cache-Control:private, max-age=0, no-transform" \
37                         gs://artifacts.opnfv.org/"$project""$subdir"/"$gs_cp_folder".html
38         cat gsoutput.txt
39         rm -f gsoutput.txt
40
41         echo "rst2pdf $file"
42         rst2pdf $file -o - | gsutil cp -L gsoutput.txt - \
43         gs://artifacts.opnfv.org/"$project""$subdir"/"$gs_cp_folder".pdf
44         gsutil setmeta -h "Content-Type:application/pdf" \
45                         -h "Cache-Control:private, max-age=0, no-transform" \
46                         gs://artifacts.opnfv.org/"$project""$subdir"/"$gs_cp_folder".pdf
47         cat gsoutput.txt
48         rm -f gsoutput.txt
49
50   links+="http://artifacts.opnfv.org/"$project""$subdir"/"$gs_cp_folder".html \n"
51   links+="http://artifacts.opnfv.org/"$project""$subdir"/"$gs_cp_folder".pdf \n"
52
53 done
54
55 images=()
56 while read -r -d ''; do
57         images+=("$REPLY")
58 done < <(find * -type f \( -iname \*.jpg -o -iname \*.png \) -print0)
59
60 for img in "${{images[@]}}"; do
61
62         # uploading found images
63         echo "uploading $img"
64         cat "$img" | gsutil cp -L gsoutput.txt - \
65         gs://artifacts.opnfv.org/"$project""$subdir"/"$img"
66         gsutil setmeta -h "Content-Type:image/jpeg" \
67                         -h "Cache-Control:private, max-age=0, no-transform" \
68                         gs://artifacts.opnfv.org/"$project""$subdir"/"$img"
69         cat gsoutput.txt
70         rm -f gsoutput.txt
71
72 done
73
74 if [[ $GERRIT_EVENT_TYPE = "change-merged" ]] ; then
75     subdir="/$GERRIT_CHANGE_NUMBER"
76     if [ ! -z "$subdir" ]; then
77       gsutil rm gs://artifacts.opnfv.org/"$project""$subdir"/** || true
78     fi
79 fi
80
81 echo -e "$links"
82