jjb: make doc builder to use conf and logo in releng repo
[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             git clone ssh://gerrit.opnfv.org:29418/releng
172             [[ -d releng ]]
173
174             find docs/ -name 'index.rst' -printf '%h\n' | while read dir
175             do
176                 _name="${dir##*/}"
177                 _build="$dir/build"
178                 _output="docs/output/$_name"
179
180                 echo
181                 echo "#################${dir//?/#}"
182                 echo "Building DOCS in $dir"
183                 echo "#################${dir//?/#}"
184                 echo
185
186                 sed -i "s/_sha1_/$_git_sha1/g" "$dir/index.rst"
187
188                 if [[ ! -f "$dir/conf.py" ]] ; then
189                     cp releng/docs/etc/conf.py "$dir/conf.py"
190                     _title=$(cd $dir; python -c "$_get_title_script")
191                     echo "latex_documents = [('index', '$_name.tex', '$_title', 'OPNFV', 'manual'),]" >> "$dir/conf.py"
192                 fi
193                 cp -f releng/docs/etc/opnfv-logo.png "$dir/opnfv-logo.png"
194
195                 mkdir -p "$_output"
196
197                 sphinx-build -b html -E "$dir" "$_output"
198
199                 # Note: PDF creation may fail in project doc builds.
200                 #       We allow this test to be marked as succeeded with
201                 #       failure in PDF creation, but leave message to fix it.
202                 #       Any failure has to be fixed before B release.
203                 {
204                     sphinx-build -b latex -E "$dir" "$_build"
205                     make -C "$_build" LATEXOPTS='--interaction=nonstopmode' all-pdf
206                     mv "$_build/$_name.pdf" "$_output"
207                 } || {
208                     _msg="Error: PDF creation for $dir has failed, please fix source rst file(s)."
209                     echo
210                     echo "$_msg"
211                     echo
212                     echo "$_msg" >> gerrit_comment.txt
213                 }
214             done
215
216 - builder:
217     name: upload-under-review-docs-to-opnfv-artifacts
218     builders:
219         - shell: |
220             #!/bin/bash -e
221             set -o pipefail
222             export PATH=$PATH:/usr/local/bin/
223
224             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
225             [[ -d docs/output ]]
226
227             echo
228             echo "###########################"
229             echo "UPLOADING DOCS UNDER REVIEW"
230             echo "###########################"
231             echo
232
233             gs_base="artifacts.opnfv.org/review"
234             gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
235             local_path="docs/$GERRIT_CHANGE_NUMBER"
236
237             mv docs/output "$local_path"
238             gsutil -m cp -r "$local_path" "gs://$gs_base"
239
240             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
241                 gsutil -m setmeta \
242                     -h "Content-Type:text/html" \
243                     -h "Cache-Control:private, max-age=0, no-transform" \
244                     "gs://$gs_path"/**.html
245             fi
246
247             echo "Document link(s):" >> gerrit_comment.txt
248             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
249                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
250
251 - builder:
252     name: upload-merged-docs-to-opnfv-artifacts
253     builders:
254         - shell: |
255             #!/bin/bash -e
256             set -o pipefail
257             export PATH=$PATH:/usr/local/bin/
258
259             [[ -d docs/output ]]
260
261             echo
262             echo "#####################"
263             echo "UPLOADING MERGED DOCS"
264             echo "#####################"
265             echo
266
267             if [[ "$GERRIT_BRANCH" == "master" ]] ; then
268                 gs_base="artifacts.opnfv.org/$GERRIT_PROJECT"
269             else
270                 gs_base="artifacts.opnfv.org/$GERRIT_PROJECT/$GERRIT_BRANCH"
271             fi
272             gs_path="$gs_base/docs"
273             local_path="docs/docs"
274
275             mv docs/output "$local_path"
276             gsutil -m cp -r "$local_path" "gs://$gs_base"
277
278             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
279                 gsutil -m setmeta \
280                     -h "Content-Type:text/html" \
281                     -h "Cache-Control:private, max-age=0, no-transform" \
282                     "gs://$gs_path"/**.html
283             fi
284
285             echo "Document link(s):" >> gerrit_comment.txt
286             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
287                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
288
289 - builder:
290     name: report-docs-build-result-to-gerrit
291     builders:
292         - shell: |
293             #!/bin/bash -e
294             export PATH=$PATH:/usr/local/bin/
295             if [[ -e gerrit_comment.txt ]] ; then
296                 echo
297                 echo "posting review comment to gerrit..."
298                 echo
299                 cat gerrit_comment.txt
300                 echo
301                 ssh -p 29418 gerrit.opnfv.org \
302                     "gerrit review -p $GERRIT_PROJECT \
303                      -m '$(cat gerrit_comment.txt)' \
304                      $GERRIT_PATCHSET_REVISION"
305             fi
306
307 - builder:
308     name: remove-old-docs-from-opnfv-artifacts
309     builders:
310         - shell: |
311             #!/bin/bash -e
312             export PATH=$PATH:/usr/local/bin/
313
314             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
315
316             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
317
318             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
319                 echo
320                 echo "Deleting Out-of-dated Documents..."
321                 gsutil -m rm -r "gs://$gs_path"
322             fi
323
324 - builder:
325     name: upload-review-docs
326     builders:
327         - build-html-and-pdf-docs-output
328         - upload-under-review-docs-to-opnfv-artifacts
329         - report-docs-build-result-to-gerrit
330
331 - builder:
332     name: upload-merged-docs
333     builders:
334         - build-html-and-pdf-docs-output
335         - upload-merged-docs-to-opnfv-artifacts
336         - report-docs-build-result-to-gerrit
337         - remove-old-docs-from-opnfv-artifacts