Migrate ansible-lint to pre-commit
* Kept old specific linter tox targets for backwards compatibility, so developer can easily run a single linter if desired. * Reused tox linters virtualenvs to avoid wasting space * Moved linter config to their official location which enables developer to call them in any way he wants (like his IDE) * Updates yamllint to its newer version which supports strict * Fixed yamllint errors * Used parsable output format on yamllint which is more consistent with other tools, being also recognized by IDEs and terminals. Change-Id: I2bd44feb0a221dcd6f5402e070cf38b31fd8ac97 Depends-On: https://review.openstack.org/#/c/621930/ Story: https://tree.taiga.io/project/tripleo-ci-board/task/381
This commit is contained in:
parent
e25a4ca4d5
commit
ebcf22bb69
|
@ -0,0 +1,18 @@
|
|||
exclude_paths:
|
||||
- roles/validate-ui/.travis.yml
|
||||
parseable: true
|
||||
rulesdir:
|
||||
- ./ci-scripts/ansible_rules/
|
||||
quiet: false
|
||||
skip_list:
|
||||
- ANSIBLE0006 # Using command rather than module we have a few use cases
|
||||
# where we need to use curl and rsync
|
||||
- ANSIBLE0007 # Using command rather than an argument to e.g file
|
||||
# we have a lot of 'rm' command and we should use file module instead
|
||||
- ANSIBLE0010 # Package installs should not use latest.
|
||||
# Sometimes we need to update some packages.
|
||||
- ANSIBLE0012 # Commands should not change things if nothing needs doing
|
||||
- ANSIBLE0013 # Use Shell only when shell functionality is required
|
||||
- ANSIBLE0016 # Tasks that run when changed should likely be handlers
|
||||
# this requires refactoring roles, skipping for now
|
||||
verbosity: 1
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v1.4.0
|
||||
rev: v2.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: mixed-line-ending
|
||||
|
@ -20,7 +20,13 @@ repos:
|
|||
- id: yamllint
|
||||
files: \.(yaml|yml)$
|
||||
types: [file, yaml]
|
||||
entry: yamllint --strict
|
||||
entry: yamllint --strict -f parsable
|
||||
- repo: https://github.com/ansible/ansible-lint
|
||||
rev: v3.5.1
|
||||
hooks:
|
||||
- id: ansible-lint
|
||||
files: \.(yaml|yml)$
|
||||
entry: ansible-lint --force-color -v
|
||||
- repo: https://github.com/openstack-dev/bashate.git
|
||||
rev: 0.6.0
|
||||
hooks:
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ANSIBLE0006: Using command rather than module
|
||||
# we have a few use cases where we need to use curl and rsync
|
||||
# ANSIBLE0007: Using command rather than an argument to e.g file
|
||||
# we have a lot of 'rm' command and we should use file module instead
|
||||
# ANSIBLE0010: Package installs should not use latest.
|
||||
# Sometimes we need to update some packages.
|
||||
# ANSIBLE0012: Commands should not change things if nothing needs doing
|
||||
# ANSIBLE0013: Use Shell only when shell functionality is required
|
||||
# ANSIBLE0016: Tasks that run when changed should likely be handlers
|
||||
# this requires refactoring roles, skipping for now
|
||||
SKIPLIST="ANSIBLE0006,ANSIBLE0007,ANSIBLE0010,ANSIBLE0012,ANSIBLE0013,ANSIBLE0016"
|
||||
|
||||
# lint the playbooks separately to avoid linting the roles multiple times
|
||||
pushd playbooks
|
||||
for playbook in `find . -type f -regex '.*\.y[a]?ml'`; do
|
||||
ansible-lint -vvv -p -x $SKIPLIST -R -r ../ci-scripts/ansible_rules $playbook || lint_error=1
|
||||
done
|
||||
popd
|
||||
|
||||
# lint all the possible roles
|
||||
# Due to https://github.com/willthames/ansible-lint/issues/210, the roles
|
||||
# directories need to contain a trailing slash at the end of the path.
|
||||
for rolesdir in `find ./roles -maxdepth 1 -type d`; do
|
||||
ansible-lint -vvv -p -x $SKIPLIST -R -r ./ci-scripts/ansible_rules $rolesdir/ || lint_error=1
|
||||
done
|
||||
|
||||
## exit with 1 if we had a least an error or warning.
|
||||
if [[ -n "$lint_error" ]]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
openstackdocstheme>=1.11.0 # Apache-2.0
|
||||
|
||||
pre-commit>=1.10 # MIT License
|
||||
ansible-lint>=3.5.0
|
||||
sphinx>=1.6.2 # BSD
|
||||
reno>=1.8.0 # Apache-2.0
|
||||
jinja2
|
||||
|
|
6
tox.ini
6
tox.ini
|
@ -22,6 +22,7 @@ commands = bindep test
|
|||
commands = python setup.py build_sphinx
|
||||
|
||||
[testenv:bashate]
|
||||
envdir = {toxworkdir}/linters
|
||||
commands =
|
||||
python -m pre_commit run bashate --all-files
|
||||
|
||||
|
@ -31,9 +32,9 @@ commands =
|
|||
python -m pre_commit run flake8 --all-files
|
||||
|
||||
[testenv:ansible-lint]
|
||||
basepython=python2
|
||||
envdir = {toxworkdir}/linters
|
||||
commands =
|
||||
bash ci-scripts/ansible-lint.sh
|
||||
python -m pre_commit run ansible-lint -a
|
||||
|
||||
[testenv:releasenotes]
|
||||
whitelist_externals = bash
|
||||
|
@ -45,7 +46,6 @@ commands =
|
|||
python -m pre_commit run --source HEAD^ --origin HEAD
|
||||
# in the future we may want to check entire repository:
|
||||
# python -m pre_commit run yamllint --all-files
|
||||
{[testenv:ansible-lint]commands}
|
||||
{[testenv:validate-jinja]commands}
|
||||
|
||||
[testenv:venv]
|
||||
|
|
Loading…
Reference in New Issue