Add YAMLLint for static check 17/25717/9
authorKingPoo <haojingbo@huawei.com>
Fri, 9 Dec 2016 08:49:24 +0000 (03:49 -0500)
committerKingPoo <haojingbo@huawei.com>
Sat, 24 Dec 2016 11:35:36 +0000 (06:35 -0500)
JIRA: OCTO-160

Current CI commit gate is simple, just have flake8 check in part of projects,
it's better to apply more check tools to more projects.
Yaml files could be checked by YAMLLint when the project is configed in releng.
YAMLLint does not only check for syntax validity, but for weirdnesses like key
repetition and cosmetic problems such as lines length, trailing spaces, indentation,
etc.

Change-Id: Ie90afd4a07ad10cc723f31efd35e5605f765583c
Signed-off-by: KingPoo <haojingbo@huawei.com>
jjb/global/releng-macros.yml
jjb/releng/opnfv-lint.yml

index cd92480..7647a35 100644 (file)
     name: check-bash-syntax
     builders:
         - shell: "find . -name '*.sh' | xargs bash -n"
+
+- builder:
+    name: lint-yaml-code
+    builders:
+        - shell: |
+            #!/bin/bash
+            set -o errexit
+            set -o pipefail
+            set -o xtrace
+            export PATH=$PATH:/usr/local/bin/
+
+            # generate and upload lint log
+            echo "Running yaml code on $PROJECT ..."
+
+            # Ensure we start with a clean environment
+            rm -f yaml-violation.log lint.log
+
+            # Get number of yaml violations. If none, this will be an
+            # empty string: ""
+            find . \
+                -path './releng_yamllint' -prune -o \
+                -path './.tox' -prune -o \
+                -type f -name "*.yml" -print \
+                -o -name "*.yaml" -print | \
+                xargs yamllint > yaml-violation.log || true
+
+            if [ -s "yaml-violation.log" ]; then
+              SHOWN=$(cat yaml-violation.log| grep -v "^$" |wc -l)
+              echo -e "First $SHOWN shown\n---" > lint.log
+              cat yaml-violation.log >> lint.log
+              sed -r -i '4,$s/^/ /g' lint.log
+            fi
+
index 7115cce..cd122d8 100644 (file)
@@ -9,6 +9,7 @@
 
     jobs:
         - 'opnfv-lint-verify-{stream}'
+        - 'opnfv-yamllint-verify-{stream}'
 
     stream:
         - master:
     builders:
         - lint-python-code
         - report-lint-result-to-gerrit
+
+- job-template:
+    name: 'opnfv-yamllint-verify-{stream}'
+
+    disabled: '{obj:disabled}'
+
+    parameters:
+        - project-parameter:
+            project: $GERRIT_PROJECT
+        - gerrit-parameter:
+            branch: '{branch}'
+        - node:
+            name: SLAVE_NAME
+            description: Slaves to execute yamllint
+            default-slaves:
+                - lf-build1
+            allowed-multiselect: true
+            ignore-offline-nodes: true
+
+    scm:
+        - git-scm-gerrit
+
+    triggers:
+        - gerrit:
+            server-name: 'gerrit.opnfv.org'
+            trigger-on:
+                - patchset-created-event:
+                    exclude-drafts: 'false'
+                    exclude-trivial-rebase: 'false'
+                    exclude-no-code-change: 'false'
+                - draft-published-event
+                - comment-added-contains-event:
+                    comment-contains-value: 'recheck'
+                - comment-added-contains-event:
+                    comment-contains-value: 'reverify'
+            projects:
+              - project-compare-type: 'REG_EXP'
+                project-pattern: 'compass4nfv'
+                branches:
+                  - branch-compare-type: 'ANT'
+                    branch-pattern: '**/{branch}'
+                file-paths:
+                  - compare-type: ANT
+                    pattern: '**/*.yml'
+                  - compare-type: ANT
+                    pattern: '**/*.yaml'
+
+    builders:
+        - lint-yaml-code
+        - report-lint-result-to-gerrit