From 077b9b4e5e251bfee39d0d5e6ea5ab74e25e24f0 Mon Sep 17 00:00:00 2001 From: Ben Grande Date: Mon, 8 Jul 2024 11:12:38 +0200 Subject: [PATCH] ci: lint YAML and spell check code --- .codespellrc | 9 +++++++++ .github/workflows/main.yaml | 5 ++--- .pre-commit-config.yaml | 32 ++++++++++++++++++++++++-------- .reuse/dep5 | 4 ++++ .salt-lint => .salt-lint.yaml | 0 .yamllint => .yamllint.yaml | 4 ++-- dependencies/debian.txt | 11 +++++++++++ dependencies/pip.txt | 1 + dependencies/rpm.txt | 4 ++++ scripts/spell-lint.sh | 30 ++++++++++++++++++++++++++++++ scripts/yaml-lint.sh | 28 ++++++++++++++++++++++++++++ 11 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 .codespellrc rename .salt-lint => .salt-lint.yaml (100%) rename .yamllint => .yamllint.yaml (93%) create mode 100644 dependencies/debian.txt create mode 100644 dependencies/pip.txt create mode 100644 dependencies/rpm.txt create mode 100755 scripts/spell-lint.sh create mode 100755 scripts/yaml-lint.sh diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..5ed3cd6 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2023 Benjamin Grande M. S. +# +# SPDX-License-Identifier: GPL-3.0-or-later +# vim: ft=toml + +[codespell] +skip = LICENSES,.git,*.asc,./rpm_spec/*-*.spec,*.muttrc,./salt/sys-cacher/files/server/conf/*_mirrors_*,./salt/dotfiles/files/vim/.config/vim/after/plugin/update-time.vim +ignore-words-list = uptodate,iterm,doas +ignore-regex = (nnoremap|bind)\b.* diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 51e5bff..da6d4ce 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -34,13 +34,12 @@ jobs: run: sudo apt-get -y update - name: Install OS packages # yamllint disable-line rule:line-length - run: sudo apt-get install -y python3-dev python3-pip shellcheck reuse ruby-mdl pylint - # gitlint is available on Debian but Ubuntu has an older version. + run: sudo apt-get install -y $(cat dev-deps-debian.txt) - name: Remove externally managed python environment flag # yamllint disable-line rule:line-length run: sudo dpkg-divert --rename --add /usr/lib/$(py3versions -d)/EXTERNALLY-MANAGED - name: Install pip packages - run: pip3 install salt-lint gitlint + run: pip3 install $(cat dev-deps-pip.txt) - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b5c3140..19494d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +# yamllint disable-line rule:line-length # SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. # # SPDX-License-Identifier: AGPL-3.0-or-later @@ -14,6 +15,13 @@ repos: pass_filenames: true description: Prohibit Unicode + - id: spell-lint + name: spell-lint + entry: scripts/spell-lint.sh + language: script + pass_filenames: true + description: Spellcheck files + - id: shell-lint name: shell-lint entry: scripts/shell-lint.sh @@ -45,6 +53,14 @@ repos: files: \.(sls|top)$ description: Lint Salt files + - id: yaml-lint + name: yaml-lint + entry: scripts/yaml-lint.sh + language: script + pass_filenames: true + files: \.(yaml|yml)$ + description: Lint YAML files + - id: qubesbuilder-gen name: qubesbuilder-gen entry: scripts/qubesbuilder-gen.sh @@ -53,14 +69,14 @@ repos: pass_filenames: false description: Check if .qubesbuilder is up to date -# TODO: generate temporary spec and compare against staged one. -# - id: spec-gen -# name: spec-gen -# language: script -# entry: scripts/spec-gen.sh test -# args: [test] -# # pass_filenames: true -# description: Check if RPM SPEC files are up to date + # TODO: generate temporary spec and compare against staged one. + # - id: spec-gen + # name: spec-gen + # language: script + # entry: scripts/spec-gen.sh test + # args: [test] + # # pass_filenames: true + # description: Check if RPM SPEC files are up to date - id: reuse-lint name: reuse-lint diff --git a/.reuse/dep5 b/.reuse/dep5 index 831dfff..a6402b4 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -11,6 +11,10 @@ Files: version salt/*/version Copyright: 2023 - 2024 Benjamin Grande M. S. License: CC0-1.0 +Files: dependencies/* +Copyright: 2024 Benjamin Grande M. S. +License: CC0-1.0 + Files: salt/electrum/files/client/keys/* Copyright: SomberNight/ghost43 Stephan Oeste diff --git a/.salt-lint b/.salt-lint.yaml similarity index 100% rename from .salt-lint rename to .salt-lint.yaml diff --git a/.yamllint b/.yamllint.yaml similarity index 93% rename from .yamllint rename to .yamllint.yaml index 76e4f96..695b3b3 100644 --- a/.yamllint +++ b/.yamllint.yaml @@ -11,8 +11,8 @@ ignore: | yaml-files: - '*.yaml' - '*.yml' - - .salt-lint - - .yamllint + +strict: true rules: empty-values: diff --git a/dependencies/debian.txt b/dependencies/debian.txt new file mode 100644 index 0000000..b059221 --- /dev/null +++ b/dependencies/debian.txt @@ -0,0 +1,11 @@ +codespell +git +gitlint +pre-commit +pylint +python3-dev +python3-pip +reuse +ruby-mdl +shellcheck +yamllint diff --git a/dependencies/pip.txt b/dependencies/pip.txt new file mode 100644 index 0000000..9d0c0b8 --- /dev/null +++ b/dependencies/pip.txt @@ -0,0 +1 @@ +salt-lint diff --git a/dependencies/rpm.txt b/dependencies/rpm.txt new file mode 100644 index 0000000..ab8cd84 --- /dev/null +++ b/dependencies/rpm.txt @@ -0,0 +1,4 @@ +dnf +dnf-plugins-core +rpm +rpmlint diff --git a/scripts/spell-lint.sh b/scripts/spell-lint.sh new file mode 100755 index 0000000..bfc26df --- /dev/null +++ b/scripts/spell-lint.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +## SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. +## +## SPDX-License-Identifier: AGPL-3.0-or-later + +# shellcheck disable=SC2086 +set -eu + +command -v git >/dev/null || { echo "Missing program: git" >&2; exit 1; } +cd "$(git rev-parse --show-toplevel)" || exit 1 +./scripts/requires-program.sh codespell + +if test -n "${1-}"; then + files="" + for f in "$@"; do + test -f "$f" || continue + case "$f" in + *LICENSES/*|.git/*|*.asc|rpm_spec/*-*.spec|*.muttrc| \ + salt/sys-cacher/files/server/conf/*_mirrors_*|\ + salt/dotfiles/files/vim/.config/vim/after/plugin/update-time.vim) + continue;; + *) files="$files $f";; + esac + done + test -n "$files" || exit 0 + exec codespell --check-filenames --check-hidden ${files} +fi + +exec codespell --check-filenames --check-hidden diff --git a/scripts/yaml-lint.sh b/scripts/yaml-lint.sh new file mode 100755 index 0000000..977fe1b --- /dev/null +++ b/scripts/yaml-lint.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +## SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. +## +## SPDX-License-Identifier: AGPL-3.0-or-later + +# shellcheck disable=SC2086 +set -eu + +command -v git >/dev/null || { echo "Missing program: git" >&2; exit 1; } +cd "$(git rev-parse --show-toplevel)" || exit 1 +./scripts/requires-program.sh yamllint + +if test -n "${1-}"; then + files="" + for f in "$@"; do + test -f "$f" || continue + extension="${f##*.}" + case "$extension" in + yaml|yml) files="$files $f";; + *) continue;; + esac + done + test -n "$files" || exit 0 + exec yamllint ${files} +fi + +exec yamllint .