edadc2fb123a367edda893e1025bfcc26319b4e8
[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 [[ $GERRIT_EVENT_TYPE = "patchset-created" ]] ; then
12     patchset="/$GERRIT_CHANGE_NUMBER"
13 fi
14
15
16 files=()
17 while read -r -d ''; do
18         files+=("$REPLY")
19 done < <(find * -type f -iname '*.rst' -print0)
20
21 for file in "${{files[@]}}"; do
22
23         file_cut="${{file%.*}}"
24         gs_cp_folder="${{file_cut}}"
25
26         # sed part
27         sed -i "s/_sha1_/$git_sha1/g" $file
28         sed -i "s/_date_/$docu_build_date/g" $file
29
30         # rst2html part
31         echo "rst2html $file"
32         rst2html $file | gsutil cp -L gsoutput.txt - \
33         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder".html
34         gsutil setmeta -h "Content-Type:text/html" \
35                         -h "Cache-Control:private, max-age=0, no-transform" \
36                         gs://artifacts.opnfv.org/"$project""$patchset"/"$gs_cp_folder".html
37         cat gsoutput.txt
38         rm -f gsoutput.txt
39
40         echo "rst2pdf $file"
41         rst2pdf $file -o - | gsutil cp -L gsoutput.txt - \
42         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder".pdf
43         gsutil setmeta -h "Content-Type:application/pdf" \
44                         -h "Cache-Control:private, max-age=0, no-transform" \
45                         gs://artifacts.opnfv.org/"$project""$patchset"/"$gs_cp_folder".pdf
46         cat gsoutput.txt
47         rm -f gsoutput.txt
48
49   links+="http://artifacts.opnfv.org/"$project""$patchset"/"$gs_cp_folder".html \n"
50   links+="http://artifacts.opnfv.org/"$project""$patchset"/"$gs_cp_folder".pdf \n"
51
52 done
53
54 images=()
55 while read -r -d ''; do
56         images+=("$REPLY")
57 done < <(find * -type f \( -iname \*.jpg -o -iname \*.png \) -print0)
58
59 for img in "${{images[@]}}"; do
60
61         # uploading found images
62         echo "uploading $img"
63         cat "$img" | gsutil cp -L gsoutput.txt - \
64         gs://artifacts.opnfv.org/"$project"/"$img"
65         gsutil setmeta -h "Content-Type:image/jpeg" \
66                         -h "Cache-Control:private, max-age=0, no-transform" \
67                         gs://artifacts.opnfv.org/"$project"/"$img"
68         cat gsoutput.txt
69         rm -f gsoutput.txt
70
71 done
72
73 echo -e "$links"