Skip to content

Commit

Permalink
chore(pre-commit): streamline the configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Macha committed Mar 30, 2024
1 parent 177d017 commit ffcf155
Show file tree
Hide file tree
Showing 6 changed files with 494 additions and 74 deletions.
19 changes: 19 additions & 0 deletions .ansible-lint-ignore-legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file contains ignores rule violations for ansible-lint
.gitlab-ci.yml yaml[quoted-strings]
.pre-commit-config-legacy.yaml yaml[line-length]
.releaserc.yaml yaml[document-end]
.releaserc.yaml yaml[document-start]
.releaserc.yaml yaml[quoted-strings]
ansible/fetch-secrets-from-ucs-machine.yaml no-changed-when
ansible/fetch-secrets-from-ucs-machine.yaml risky-file-permissions
ansible/fetch-secrets-from-ucs-machine.yaml yaml[document-end]
ansible/fetch-secrets-from-ucs-machine.yaml yaml[quoted-strings]
docker-compose.yaml yaml[empty-values]
docker-compose.yaml yaml[line-length]
docker-compose.yaml yaml[quoted-strings]
helm/udm-rest-api/Chart.yaml yaml[document-end]
helm/udm-rest-api/Chart.yaml yaml[quoted-strings]
helm/udm-rest-api/linter_values.yaml yaml[quoted-strings]
helm/udm-rest-api/values.yaml yaml[document-end]
helm/udm-rest-api/values.yaml yaml[line-length]
helm/udm-rest-api/values.yaml yaml[quoted-strings]
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

[flake8]

# yapf with 79 sometimes use 80
# default=79
max-line-length = 100

max-complexity = 10
8 changes: 2 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: 2023 Univention GmbH

---

include:
- project: "univention/customers/dataport/upx/common-ci"
ref: "v1.25.0"
Expand All @@ -11,7 +12,7 @@ include:
- "jobs/sphinx-docs.yaml"
- "defaults/stages.yaml"
- "defaults/souvap-workflow.yaml"
- "jobs/lint-pre-commit.yaml"
- "jobs/lint-pre-commit-legacy.yaml"
- "jobs/lint-commit-messages.yaml"
- "jobs/semantic-release-env.yaml"
- "jobs/container-build-souvap.yaml"
Expand All @@ -23,11 +24,6 @@ include:
file:
- "dind.yml"

lint-pre-commit:
before_script:
# Compose lint would fail without the referenced env files
- "cp .env.udm-rest-api.example .env.udm-rest-api"

.build-matrix: &build-matrix
- IMAGE_NAME:
- "udm-rest-api"
Expand Down
235 changes: 235 additions & 0 deletions .pre-commit-config-legacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
---

# SPDX-FileCopyrightText: 2023-2024 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

repos:
# "Copy .env.udm-rest-api.example so that docker-compose.yaml can be linted"
- repo: "local"
hooks:
- id: "copy-udm-rest-api"
name: "copy-udm-rest-api"
entry: "sh -c 'if [ ! -f .env.udm-rest-api ]; then cp .env.udm-rest-api.example .env.udm-rest-api; fi'"
language: "system"
files: "docker-compose.yaml"
pass_filenames: false

- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v4.5.0"
hooks:
- id: "check-added-large-files"
name: "check for added large files"
- id: "check-ast"
name: "check python ast"
- id: "check-case-conflict"
name: "check for case conflicts"
- id: "check-docstring-first"
name: "check docstring is first"
- id: "check-executables-have-shebangs"
name: "check that executables have shebangs"
- id: "check-json"
name: "check json"
- id: "check-merge-conflict"
name: "check for merge conflicts"
- id: "check-yaml"
name: "check yaml"
exclude: "^helm/.+/templates/"
args:
- "--allow-multiple-documents"
# Allow custom tags like Gitlab's "!reference" tag.
- "--unsafe"
- id: "check-symlinks"
name: "check for broken symlinks"
- id: "detect-private-key"
name: "detect private key"
- id: "end-of-file-fixer"
name: "fix end of files"
exclude: "^helm/.+/README.md$"
- id: "fix-byte-order-marker"
name: "fix utf-8 byte order marker"
- id: "trailing-whitespace"
name: "trim trailing whitespace"

- repo: "https://github.com/compilerla/conventional-pre-commit"
rev: "v3.0.0"
hooks:
- id: "conventional-pre-commit"
name: "Conventional Commit"
stages: ["commit-msg"]

- repo: "https://git.knut.univention.de/univention/dist/pre-commit-hooks/addlicense"
rev: "v1.0.1"
hooks:
- id: "addlicense"
name: "Check or add license headers to files"
types_or:
- "dockerfile"
- "python"
- "yaml"

