aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2022-08-26 15:59:53 +0200
committerSebastiaan van Stijn <github@gone.nl>2022-08-29 19:52:56 +0200
commit6cef06b94031b15fb1a9dd4b84a0b19d93013b0b (patch)
treefae72f3b18a02980f54966676d00352af5dabd98
parent91bb776bb85a75e86760b406d5af46b651f044dd (diff)
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; - 30295c1750714d26f3c8fc9c3451f11ac351f2be - 8e8d9a36500fb07fa9d1b68539756b9a93d3509e 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>
-rwxr-xr-xhack/validate/default1
-rwxr-xr-xhack/validate/yamllint29
2 files changed, 30 insertions, 0 deletions
diff --git a/hack/validate/default b/hack/validate/default
index 88a4b95680..b48d9fa09c 100755
--- a/hack/validate/default
+++ b/hack/validate/default
@@ -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
diff --git a/hack/validate/yamllint b/hack/validate/yamllint
new file mode 100755
index 0000000000..1c663b1748
--- /dev/null
+++ b/hack/validate/yamllint
@@ -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