Extend dynamic project variable in docu-build scripts
[releng.git] / jjb / functest / 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 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="${{file_cut}}"
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         echo "rst2html $file"
27         rst2html $file | gsutil cp -L gsoutput.txt - \
28         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder".html
29         gsutil setmeta -h "Content-Type:text/html" \
30                         -h "Cache-Control:private, max-age=0, no-transform" \
31                         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder".html
32         cat gsoutput.txt
33         rm -f gsoutput.txt
34
35         echo "rst2pdf $file"
36         rst2pdf $file -o - | gsutil cp -L gsoutput.txt - \
37         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder".pdf
38         gsutil setmeta -h "Content-Type:application/pdf" \
39                         -h "Cache-Control:private, max-age=0, no-transform" \
40                         gs://artifacts.opnfv.org/"$project"/"$gs_cp_folder".pdf
41         cat gsoutput.txt
42         rm -f gsoutput.txt
43
44 done
45
46 images=()
47 while read -r -d ''; do
48         images+=("$REPLY")
49 done < <(find * -type f \( -iname \*.jpg -o -iname \*.png \) -print0)
50
51 for img in "${{images[@]}}"; do
52
53         # uploading found images
54         echo "uploading $img"
55         cat "$img" | gsutil cp -L gsoutput.txt - \
56         gs://artifacts.opnfv.org/"$project"/"$img"
57         gsutil setmeta -h "Content-Type:image/jpeg" \
58                         -h "Cache-Control:private, max-age=0, no-transform" \
59                         gs://artifacts.opnfv.org/"$project"/"$img"
60         cat gsoutput.txt
61         rm -f gsoutput.txt
62
63 done