39 lines
1.1 KiB
Bash
Executable File
39 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
set +o xtrace -o errexit -o nounset -o pipefail
|
|
|
|
#
|
|
# Manual check in terminal:
|
|
#
|
|
# ansible-lint ./*.yml
|
|
#
|
|
|
|
export ANSIBLE_ROLES_PATH="$PWD/roles"
|
|
FILES_PATTERN='\.yml$'
|
|
EXIT_CODE=0
|
|
|
|
# Output to stderr
|
|
exec 1>&2
|
|
|
|
CHANGED_FILES=()
|
|
for FILE in $(git diff --cached --name-only --diff-filter=ACM | grep --extended-regexp "${FILES_PATTERN}" | grep -Ev '^\.circleci'); do
|
|
CHANGED_FILES+=("${FILE}")
|
|
done
|
|
|
|
if [ 0 -eq "${#CHANGED_FILES[@]}" ]; then
|
|
echo "No changed files matching '${FILES_PATTERN}'"
|
|
else
|
|
# echo "Running ansible-lint --write..."
|
|
# Have to add the playbooks in the root to make ansible-lint detect every problem
|
|
# ansible-lint -qq --write --nocolor "${CHANGED_FILES[@]}" >/dev/null && true
|
|
# ansible-lint -qq --skip-list 'yaml[line-length],jinja[spacing]' --write --nocolor ./*.yml
|
|
# git add "${CHANGED_FILES[@]}"
|
|
echo -e "Running ansible-lint...\n"
|
|
# set -o xtrace
|
|
ansible-lint --format full ./*.yml "${CHANGED_FILES[@]}"
|
|
{ set +o xtrace; } 2>/dev/null
|
|
EXIT_CODE="$?"
|
|
fi
|
|
|
|
echo "Exit code ${EXIT_CODE}"
|
|
exit "${EXIT_CODE}"
|