From 6779ff041c117565ec9cfa77b54110d4a1beb663 Mon Sep 17 00:00:00 2001 From: Andrii Ostapenko Date: Sun, 17 May 2020 14:01:39 -0500 Subject: [PATCH] Add yamllint check to lint job Initial commit with bootstrapping non-voting configuration for yamllint. Yamllint checks will be switched from 'warning' to 'enabled' in subsequent commits together with code adjustments. Change-Id: Ie372cb9fefb310bd044b4b03064e183f0c8c003b --- playbooks/zuul-linter.yaml | 9 +++++++ tox.ini | 11 +++++++++ yamllint.conf | 49 ++++++++++++++++++++++++++++++++++++++ zuul.d/playbooks/lint.yml | 11 +++++++++ 4 files changed, 80 insertions(+) create mode 100644 yamllint.conf diff --git a/playbooks/zuul-linter.yaml b/playbooks/zuul-linter.yaml index 3e9f0710c..3cf00ea89 100644 --- a/playbooks/zuul-linter.yaml +++ b/playbooks/zuul-linter.yaml @@ -16,3 +16,12 @@ command: find . -not -path "*/\.*" -not -path "*/doc/build/*" -not -name "*.tgz" -type f -exec egrep -l " +$" {} \; register: result failed_when: result.stdout != "" + + - name: Check if yamllint.conf exists + stat: + path: yamllint.conf + register: yamllintconf + + - name: Execute yamllint check for values* yaml files + command: tox -e lint + when: yamllintconf.stat.exists == True diff --git a/tox.ini b/tox.ini index 5685b3100..3608ea809 100644 --- a/tox.ini +++ b/tox.ini @@ -20,3 +20,14 @@ commands = sphinx-build -W -b html doc/source doc/build/html whitelist_externals = rm + +[testenv:lint] +deps = yamllint +commands = + bash -c "rm -rf {toxinidir}/.yamllint" + bash -c "mkdir -p {toxinidir}/.yamllint" + bash -c "cp -r $(ls {toxinidir}) {toxinidir}/.yamllint/" + bash -c "find {toxinidir}/.yamllint -type f -exec sed -i 's/%%%.*/XXX/g' \{\} +" + bash -c "yamllint -c {toxinidir}/yamllint.conf {toxinidir}/.yamllint/*/values*" +whitelist_externals = + bash diff --git a/yamllint.conf b/yamllint.conf new file mode 100644 index 000000000..ea59c739a --- /dev/null +++ b/yamllint.conf @@ -0,0 +1,49 @@ +--- + +yaml-files: +- '*.yaml' +- '*.yml' +- '.yamllint' + +rules: + braces: + level: warning + brackets: + level: warning + colons: + level: warning + commas: + level: warning + comments: + level: warning + comments-indentation: + level: warning + document-end: + level: warning + document-start: + level: warning + empty-lines: + level: warning + empty-values: + level: warning + hyphens: + level: warning + indentation: + spaces: 2 + indent-sequences: whatever + level: warning + key-duplicates: + level: warning + key-ordering: disable + line-length: disable + new-line-at-end-of-file: + level: warning + new-lines: + level: warning + octal-values: + level: warning + quoted-strings: disable + trailing-spaces: enable + truthy: + level: warning +... diff --git a/zuul.d/playbooks/lint.yml b/zuul.d/playbooks/lint.yml index 19d0d41bf..9ebcc7b98 100644 --- a/zuul.d/playbooks/lint.yml +++ b/zuul.d/playbooks/lint.yml @@ -21,3 +21,14 @@ failed_when: _found_whitespaces.stdout != "" args: chdir: "{{ ansible_user_dir }}/src/{{ zuul.project.canonical_name }}" + + - name: Check if yamllint.conf exists + stat: + path: "{{ ansible_user_dir }}/src/{{ zuul.project.canonical_name }}/yamllint.conf" + register: yamllintconf + + - name: Execute yamllint check for values* yaml files + command: tox -e lint + args: + chdir: "{{ ansible_user_dir }}/src/{{ zuul.project.canonical_name }}" + when: yamllintconf.stat.exists == True