Files
charts/githooks/pre-push/kubeval
Javier J. Salmeron Garcia b091fc863a Add githook to folder
2019-10-02 18:24:44 +03:00

31 lines
922 B
Bash
Executable File

#!/bin/bash
repo_path="$(git rev-parse --show-toplevel)"
current_branch="$(git rev-parse --abbrev-ref HEAD)"
origin_commit="$(git rev-parse --short "$(git merge-base master "$current_branch")")"
files_to_push="$(git diff --name-only "$origin_commit")"
# shellcheck source=../functions/libkubeval.sh
. "${repo_path}/githooks/functions/libkubeval.sh"
failed=0
for chart_name in $( cut -d'/' -f1,2 <<< "$files_to_push" | uniq ); do
check_kubeval
# Avoid running 'kubeval' when modified dirs are not charts
if [[ $chart_name = bitnami/* ]]; then
printf '\033[01;33mValidating %s with kubeval:\n\033[0m' "$chart_name"
if ! run_kubeval_chart "$chart_name"; then
failed=1
fi
fi
done
if [[ "$failed" = "1" ]]; then
printf '\033[0;31m\U0001F6AB Kubeval failed. Not pushing\n\n\033[0m'
else
printf '\033[0;32m\U00002705 Kubeval succeeded\n\n\033[0m'
fi
exit $failed