summaryrefslogtreecommitdiff
path: root/hack/validate/yamllint
blob: 1c663b17481ffdd379570ec05509a0dd9cfd2865 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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