validate: add yamllint validation

validate other YAML files, such as the ones used in the documentation,
and GitHub actions workflows, to prevent issues such as;

- 30295c1750
- 8e8d9a3650

With this patch:

    hack/validate/yamllint
    Congratulations! yamllint config file formatted correctly
    Congratulations! YAML files are formatted correctly

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-08-26 15:59:53 +02:00
parent 91bb776bb8
commit 6cef06b940
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 30 additions and 0 deletions

View File

@ -8,6 +8,7 @@ export SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#. "${SCRIPTDIR}"/dco
. "${SCRIPTDIR}"/default-seccomp
. "${SCRIPTDIR}"/pkg-imports
. "${SCRIPTDIR}"/yamllint
. "${SCRIPTDIR}"/swagger
. "${SCRIPTDIR}"/swagger-gen
. "${SCRIPTDIR}"/toml

29
hack/validate/yamllint Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPTDIR}/.validate"
if [ -n "${TEST_FORCE_VALIDATE:-}" ]; then
files=(docs/api/*.yaml)
else
IFS=$'\n'
files=($(validate_diff --diff-filter=ACMR --name-only -- docs/*.yaml || true))
unset IFS
fi
# validate the yamllint configuration file before anything else
if out=$(yamllint -f parsable -d "{extends: default, rules: {document-start: disable}}" "${SCRIPTDIR}"/yamllint.yaml); then
echo "Congratulations! yamllint config file formatted correctly"
else
echo "${out}" >&2
false
fi
# Then validate GitHub actions workflows, and conditionally lint the swagger
# files in the docs directory, as these are large files and take some time.
if out=$(yamllint -f parsable -c "${SCRIPTDIR}"/yamllint.yaml .github/workflows/*.yml "${files[@]}"); then
echo "Congratulations! YAML files are formatted correctly"
else
echo "${out}" >&2
false
fi