From 85b986cf3ee968cc4fae7296025e9cbd1adeff0b Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Tue, 29 Jul 2025 11:25:26 -0500 Subject: [PATCH] chore: add pre-commit and hook it into Zuul A number of OpenStack projects have adopted pre-commit and run it as their lint step so that developers have an easy way to run the same checks locally that will run in the CI loop. So this adds an initial pre-commit config to detect trailing whitespace and replaces that existing check to be called via pre-commit. Added a tox environment for running pre-commit as well. Change-Id: I9cf95f0c6db166ee1e59f8aedf376c511ac23010 Signed-off-by: Doug Goldstein --- .pre-commit-config.yaml | 8 ++++++++ playbooks/lint.yaml | 7 ------- tox.ini | 5 +++++ zuul.d/base.yaml | 4 ++++ zuul.d/project.yaml | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..4e533163e7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: fix-byte-order-marker + - id: check-merge-conflict diff --git a/playbooks/lint.yaml b/playbooks/lint.yaml index 40890bcc6e..bc487c6552 100644 --- a/playbooks/lint.yaml +++ b/playbooks/lint.yaml @@ -39,13 +39,6 @@ # chdir: "{{ work_dir }}" # target: all - - name: Prevent trailing whitespaces - shell: find . \! \( -path "*/\.*" -o -path "*/doc/build/*" -o -name "*.tgz" -o -name "*.png" -o -name "*.jpg" \) -type f -exec grep -El " +$" {} \; - register: _found_whitespaces - failed_when: _found_whitespaces.stdout != "" - args: - chdir: "{{ work_dir }}" - - name: Install yamllint shell: pip3 install -U yq yamllint become: yes diff --git a/tox.ini b/tox.ini index 83e485730d..7e90f9c70d 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,11 @@ passenv = *_proxy,*_PROXY [testenv:venv] commands = {posargs} +[testenv:linters] +deps = pre-commit +allowlist_externals = pre-commit +commands = pre-commit run --all-files --show-diff-on-failure {posargs} + [testenv:docs] deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} diff --git a/zuul.d/base.yaml b/zuul.d/base.yaml index 7563cf1931..85b91c7754 100644 --- a/zuul.d/base.yaml +++ b/zuul.d/base.yaml @@ -23,6 +23,10 @@ pre-run: - playbooks/inject-keys.yaml +- job: + name: openstack-helm-pre-commit + parent: tox-linters + - job: name: openstack-helm-bandit roles: diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml index 188135174e..693ac8baf3 100644 --- a/zuul.d/project.yaml +++ b/zuul.d/project.yaml @@ -20,6 +20,7 @@ check: jobs: - openstack-helm-linter + - openstack-helm-pre-commit - openstack-helm-bandit # 2024.1 - openstack-helm-tls-2024-1-ubuntu_jammy # 3 nodes rook