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