jjb: fix dirs to upload gs in doc builder jobs
[releng.git] / jjb / releng-macros.yaml
1 # OLD Releng macros
2
3 - parameter:
4     name: project-parameter
5     parameters:
6         - string:
7             name: PROJECT
8             default: '{project}'
9             description: "JJB configured PROJECT parameter to identify an opnfv Gerrit project"
10
11 - parameter:
12     name: gerrit-parameter
13     parameters:
14         - string:
15             name: GERRIT_BRANCH
16             default: '{branch}'
17             description: "JJB configured GERRIT_BRANCH parameter"
18
19 - scm:
20     name: git-scm
21     scm:
22         - git:
23             credentials-id: '{credentials-id}'
24             url: '$GIT_BASE'
25             refspec: ''
26             branches:
27                 - 'origin/{branch}'
28             skip-tag: true
29             wipe-workspace: true
30
31 - scm:
32     name: gerrit-trigger-scm
33     scm:
34         - git:
35             credentials-id: '{credentials-id}'
36             url: '$GIT_BASE'
37             refspec: '{refspec}'
38             branches:
39                 - 'origin/$GERRIT_BRANCH'
40             skip-tag: true
41             choosing-strategy: '{choosing-strategy}'
42
43 - wrapper:
44     name: build-timeout
45     wrappers:
46         - timeout:
47             type: absolute
48             timeout: 360
49             fail: true
50
51 - trigger:
52     name: gerrit-trigger-patch-submitted
53     triggers:
54         - gerrit:
55             server-name: 'gerrit.opnfv.org'
56             trigger-on:
57                 - patchset-created-event:
58                     exclude-drafts: 'false'
59                     exclude-trivial-rebase: 'false'
60                     exclude-no-code-change: 'false'
61                 - draft-published-event
62                 - comment-added-contains-event:
63                     comment-contains-value: 'recheck'
64             projects:
65               - project-compare-type: 'ANT'
66                 project-pattern: '{name}'
67                 branches:
68                   - branch-compare-type: 'ANT'
69                     branch-pattern: '**/{branch}'
70
71 - trigger:
72     name: gerrit-trigger-patch-merged
73     triggers:
74         - gerrit:
75             server-name: 'gerrit.opnfv.org'
76             trigger-on:
77                 - change-merged-event
78                 - comment-added-contains-event:
79                     comment-contains-value: 'remerge'
80             projects:
81               - project-compare-type: 'ANT'
82                 project-pattern: '{name}'
83                 branches:
84                   - branch-compare-type: 'ANT'
85                     branch-pattern: '**/{branch}'
86
87 - publisher:
88     name: archive-artifacts
89     publishers:
90         - archive:
91             artifacts: '{artifacts}'
92             allow-empty: true
93             fingerprint: true
94             latest-only: true
95
96 - publisher:
97     name: email-notification
98     publishers:
99         - email-ext:
100             recipients: 'jenkins@lists.opnfv.org'
101             reply-to:
102             content-type: default
103             subject: '{email-prefix} $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!'
104             body: |
105                 $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
106
107                 Check console output at $BUILD_URL to view the results.
108             unstable: true
109             fixed: true
110             send-to:
111                 - developers
112                 - recipients
113
114 - publisher:
115         name: jacoco-report
116         publishers:
117             - jacoco:
118                 exec-pattern: "**/**.exec"
119                 class-pattern: "**/classes"
120                 source-pattern: "**/src/main/java"
121                 exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**"
122                 status-update: true
123                 targets:
124                   - branch:
125                       healthy: 10
126                       unhealthy: 20
127                   - method:
128                       healthy: 50
129                       unhealthy: 40
130
131
132 - builder:
133     name: test-macro
134     builders:
135         - shell: 'echo testing macro "test-macro"'
136
137 - builder:
138     name: wipe-org-opendaylight-repo
139     builders:
140         - shell: 'if [ -d /tmp/r/org/opendaylight ]; then rm -rf /tmp/r/org/opendaylight; fi'
141
142 - builder:
143     name: jacoco-nojava-workaround
144     builders:
145         - shell: 'mkdir -p $WORKSPACE/target/classes'
146
147
148 # New Releng macros
149
150 - builder:
151     name: build-html-and-pdf-docs-output
152     builders:
153         - shell: |
154             #!/bin/bash -e
155             set -o pipefail
156             export PATH=$PATH:/usr/local/bin/
157
158             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
159
160             _get_title_script="
161             import os
162             from docutils import core
163             with open('index.rst', 'r') as file:
164                 data = file.read()
165                 doctree = core.publish_doctree(data,
166                     settings_overrides={'report_level': 5,
167                                         'halt_level': 5})
168                 print doctree[0].astext()"
169             _git_sha1="$(git rev-parse HEAD)"
170
171             find docs/ -name 'index.rst' -printf '%h\n' | while read dir
172             do
173                 _name="${dir##*/}"
174                 _build="$dir/build"
175                 _output="docs/output/$_name"
176
177                 echo
178                 echo "#################${dir//?/#}"
179                 echo "Building DOCS in $dir"
180                 echo "#################${dir//?/#}"
181                 echo
182
183                 sed -i "s/_sha1_/$_git_sha1/g" "$dir/index.rst"
184
185                 if [[ ! -f "$dir/conf.py" ]] ; then
186                     cp "docs/etc/conf.py" "$dir/conf.py"
187                     _title=$(cd $dir; python -c "$_get_title_script")
188                     echo "latex_documents = [('index', '$_name.tex', '$_title', 'OPNFV', 'manual'),]" >> "$dir/conf.py"
189                 fi
190                 cp -f "docs/etc/opnfv-logo.png" "$dir/opnfv-logo.png"
191
192                 mkdir -p "$_output"
193
194                 sphinx-build -b html -E "$dir" "$_output"
195
196                 # Note: PDF creation may fail in project doc builds.
197                 #       We allow this test to be marked as succeeded with
198                 #       failure in PDF creation, but leave message to fix it.
199                 #       Any failure has to be fixed before B release.
200                 {
201                     sphinx-build -b latex -E "$dir" "$_build"
202                     make -C "$_build" LATEXOPTS='--interaction=nonstopmode' all-pdf
203                     mv "$_build/$_name.pdf" "$_output"
204                 } || {
205                     _msg="Error: PDF creation for $dir has failed, please fix source rst file(s)."
206                     echo
207                     echo "$_msg"
208                     echo
209                     echo "$_msg" >> gerrit_comment.txt
210                 }
211             done
212
213 - builder:
214     name: upload-under-review-docs-to-opnfv-artifacts
215     builders:
216         - shell: |
217             #!/bin/bash -e
218             set -o pipefail
219             export PATH=$PATH:/usr/local/bin/
220
221             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
222             [[ -d docs/output ]]
223
224             echo
225             echo "###########################"
226             echo "UPLOADING DOCS UNDER REVIEW"
227             echo "###########################"
228             echo
229
230             gs_base="artifacts.opnfv.org/review"
231             gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
232             local_path="docs/$GERRIT_CHANGE_NUMBER"
233
234             mv docs/output "$local_path"
235             gsutil -m cp -r "$local_path" "gs://$gs_base"
236
237             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
238                 gsutil -m setmeta \
239                     -h "Content-Type:text/html" \
240                     -h "Cache-Control:private, max-age=0, no-transform" \
241                     "gs://$gs_path"/**.html
242             fi
243
244             echo "Document link(s):" >> gerrit_comment.txt
245             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
246                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
247
248 - builder:
249     name: upload-merged-docs-to-opnfv-artifacts
250     builders:
251         - shell: |
252             #!/bin/bash -e
253             set -o pipefail
254             export PATH=$PATH:/usr/local/bin/
255
256             [[ -d docs/output ]]
257
258             echo
259             echo "#####################"
260             echo "UPLOADING MERGED DOCS"
261             echo "#####################"
262             echo
263
264             if [[ "$GERRIT_BRANCH" == "master" ]] ; then
265                 gs_base="artifacts.opnfv.org/$GERRIT_PROJECT"
266             else
267                 gs_base="artifacts.opnfv.org/$GERRIT_PROJECT/$GERRIT_BRANCH"
268             fi
269             gs_path="$gs_base/docs"
270             local_path="docs/docs"
271
272             mv docs/output "$local_path"
273             gsutil -m cp -r "$local_path" "gs://$gs_base"
274
275             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
276                 gsutil -m setmeta \
277                     -h "Content-Type:text/html" \
278                     -h "Cache-Control:private, max-age=0, no-transform" \
279                     "gs://$gs_path"/**.html
280             fi
281
282             echo "Document link(s):" >> gerrit_comment.txt
283             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
284                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
285
286 - builder:
287     name: report-docs-build-result-to-gerrit
288     builders:
289         - shell: |
290             #!/bin/bash -e
291             export PATH=$PATH:/usr/local/bin/
292             if [[ -e gerrit_comment.txt ]] ; then
293                 echo
294                 echo "posting review comment to gerrit..."
295                 echo
296                 cat gerrit_comment.txt
297                 echo
298                 ssh -p 29418 gerrit.opnfv.org \
299                     "gerrit review -p $GERRIT_PROJECT \
300                      -m '$(cat gerrit_comment.txt)' \
301                      $GERRIT_PATCHSET_REVISION"
302             fi
303
304 - builder:
305     name: remove-old-docs-from-opnfv-artifacts
306     builders:
307         - shell: |
308             #!/bin/bash -e
309             export PATH=$PATH:/usr/local/bin/
310
311             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
312
313             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
314
315             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
316                 echo
317                 echo "Deleting Out-of-dated Documents..."
318                 gsutil -m rm -r "gs://$gs_path"
319             fi
320
321 - builder:
322     name: upload-review-docs
323     builders:
324         - build-html-and-pdf-docs-output
325         - upload-under-review-docs-to-opnfv-artifacts
326         - report-docs-build-result-to-gerrit
327
328 - builder:
329     name: upload-merged-docs
330     builders:
331         - build-html-and-pdf-docs-output
332         - upload-merged-docs-to-opnfv-artifacts
333         - report-docs-build-result-to-gerrit
334         - remove-old-docs-from-opnfv-artifacts