- repo: "https://github.com/adrienverge/yamllint"
rev: "v1.33.0"
hooks:
- id: "yamllint"
name: "yamllint"
types:
- "yaml"
exclude: "^helm/.+/templates/"
args:
- "--config-file=.yamllint"
- "--format=parsable"
# TODO replace no-warnings with strict
# - "--strict"
- "--no-warnings"

- repo: "https://github.com/ansible/ansible-lint"
rev: "v6.22.1"
hooks:
- id: "ansible-lint"
name: "Ansible-lint"
args:
- "--ignore-file=.ansible-lint-ignore-legacy"

- repo: "https://github.com/google/yapf"
rev: "v0.40.2"
hooks:
- id: "yapf"
name: "yapf"
types:
- "python"
exclude: "^(docs/conf.py|tests/integration/conftest.py|tests/integration/test_users_user.py)"

- repo: "https://github.com/astral-sh/ruff-pre-commit"
rev: "v0.1.9"
hooks:
- id: "ruff"
name: "ruff"
types:
- "python"
args:
- "--fix"
- "--show-source"
- "--exit-non-zero-on-fix"
- "--extend-select=COM"

- repo: "https://github.com/hhatto/autopep8"
rev: "v2.0.4"
hooks:
- id: "autopep8"
name: "autopep8"
types:
- "python"
args:
- "--in-place"
- "--aggressive"
- "--aggressive"
- "--experimental"

- repo: "https://github.com/PyCQA/flake8"
rev: "6.1.0"
hooks:
- id: "flake8"
name: "flake8"
types:
- "python"

- repo: "https://github.com/pylint-dev/pylint"
rev: "v3.0.3"
hooks:
- id: "pylint"
name: "pylint"
types:
- "python"
additional_dependencies:
- "pytest"
- "requests"
- "sphinx"
# TODO: remove args
args:
# C0103: Constant name "pdf_doc_base" doesn't conform to UPPER_CASE naming style (invalid-name)
- "--disable=invalid-name"
# C0114: Missing module docstring (missing-module-docstring)
- "--disable=missing-module-docstring"
# C0116: Missing function or method docstring (missing-function-docstring)
- "--disable=missing-function-docstring"
# C0209: Formatting a regular string which could be an f-string (consider-using-f-string)
- "--disable=consider-using-f-string"
# E1101: Instance of '<class>' has no '<member>' member (no-member)
- "--disable=no-member"
# W0621: Redefining name 'session' from outer scope (line 55) (redefined-outer-name)
- "--disable=redefined-outer-name"
# W0622: Redefining built-in 'copyright' (redefined-builtin)
- "--disable=redefined-builtin"

- repo: "https://github.com/hadolint/hadolint"
rev: "v2.12.0"
hooks:
- id: "hadolint"
name: "Lint Dockerfiles"
types:
- "dockerfile"
args:
- "--no-color"
- "--strict-labels"
# DL3050 info: Superfluous label(s) present.
- "--ignore=DL3050"

- repo: "https://gitlab.com/univention/pre-commit-hooks/docker-compose-check"
rev: "7702a8801a158b8595569dd29e2dd655d8a08310"
hooks:
- id: "docker-compose-check"
name: "Validate docker-compose files (python)"
types:
- "yaml"

# Cloned from github.com/IamTheFij/docker-pre-commit
- repo: "https://gitlab.com/univention/pre-commit-hooks/docker-pre-commit"
rev: "v3.0.1"
hooks:
- id: "docker-compose-check"
name: "Validate docker compose files (bash)"
types:
- "yaml"

- repo: "https://gitlab.com/univention/pre-commit-hooks/pre-commit-shell"
rev: "v1.0.6+uv1"
hooks:
- id: "shell-lint"
name: "Shell Syntax Check"
types:
- "shell"
args:
- "--enable=all"
- "--external-sources"
# SC2250 (style): Prefer putting braces around variable references even when not strictly required.
- "--exclude=SC2250"

- repo: "https://github.com/gruntwork-io/pre-commit"
rev: "v0.1.23"
hooks:
- id: "helmlint"
name: "helmlint"

- repo: "https://github.com/norwoodj/helm-docs"
rev: "v1.12.0"
hooks:
- id: "helm-docs"
name: "Helm Docs"
args:
- "--chart-search-root=helm"
- "--template-files=README.md.gotmpl"
always_run: true

# Uses `GITLAB_SERVER`, `GITLAB_PROJECT_ID` and `GITLAB_PRIVATE_TOKEN`
- repo: "https://gitlab.com/univention/pre-commit-hooks/gitlab-ci-linter"
rev: "v1.0.6+uv2"
hooks:
- id: "gitlab-ci-linter"
name: ".gitlab-ci.yml linter"
stages:
- "manual"

...
Loading

0 comments on commit ffcf155

Please sign in to comment.