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