diff --git a/githooks/pre-commit/kubeapps b/githooks/pre-commit/kubeapps new file mode 100755 index 000000000..801421176 --- /dev/null +++ b/githooks/pre-commit/kubeapps @@ -0,0 +1,8 @@ +#!/bin/bash + +if git diff --name-only --cached | grep '/kubeapps/'; then + printf '\n\U1F6AB Commit cancelled\n\nKubeapps changes detected in this repository.\nPlease, implement them in the kubeapps repository (https://github.com/kubeapps/kubeapps/tree/master/chart/kubeapps).\n' + exit 1 +fi + +exit 0 diff --git a/githooks/pre-commit/upstreamed b/githooks/pre-commit/upstreamed new file mode 100755 index 000000000..b20e5c902 --- /dev/null +++ b/githooks/pre-commit/upstreamed @@ -0,0 +1,8 @@ +#!/bin/bash + +if git diff --name-only --cached | grep '/upstreamed/'; then + printf '\n\U1F6AB Commit cancelled\n\nChanges detected in the "upstreamed" folder.\nPlease, implement them in the Helm Charts repository (https://github.com/helm/charts).\n' + exit 1 +fi + +exit 0 diff --git a/githooks/pre-push/helm-lint b/githooks/pre-push/helm-lint new file mode 100755 index 000000000..edb088516 --- /dev/null +++ b/githooks/pre-push/helm-lint @@ -0,0 +1,34 @@ +#!/bin/bash + +currentBranch="$(git rev-parse --abbrev-ref HEAD)" +originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" +filesToBePushed="$(git diff --name-only "$originCommit")" +failed=0 + +for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do + # Avoid running 'helm lint|install' when modified dirs are not charts + if [[ $chartName = bitnami/* ]]; then + printf '\033[01;33mValidating %s:\n\033[0m' "$chartName" + chartPath="$(git rev-parse --show-toplevel)"/"$chartName" + + printf '\033[0;34m- Running helm lint %s\n\033[0m' "$chartPath" + if helm lint "$chartPath"; then + printf '\033[0;32m\U2705 helm lint %s\n\n\033[0m' "$chartPath" + else + printf '\033[0;31m\U1F6AB helm lint %s failed. Push cancelled.\n\n\033[0m' "$chartPath" + failed=1 + fi + + printf '\033\033[0;34m- Running helm install --dry-run %s\n\033[0m' "$chartPath" + helm repo add bitnami https://charts.bitnami.com/bitnami >> /dev/null + helm dependency update "$chartPath" >> /dev/null + if helm install --dry-run "$chartPath"; then + printf '\033[0;32m\U2705 helm install --dry-run %s\n\n\033[0m' "$chartPath" + else + printf '\033[0;31m\U1F6AB helm install --dry-run %s failed. Push cancelled.\n\n\033[0m' "$chartPath" + failed=1 + fi + fi +done + +exit $failed