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 <cardoe@cardoe.com>
This commit is contained in:
Doug Goldstein
2025-07-29 11:25:26 -05:00
parent 7bcc0b9572
commit 85b986cf3e
5 changed files with 18 additions and 7 deletions

8
.pre-commit-config.yaml Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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}

View File

@@ -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:

View File

@@ -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