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