3afd355e6087ff085590809776fe6ddef7614501
[releng.git] / jjb / global / releng-macros.yml
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         - string:
11             name: GS_BASE
12             default: artifacts.opnfv.org/$PROJECT
13             description: "URL to Google Storage."
14         - string:
15             name: GS_BASE_PROXY
16             default: build.opnfv.org/artifacts.opnfv.org/$PROJECT
17             description: "URL to Google Storage proxy"
18
19 - parameter:
20     name: gerrit-parameter
21     parameters:
22         - string:
23             name: GERRIT_BRANCH
24             default: '{branch}'
25             description: "JJB configured GERRIT_BRANCH parameter"
26
27 - scm:
28     name: git-scm
29     scm:
30         - git:
31             credentials-id: '{credentials-id}'
32             url: '$GIT_BASE'
33             refspec: ''
34             branches:
35                 - 'origin/{branch}'
36             skip-tag: true
37             wipe-workspace: true
38
39 - scm:
40     name: gerrit-trigger-scm
41     scm:
42         - git:
43             credentials-id: '{credentials-id}'
44             url: '$GIT_BASE'
45             refspec: '{refspec}'
46             branches:
47                 - 'origin/$GERRIT_BRANCH'
48             skip-tag: true
49             choosing-strategy: '{choosing-strategy}'
50             timeout: 15
51
52 - trigger:
53     name: 'daily-trigger-disabled'
54     triggers:
55         - timed: ''
56
57 - trigger:
58     name: 'weekly-trigger-disabled'
59     triggers:
60         - timed: ''
61
62 - trigger:
63     name: gerrit-trigger-patch-submitted
64     triggers:
65         - gerrit:
66             server-name: 'gerrit.opnfv.org'
67             trigger-on:
68                 - patchset-created-event:
69                     exclude-drafts: 'false'
70                     exclude-trivial-rebase: 'false'
71                     exclude-no-code-change: 'false'
72                 - draft-published-event
73                 - comment-added-contains-event:
74                     comment-contains-value: 'recheck'
75             projects:
76               - project-compare-type: 'ANT'
77                 project-pattern: '{name}'
78                 branches:
79                   - branch-compare-type: 'ANT'
80                     branch-pattern: '**/{branch}'
81
82 - trigger:
83     name: gerrit-trigger-patch-merged
84     triggers:
85         - gerrit:
86             server-name: 'gerrit.opnfv.org'
87             trigger-on:
88                 - change-merged-event
89                 - comment-added-contains-event:
90                     comment-contains-value: 'remerge'
91             projects:
92               - project-compare-type: 'ANT'
93                 project-pattern: '{name}'
94                 branches:
95                   - branch-compare-type: 'ANT'
96                     branch-pattern: '**/{branch}'
97
98 - publisher:
99     name: archive-artifacts
100     publishers:
101         - archive:
102             artifacts: '{artifacts}'
103             allow-empty: true
104             fingerprint: true
105             latest-only: true
106
107 # New Releng macros
108
109 - builder:
110     name: build-html-and-pdf-docs-output
111     builders:
112         - shell: |
113             #!/bin/bash
114             set -o errexit
115             set -o xtrace
116             export PATH=$PATH:/usr/local/bin/
117             git clone ssh://gerrit.opnfv.org:29418/opnfvdocs docs_build/_opnfvdocs
118             GERRIT_COMMENT=gerrit_comment.txt ./docs_build/_opnfvdocs/scripts/docs-build.sh
119
120 - builder:
121     name: upload-under-review-docs-to-opnfv-artifacts
122     builders:
123         - shell: |
124             #!/bin/bash
125             set -o errexit
126             set -o pipefail
127             set -o xtrace
128             export PATH=$PATH:/usr/local/bin/
129
130             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
131             [[ -d docs_output ]] || exit 0
132
133             echo
134             echo "###########################"
135             echo "UPLOADING DOCS UNDER REVIEW"
136             echo "###########################"
137             echo
138
139             gs_base="artifacts.opnfv.org/$PROJECT/review"
140             gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
141             local_path="upload/$GERRIT_CHANGE_NUMBER"
142
143             mkdir -p upload
144             mv docs_output "$local_path"
145             gsutil -m cp -r "$local_path" "gs://$gs_base"
146
147             gsutil -m setmeta \
148                 -h "Content-Type:text/html" \
149                 -h "Cache-Control:private, max-age=0, no-transform" \
150                 "gs://$gs_path"/**.html > /dev/null 2>&1
151
152             echo "Document link(s):" >> gerrit_comment.txt
153             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
154                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
155
156 - builder:
157     name: upload-generated-docs-to-opnfv-artifacts
158     builders:
159         - shell: |
160             #!/bin/bash
161             set -o errexit
162             set -o pipefail
163             set -o xtrace
164             export PATH=$PATH:/usr/local/bin/
165
166             [[ -d docs_output ]] || exit 0
167
168             echo
169             echo "########################"
170             echo "UPLOADING GENERATED DOCS"
171             echo "########################"
172             echo
173
174             echo "gs_path="$GS_URL/docs""
175             echo "local_path="upload/docs""
176
177             gs_path="$GS_URL/docs"
178             local_path="upload/docs"
179
180             mkdir -p upload
181             mv docs_output "$local_path"
182             ls "$local_path"
183
184             echo "gsutil -m cp -r "$local_path"/* "gs://$gs_path""
185             gsutil -m cp -r "$local_path"/* "gs://$gs_path"
186
187             gsutil -m setmeta \
188                 -h "Content-Type:text/html" \
189                 -h "Cache-Control:private, max-age=0, no-transform" \
190                 "gs://$gs_path"/**.html > /dev/null 2>&1
191
192             echo "Document link(s):" >> gerrit_comment.txt
193             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
194                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
195
196 - builder:
197     name: report-docs-build-result-to-gerrit
198     builders:
199         - shell: |
200             #!/bin/bash
201             set -o errexit
202             set -o pipefail
203             set -o xtrace
204             export PATH=$PATH:/usr/local/bin/
205             if [[ -e gerrit_comment.txt ]] ; then
206                 echo
207                 echo "posting review comment to gerrit..."
208                 echo
209                 cat gerrit_comment.txt
210                 echo
211                 ssh -p 29418 gerrit.opnfv.org \
212                     "gerrit review -p $GERRIT_PROJECT \
213                      -m '$(cat gerrit_comment.txt)' \
214                      $GERRIT_PATCHSET_REVISION \
215                      --notify NONE"
216             fi
217
218 - builder:
219     name: remove-old-docs-from-opnfv-artifacts
220     builders:
221         - shell: |
222             #!/bin/bash
223             set -o errexit
224             set -o pipefail
225             set -o xtrace
226             export PATH=$PATH:/usr/local/bin/
227
228             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
229
230             gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
231
232             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
233                 echo
234                 echo "Deleting Out-of-dated Documents..."
235                 gsutil -m rm -r "gs://$gs_path"
236             fi
237             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
238
239             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
240                 echo
241                 echo "Deleting Out-of-dated Documents..."
242                 gsutil -m rm -r "gs://$gs_path"
243             fi
244
245 - builder:
246     name: build-and-upload-artifacts-json-api
247     builders:
248         - shell: |
249             #!/bin/bash
250             set -o errexit
251             set -o pipefail
252             export PATH=$PATH:/usr/local/bin/
253
254             virtualenv -p python2.7 $WORKSPACE/releng_artifacts
255             source $WORKSPACE/releng_artifacts/bin/activate
256
257             # install python packages
258             pip install google-api-python-client
259
260             # generate and upload index file
261             echo "Generating Artifacts API ..."
262             python $WORKSPACE/utils/opnfv-artifacts.py > index.json
263             gsutil cp index.json gs://artifacts.opnfv.org/index.json
264
265             deactivate
266
267 - builder:
268     name: lint-python-code
269     builders:
270         - shell: |
271             #!/bin/bash
272             set -o errexit
273             set -o pipefail
274             set -o xtrace
275             export PATH=$PATH:/usr/local/bin/
276
277             virtualenv -p python2.7 $WORKSPACE/releng_flake8
278             source $WORKSPACE/releng_flake8/bin/activate
279
280             # install python packages
281             pip install "flake8==2.6.2"
282
283             # generate and upload lint log
284             echo "Running flake8 code on $PROJECT ..."
285
286             # Get number of flake8 violations. If none, this will be an
287             # empty string: ""
288             FLAKE_COUNT="$(find . \
289                 -path './releng_flake8' -prune -o \
290                 -path './.tox' -prune -o \
291                 -type f -name "*.py" -print | \
292                 xargs flake8 --exit-zero -qq --count 2>&1)"
293
294             # Ensure we start with a clean environment
295             rm -f lint.log
296
297             if [ ! -z $FLAKE_COUNT ]; then
298               echo "Flake8 Violations: $FLAKE_COUNT" > lint.log
299               find . \
300                   -path './releng_flake8' -prune -o \
301                   -path './.tox' -prune -o \
302                   -type f -name "*.py" -print | \
303                   xargs flake8 --exit-zero --first >> violation.log
304               SHOWN=$(wc -l violation.log | cut -d' ' -f1)
305               echo -e "First $SHOWN shown\n---" >> lint.log
306               cat violation.log >> lint.log
307               sed -r -i '4,$s/^/ /g' lint.log
308               rm violation.log
309             fi
310
311             deactivate
312
313 - builder:
314     name: report-lint-result-to-gerrit
315     builders:
316         - shell: |
317             #!/bin/bash
318             set -o errexit
319             set -o pipefail
320             set -o xtrace
321             export PATH=$PATH:/usr/local/bin/
322
323             # If no violations were found, no lint log will exist.
324             if [[ -e lint.log ]] ; then
325                 echo -e "\nposting linting report to gerrit...\n"
326
327                 cat lint.log
328                 echo
329
330                 ssh -p 29418 gerrit.opnfv.org \
331                     "gerrit review -p $GERRIT_PROJECT \
332                      -m \"$(cat lint.log)\" \
333                      $GERRIT_PATCHSET_REVISION \
334                      --notify NONE"
335
336                 exit 1
337             fi
338
339 - builder:
340     name: upload-review-docs
341     builders:
342         - build-html-and-pdf-docs-output
343         - upload-under-review-docs-to-opnfv-artifacts
344         - report-docs-build-result-to-gerrit
345
346 - builder:
347     name: upload-merged-docs
348     builders:
349         - build-html-and-pdf-docs-output
350         - upload-generated-docs-to-opnfv-artifacts
351         - report-docs-build-result-to-gerrit
352         - remove-old-docs-from-opnfv-artifacts
353
354 - builder:
355     name: check-bash-syntax
356     builders:
357         - shell: "find . -name '*.sh' | xargs bash -n"