Fail on exit status != 0 on every command in pipeline for build-docu scripts
[releng.git] / jjb / genesis / build-upload-docu.sh
1 #!/bin/bash
2 set -e
3 set -o pipefail
4
5 project="genesis"
6 export PATH=$PATH:/usr/local/bin/
7
8 git_sha1="$(git rev-parse HEAD)"
9 docu_build_date="$(date)"
10
11 files=()
12 while read -r -d ''; do
13         files+=("$REPLY")
14 done < <(find . -type f -iname '*.rst' -print0)
15
16 for file in "${{files[@]}}"; do
17
18         file_cut="${{file%.*}}"
19         gs_cp_folder="$(echo "$file"| cut -d "/" -f2,3)"
20
21         # sed part
22         sed -i "s/_sha1_/$git_sha1/g" $file
23         sed -i "s/_date_/$docu_build_date/g" $file
24
25         # rst2html part
26         html_file=$file_cut".html"
27         echo "rst2html $file"
28         rst2html $file | gsutil cp -L gsoutput.txt - \
29         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder"/$(basename "$html_file")
30         gsutil setmeta -h "Content-Type:text/html" \
31                         -h "Cache-Control:private, max-age=0, no-transform" \
32                         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder"/$(basename "$html_file")
33         cat gsoutput.txt
34         rm -f gsoutput.txt
35
36         # rst2pdf part
37         pdf_file="$file_cut"".pdf"
38         echo "rst2pdf $file"
39         rst2pdf "$file" -o - | gsutil cp -L gsoutput.txt - \
40         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder"/$(basename "$pdf_file")
41         gsutil setmeta -h "Content-Type:application/pdf" \
42                         -h "Cache-Control:private, max-age=0, no-transform" \
43                         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder"/$(basename "$pdf_file")
44         cat gsoutput.txt
45         rm -f gsoutput.txt
46
47 done
48
49 images=()
50 while read -r -d ''; do
51         images+=("$REPLY")
52 done < <(find * -type f \( -iname \*.jpg -o -iname \*.png \) -print0)
53
54 for img in "${{images[@]}}"; do
55
56         # uploading found images
57         echo "uploading $img"
58         cat "$img" | gsutil cp -L gsoutput.txt - \
59         gs://artifacts.opnfv.org/"$project"/"$img"
60         gsutil setmeta -h "Content-Type:image/jpeg" \
61                         -h "Cache-Control:private, max-age=0, no-transform" \
62                         gs://artifacts.opnfv.org/"$project"/"$img"
63         cat gsoutput.txt
64         rm -f gsoutput.txt
65
66 done
67