summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Kumar <chkumar@redhat.com>2019-02-15 14:47:53 +0530
committerChandan Kumar <chkumar@redhat.com>2019-02-15 18:22:10 +0530
commitb541c5ef99d61d56e78eeb00a0ae7faacc4dd604 (patch)
treed0574445ce86c1131f5d8ad626a2f34ec6f806ae
parentad56778e6e5cf05fadacbf7caca339f8680e0116 (diff)
Run all linters via pre-commit
Executes all linters via pre-commit, which is much faster, guarantees their version locking and allows upgrading them with a single command. Before this change the only linter running via pre-commit was ansible-lint. Now we also run bashate, flake8 and yamllint via pre-commit. For developer convenience we still keep the old tox environments which allow running a single linter. Added long_description_content_type to fix twine check failure Change-Id: I037eae61921b2a84aa99838804f70e96ee8d8b13
Notes
Notes (review): Code-Review+1: Sorin Sbarnea <ssbarnea@redhat.com> Code-Review+2: Alex Schultz <aschultz@redhat.com> Code-Review+2: Jill Rouleau <jill.rouleau@bespokess.com> Workflow+1: Alex Schultz <aschultz@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sat, 16 Feb 2019 02:32:08 +0000 Reviewed-on: https://review.openstack.org/637150 Project: openstack/ansible-role-tripleo-modify-image Branch: refs/heads/master
-rw-r--r--.ansible-lint2
-rw-r--r--.pre-commit-config.yaml40
-rw-r--r--.yamllint7
-rw-r--r--LICENSE1
-rw-r--r--defaults/main.yml1
-rw-r--r--files/dev_install.sh2
-rw-r--r--meta/main.yml7
-rw-r--r--setup.cfg5
-rw-r--r--setup.py1
-rw-r--r--tasks/dev_install.yml1
-rw-r--r--tasks/get_original_user.yml6
-rw-r--r--tasks/main.yml1
-rw-r--r--tasks/modify_image.yml3
-rw-r--r--tasks/precheck.yml4
-rw-r--r--tasks/rpm_install.yml3
-rw-r--r--tasks/yum_update.yml1
-rw-r--r--tasks/yum_update_buildah.yml4
-rw-r--r--tasks/yum_update_docker.yml1
-rw-r--r--test-requirements.txt2
-rw-r--r--tox.ini32
-rw-r--r--vars/main.yml1
-rw-r--r--zuul.d/layout.yaml1
22 files changed, 94 insertions, 32 deletions
diff --git a/.ansible-lint b/.ansible-lint
new file mode 100644
index 0000000..bb0b0ca
--- /dev/null
+++ b/.ansible-lint
@@ -0,0 +1,2 @@
1---
2parseable: true
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..39e69a5
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,40 @@
1---
2repos:
3 - repo: https://github.com/pre-commit/pre-commit-hooks
4 rev: v2.1.0
5 hooks:
6 - id: end-of-file-fixer
7 - id: trailing-whitespace
8 - id: mixed-line-ending
9 - id: check-byte-order-marker
10 - id: check-executables-have-shebangs
11 - id: check-merge-conflict
12 - id: debug-statements
13 - id: flake8
14 - id: check-yaml
15 files: .*\.(yaml|yml)$
16 - repo: https://github.com/adrienverge/yamllint.git
17 rev: v1.15.0
18 hooks:
19 - id: yamllint
20 files: \.(yaml|yml)$
21 types: [file, yaml]
22 entry: yamllint --strict -f parsable
23 - repo: https://github.com/ansible/ansible-lint
24 rev: v4.1.0a0
25 hooks:
26 - id: ansible-lint
27 files: \.(yaml|yml)$
28 entry: ansible-lint --force-color -v
29 - repo: https://github.com/openstack-dev/bashate.git
30 rev: 0.6.0
31 hooks:
32 - id: bashate
33 entry: bashate --error . --verbose --ignore=E006,E040
34 # Run bashate check for all bash scripts
35 # Ignores the following rules:
36 # E006: Line longer than 79 columns (as many scripts use jinja
37 # templating, this is very difficult)
38 # E040: Syntax error determined using `bash -n` (as many scripts
39 # use jinja templating, this will often fail and the syntax
40 # error will be discovered in execution anyway)
diff --git a/.yamllint b/.yamllint
new file mode 100644
index 0000000..689b7b5
--- /dev/null
+++ b/.yamllint
@@ -0,0 +1,7 @@
1---
2extends: default
3
4rules:
5 line-length:
6 # matches hardcoded 160 value from ansible-lint
7 max: 160
diff --git a/LICENSE b/LICENSE
index 68c771a..67db858 100644
--- a/LICENSE
+++ b/LICENSE
@@ -173,4 +173,3 @@
173 defend, and hold each Contributor harmless for any liability 173 defend, and hold each Contributor harmless for any liability
174 incurred by, or claims asserted against, such Contributor by reason 174 incurred by, or claims asserted against, such Contributor by reason
175 of your accepting any such warranty or additional liability. 175 of your accepting any such warranty or additional liability.
176
diff --git a/defaults/main.yml b/defaults/main.yml
index 805ad27..13ae719 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,2 +1,3 @@
1---
1update_repo: '' 2update_repo: ''
2container_build_tool: 'docker' 3container_build_tool: 'docker'
diff --git a/files/dev_install.sh b/files/dev_install.sh
index ee5d2d6..d6ce5f7 100644
--- a/files/dev_install.sh
+++ b/files/dev_install.sh
@@ -3,7 +3,7 @@ set -e
3# Cherry-pick a refspec 3# Cherry-pick a refspec
4# $1 : project name e.g. keystone 4# $1 : project name e.g. keystone
5# $2 : Gerrit refspec(s) to cherry pick 5# $2 : Gerrit refspec(s) to cherry pick
6function cherrypick(){ 6function cherrypick {
7 local PROJ_NAME=$1 7 local PROJ_NAME=$1
8 local REFSPECS="$2" 8 local REFSPECS="$2"
9 9
diff --git a/meta/main.yml b/meta/main.yml
index 7bfd2d4..cb172cb 100644
--- a/meta/main.yml
+++ b/meta/main.yml
@@ -1,3 +1,4 @@
1---
1galaxy_info: 2galaxy_info:
2 author: Steve Baker 3 author: Steve Baker
3 description: Modify container images built for TripleO 4 description: Modify container images built for TripleO
@@ -6,9 +7,9 @@ galaxy_info:
6 min_ansible_version: 2.4 7 min_ansible_version: 2.4
7 8
8 platforms: 9 platforms:
9 - name: EL 10 - name: EL
10 versions: 11 versions:
11 - 7 12 - 7
12 13
13 galaxy_tags: 14 galaxy_tags:
14 - docker 15 - docker
diff --git a/setup.cfg b/setup.cfg
index 0bc4770..d88dae4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -34,3 +34,8 @@ universal = 1
34skip_authors = True 34skip_authors = True
35skip_changelog = True 35skip_changelog = True
36 36
37[flake8]
38# E123, E125 skipped as they are invalid PEP-8.
39show-source = True
40ignore = E123,E125
41builtins = _
diff --git a/setup.py b/setup.py
index 6a931a6..69176a0 100644
--- a/setup.py
+++ b/setup.py
@@ -15,5 +15,6 @@
15import setuptools 15import setuptools
16 16
17setuptools.setup( 17setuptools.setup(
18 long_description_content_type='text/markdown',
18 setup_requires=['pbr'], 19 setup_requires=['pbr'],
19 pbr=True) 20 pbr=True)
diff --git a/tasks/dev_install.yml b/tasks/dev_install.yml
index 2979b3f..5271b30 100644
--- a/tasks/dev_install.yml
+++ b/tasks/dev_install.yml
@@ -1,3 +1,4 @@
1---
1- import_tasks: precheck.yml 2- import_tasks: precheck.yml
2 tags: 3 tags:
3 - always 4 - always
diff --git a/tasks/get_original_user.yml b/tasks/get_original_user.yml
index 06af14e..e0b6741 100644
--- a/tasks/get_original_user.yml
+++ b/tasks/get_original_user.yml
@@ -1,3 +1,4 @@
1---
1- when: container_build_tool == 'docker' 2- when: container_build_tool == 'docker'
2 block: 3 block:
3 - name: Inspect image with Docker 4 - name: Inspect image with Docker
@@ -19,8 +20,7 @@
19 become: true 20 become: true
20 - name: Set config with Buildah 21 - name: Set config with Buildah
21 set_fact: 22 set_fact:
22 buildah_config: "{{ source_image_facts.stdout_lines | join('') | from_json }}" 23 buildah_config: "{{ source_image_facts.stdout_lines | join('') | from_json }}"
23 - name: Set original_user with Buildah 24 - name: Set original_user with Buildah
24 set_fact: 25 set_fact:
25 original_user: "{{ buildah_config['Docker']['config']['User'] }}" 26 original_user: "{{ buildah_config['Docker']['config']['User'] }}"
26
diff --git a/tasks/main.yml b/tasks/main.yml
index 95ead2f..191d5db 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,3 +1,4 @@
1---
1- import_tasks: precheck.yml 2- import_tasks: precheck.yml
2 tags: 3 tags:
3 - always 4 - always
diff --git a/tasks/modify_image.yml b/tasks/modify_image.yml
index 567504e..ff5d569 100644
--- a/tasks/modify_image.yml
+++ b/tasks/modify_image.yml
@@ -1,3 +1,4 @@
1---
1- import_tasks: precheck.yml 2- import_tasks: precheck.yml
2 tags: 3 tags:
3 - always 4 - always
@@ -36,7 +37,7 @@
36 {{ build_commands[container_build_tool] }} \ 37 {{ build_commands[container_build_tool] }} \
37 --tag {{ target_image | default(source_image) }}{{ modified_append_tag }} \ 38 --tag {{ target_image | default(source_image) }}{{ modified_append_tag }} \
38 --file {{ dockerfile.path }} --network host ./ 39 --file {{ dockerfile.path }} --network host ./
39 #FIXME: buildah should not required root commands to build an image 40 # FIXME: buildah should not required root commands to build an image
40 become: "{{ true if build_commands[container_build_tool] == 'buildah' else false }}" 41 become: "{{ true if build_commands[container_build_tool] == 'buildah' else false }}"
41 args: 42 args:
42 chdir: "{{ modify_dir_path }}" 43 chdir: "{{ modify_dir_path }}"
diff --git a/tasks/precheck.yml b/tasks/precheck.yml
index 6649784..2fb2fd0 100644
--- a/tasks/precheck.yml
+++ b/tasks/precheck.yml
@@ -1,3 +1,4 @@
1---
1- name: Ensure that source_image is defined 2- name: Ensure that source_image is defined
2 assert: 3 assert:
3 that: 4 that:
@@ -5,7 +6,8 @@
5 - source_image | length > 0 6 - source_image | length > 0
6 7
7- name: Ensure that container_build_tool is correctly set 8- name: Ensure that container_build_tool is correctly set
8 fail: msg="{{ container_build_tool }} is not a valid value for container_build_tool. Pick docker or buildah." 9 fail: msg="{{ container_build_tool }} is not a valid value for
10 container_build_tool. Pick docker or buildah."
9 when: container_build_tool not in ['docker', 'buildah'] 11 when: container_build_tool not in ['docker', 'buildah']
10 12
11- name: Set default modified_append_tag 13- name: Set default modified_append_tag
diff --git a/tasks/rpm_install.yml b/tasks/rpm_install.yml
index 7c99347..fb3ce9a 100644
--- a/tasks/rpm_install.yml
+++ b/tasks/rpm_install.yml
@@ -1,3 +1,4 @@
1---
1- import_tasks: precheck.yml 2- import_tasks: precheck.yml
2 tags: 3 tags:
3 - always 4 - always
@@ -18,7 +19,7 @@
18 find: 19 find:
19 paths: "{{ rpms_path }}" 20 paths: "{{ rpms_path }}"
20 patterns: "^.*?\\.rpm$" 21 patterns: "^.*?\\.rpm$"
21 use_regex: yes 22 use_regex: true
22 when: rpms_path is defined 23 when: rpms_path is defined
23 register: context_rpms 24 register: context_rpms
24 25
diff --git a/tasks/yum_update.yml b/tasks/yum_update.yml
index 47497ac..72ecb70 100644
--- a/tasks/yum_update.yml
+++ b/tasks/yum_update.yml
@@ -1,3 +1,4 @@
1---
1- import_tasks: precheck.yml 2- import_tasks: precheck.yml
2 tags: 3 tags:
3 - always 4 - always
diff --git a/tasks/yum_update_buildah.yml b/tasks/yum_update_buildah.yml
index 3318df3..c3e2d83 100644
--- a/tasks/yum_update_buildah.yml
+++ b/tasks/yum_update_buildah.yml
@@ -1,3 +1,4 @@
1---
1- import_tasks: precheck.yml 2- import_tasks: precheck.yml
2 tags: 3 tags:
3 - always 4 - always
@@ -57,7 +58,8 @@
57 path: "{{ yum_update.path }}" 58 path: "{{ yum_update.path }}"
58 state: absent 59 state: absent
59 60
60- name: Commit changes to image {{ target_image | default(source_image) }}{{ modified_append_tag }} 61- name: Commit changes to image
62 ({{ target_image | default(source_image) }}{{ modified_append_tag }})
61 command: > 63 command: >
62 buildah commit 64 buildah commit
63 {{ from_image }} 65 {{ from_image }}
diff --git a/tasks/yum_update_docker.yml b/tasks/yum_update_docker.yml
index 13e27b0..167c489 100644
--- a/tasks/yum_update_docker.yml
+++ b/tasks/yum_update_docker.yml
@@ -1,3 +1,4 @@
1---
1- import_tasks: precheck.yml 2- import_tasks: precheck.yml
2 tags: 3 tags:
3 - always 4 - always
diff --git a/test-requirements.txt b/test-requirements.txt
index bab219e..94dba19 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1 +1 @@
hacking>=1.1.0,<1.2.0 # Apache-2.0 pre-commit # MIT
diff --git a/tox.ini b/tox.ini
index 573dc25..02f7439 100644
--- a/tox.ini
+++ b/tox.ini
@@ -20,39 +20,33 @@ deps = bindep
20commands = bindep test 20commands = bindep test
21 21
22[testenv:pep8] 22[testenv:pep8]
23basepython = python3 23envdir = {toxworkdir}/linters
24commands = 24commands =
25 # Run hacking/flake8 check for all python files 25 python -m pre_commit run flake8 -a
26 bash -c "git ls-files | grep -v releasenotes | xargs grep --binary-files=without-match \
27 --files-with-match '^.!.*python$' \
28 --exclude-dir .tox \
29 --exclude-dir .git \
30 --exclude-dir .eggs \
31 --exclude-dir *.egg-info \
32 --exclude-dir dist \
33 --exclude-dir *lib/python* \
34 --exclude-dir doc \
35 | xargs flake8 --verbose"
36 26
37[testenv:ansible-lint] 27[testenv:ansible-lint]
38basepython=python3 28setenv =
29 ANSIBLE_LIBRARY=./library
30envdir = {toxworkdir}/linters
39commands = 31commands =
40 bash ci-scripts/ansible-lint.sh 32 python -m pre_commit run ansible-lint -a
41 33
42[testenv:linters] 34[testenv:linters]
43basepython = python3 35basepython = python3
44deps =
45 -r{toxinidir}/test-requirements.txt
46 -r{toxinidir}/ansible-requirements.txt
47commands = 36commands =
48 {[testenv:pep8]commands} 37 # check only modified files:
49 {[testenv:ansible-lint]commands} 38 python -m pre_commit run -a
50 39
51[testenv:releasenotes] 40[testenv:releasenotes]
52basepython = python3 41basepython = python3
53whitelist_externals = bash 42whitelist_externals = bash
54commands = bash -c ci-scripts/releasenotes_tox.sh 43commands = bash -c ci-scripts/releasenotes_tox.sh
55 44
45[testenv:bashate]
46envdir = {toxworkdir}/linters
47commands =
48 python -m pre_commit run bashate -a
49
56[testenv:venv] 50[testenv:venv]
57basepython = python3 51basepython = python3
58commands = {posargs} 52commands = {posargs}
diff --git a/vars/main.yml b/vars/main.yml
index 63a1893..3d0b87d 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,3 +1,4 @@
1---
1# we support 'docker' or 'buildah' 2# we support 'docker' or 'buildah'
2build_commands: 3build_commands:
3 docker: docker build 4 docker: docker build
diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml
index e7923eb..3c1d097 100644
--- a/zuul.d/layout.yaml
+++ b/zuul.d/layout.yaml
@@ -1,3 +1,4 @@
1---
1- project: 2- project:
2 templates: 3 templates:
3 - tripleo-multinode-container-minimal 4 - tripleo-multinode-container-minimal