From c88d24756c3d1410a5bd9dc48ac518c49b1798dd Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Hernandez Date: Mon, 9 Sep 2019 14:29:14 +0000 Subject: [PATCH 1/7] Add git pre-push hooks --- githooks/pre-push/helm-lint | 34 ++++++++++++++++++++++++++++++++++ githooks/pre-push/kubeapps | 7 +++++++ githooks/pre-push/upstreamed | 7 +++++++ 3 files changed, 48 insertions(+) create mode 100644 githooks/pre-push/helm-lint create mode 100644 githooks/pre-push/kubeapps create mode 100644 githooks/pre-push/upstreamed diff --git a/githooks/pre-push/helm-lint b/githooks/pre-push/helm-lint new file mode 100644 index 000000000..f850fd1aa --- /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=false + +for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do + 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" + failed=true + 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" + failed=true + fi +done + +if $failed ; then + exit 1 +fi +exit 0 diff --git a/githooks/pre-push/kubeapps b/githooks/pre-push/kubeapps new file mode 100644 index 000000000..d910cffb7 --- /dev/null +++ b/githooks/pre-push/kubeapps @@ -0,0 +1,7 @@ +#!/bin/bash + +if git diff --name-only --cached origin/master | grep '/kubeapps/'; then + printf '\n\U1F6AB Pull Request 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' +fi + +exit 0 diff --git a/githooks/pre-push/upstreamed b/githooks/pre-push/upstreamed new file mode 100644 index 000000000..f60e9ad61 --- /dev/null +++ b/githooks/pre-push/upstreamed @@ -0,0 +1,7 @@ +#!/bin/bash + +if git diff --name-only --cached origin/master | grep '/upstreamed/'; then + printf '\n\U1F6AB Pull Request cancelled\n\nChanges detected in the "upstreamed" folder.\nPlease, implement them in the Helm Charts repository (https://github.com/helm/charts).\n' +fi + +exit 0 From f3cadffeb09b0a45bcb933e04fd0b0264a752e1c Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Hernandez Date: Mon, 9 Sep 2019 14:46:38 +0000 Subject: [PATCH 2/7] Fix diff --- githooks/pre-push/kubeapps | 7 ++++++- githooks/pre-push/upstreamed | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/githooks/pre-push/kubeapps b/githooks/pre-push/kubeapps index d910cffb7..633b78855 100644 --- a/githooks/pre-push/kubeapps +++ b/githooks/pre-push/kubeapps @@ -1,7 +1,12 @@ #!/bin/bash -if git diff --name-only --cached origin/master | grep '/kubeapps/'; then +currentBranch="$(git rev-parse --abbrev-ref HEAD)" +originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" +filesToBePushed="$(git diff --name-only "$originCommit")" + +if $filesToBePushed | grep '/kubeapps/'; then printf '\n\U1F6AB Pull Request 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-push/upstreamed b/githooks/pre-push/upstreamed index f60e9ad61..0f71bde6c 100644 --- a/githooks/pre-push/upstreamed +++ b/githooks/pre-push/upstreamed @@ -1,7 +1,12 @@ #!/bin/bash -if git diff --name-only --cached origin/master | grep '/upstreamed/'; then +currentBranch="$(git rev-parse --abbrev-ref HEAD)" +originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" +filesToBePushed="$(git diff --name-only "$originCommit")" + +if $filesToBePushed | grep '/upstreamed/'; then printf '\n\U1F6AB Pull Request 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 From c4f6af22f8529aa1f34378d402379a5726f7b4a2 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Hernandez Date: Mon, 9 Sep 2019 14:53:46 +0000 Subject: [PATCH 3/7] Fix if condition --- githooks/pre-push/kubeapps | 3 +-- githooks/pre-push/upstreamed | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/githooks/pre-push/kubeapps b/githooks/pre-push/kubeapps index 633b78855..0f2e27f7f 100644 --- a/githooks/pre-push/kubeapps +++ b/githooks/pre-push/kubeapps @@ -2,9 +2,8 @@ currentBranch="$(git rev-parse --abbrev-ref HEAD)" originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" -filesToBePushed="$(git diff --name-only "$originCommit")" -if $filesToBePushed | grep '/kubeapps/'; then +if git diff --name-only "$originCommit" | grep '/kubeapps/'; then printf '\n\U1F6AB Pull Request 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 diff --git a/githooks/pre-push/upstreamed b/githooks/pre-push/upstreamed index 0f71bde6c..ac96e884f 100644 --- a/githooks/pre-push/upstreamed +++ b/githooks/pre-push/upstreamed @@ -2,9 +2,8 @@ currentBranch="$(git rev-parse --abbrev-ref HEAD)" originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" -filesToBePushed="$(git diff --name-only "$originCommit")" -if $filesToBePushed | grep '/upstreamed/'; then +if git diff --name-only "$originCommit" | grep '/upstreamed/'; then printf '\n\U1F6AB Pull Request 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 From ac913e8b60ecc5f551d7e7b5672c41167fa1b55e Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Hernandez Date: Mon, 9 Sep 2019 15:12:26 +0000 Subject: [PATCH 4/7] Several fixes --- githooks/{pre-push => pre-commit}/kubeapps | 5 +---- githooks/{pre-push => pre-commit}/upstreamed | 5 +---- githooks/pre-push/helm-lint | 2 ++ 3 files changed, 4 insertions(+), 8 deletions(-) rename githooks/{pre-push => pre-commit}/kubeapps (55%) mode change 100644 => 100755 rename githooks/{pre-push => pre-commit}/upstreamed (51%) mode change 100644 => 100755 mode change 100644 => 100755 githooks/pre-push/helm-lint diff --git a/githooks/pre-push/kubeapps b/githooks/pre-commit/kubeapps old mode 100644 new mode 100755 similarity index 55% rename from githooks/pre-push/kubeapps rename to githooks/pre-commit/kubeapps index 0f2e27f7f..29f831425 --- a/githooks/pre-push/kubeapps +++ b/githooks/pre-commit/kubeapps @@ -1,9 +1,6 @@ #!/bin/bash -currentBranch="$(git rev-parse --abbrev-ref HEAD)" -originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" - -if git diff --name-only "$originCommit" | grep '/kubeapps/'; then +if git diff --name-only --cached | grep '/kubeapps/'; then printf '\n\U1F6AB Pull Request 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 diff --git a/githooks/pre-push/upstreamed b/githooks/pre-commit/upstreamed old mode 100644 new mode 100755 similarity index 51% rename from githooks/pre-push/upstreamed rename to githooks/pre-commit/upstreamed index ac96e884f..7e4e60255 --- a/githooks/pre-push/upstreamed +++ b/githooks/pre-commit/upstreamed @@ -1,9 +1,6 @@ #!/bin/bash -currentBranch="$(git rev-parse --abbrev-ref HEAD)" -originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" - -if git diff --name-only "$originCommit" | grep '/upstreamed/'; then +if git diff --name-only --cached | grep '/upstreamed/'; then printf '\n\U1F6AB Pull Request 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 diff --git a/githooks/pre-push/helm-lint b/githooks/pre-push/helm-lint old mode 100644 new mode 100755 index f850fd1aa..3324602d0 --- a/githooks/pre-push/helm-lint +++ b/githooks/pre-push/helm-lint @@ -1,5 +1,7 @@ #!/bin/bash +## TODO: Only check folders in the bitnami/ path + currentBranch="$(git rev-parse --abbrev-ref HEAD)" originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" filesToBePushed="$(git diff --name-only "$originCommit")" From d860bcba063eb78765440dc1e1e11c6c1a75152a Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Hernandez Date: Mon, 9 Sep 2019 15:56:35 +0000 Subject: [PATCH 5/7] Only run helm commands when charts are modified --- githooks/pre-push/helm-lint | 41 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/githooks/pre-push/helm-lint b/githooks/pre-push/helm-lint index 3324602d0..63492aa9d 100755 --- a/githooks/pre-push/helm-lint +++ b/githooks/pre-push/helm-lint @@ -1,32 +1,33 @@ #!/bin/bash -## TODO: Only check folders in the bitnami/ path - currentBranch="$(git rev-parse --abbrev-ref HEAD)" originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" filesToBePushed="$(git diff --name-only "$originCommit")" failed=false for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do - printf '\033[01;33mValidating %s:\n\033[0m' "$chartName" - chartPath="$(git rev-parse --show-toplevel)"/"$chartName" + # 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" - failed=true - 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" - failed=true + 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" + failed=true + 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" + failed=true + fi fi done From e75f1fca2b88ef577793e93c7b813cf8330ee090 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Hernandez Date: Tue, 10 Sep 2019 08:10:10 +0000 Subject: [PATCH 6/7] Implement suggestions --- githooks/pre-commit/kubeapps | 2 +- githooks/pre-commit/upstreamed | 2 +- githooks/pre-push/helm-lint | 11 ++++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/githooks/pre-commit/kubeapps b/githooks/pre-commit/kubeapps index 29f831425..801421176 100755 --- a/githooks/pre-commit/kubeapps +++ b/githooks/pre-commit/kubeapps @@ -1,7 +1,7 @@ #!/bin/bash if git diff --name-only --cached | grep '/kubeapps/'; then - printf '\n\U1F6AB Pull Request 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' + 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 diff --git a/githooks/pre-commit/upstreamed b/githooks/pre-commit/upstreamed index 7e4e60255..b20e5c902 100755 --- a/githooks/pre-commit/upstreamed +++ b/githooks/pre-commit/upstreamed @@ -1,7 +1,7 @@ #!/bin/bash if git diff --name-only --cached | grep '/upstreamed/'; then - printf '\n\U1F6AB Pull Request cancelled\n\nChanges detected in the "upstreamed" folder.\nPlease, implement them in the Helm Charts repository (https://github.com/helm/charts).\n' + 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 diff --git a/githooks/pre-push/helm-lint b/githooks/pre-push/helm-lint index 63492aa9d..ea5ff33f4 100755 --- a/githooks/pre-push/helm-lint +++ b/githooks/pre-push/helm-lint @@ -3,7 +3,7 @@ currentBranch="$(git rev-parse --abbrev-ref HEAD)" originCommit="$(git rev-parse --short "$(git merge-base master "$currentBranch")")" filesToBePushed="$(git diff --name-only "$originCommit")" -failed=false +failed=0 for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do # Avoid running 'helm lint|install' when modified dirs are not charts @@ -16,7 +16,7 @@ for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do printf '\033[0;32m\U2705 helm lint %s\n\n\033[0m' "$chartPath" else printf '\033[0;31m\U1F6AB helm lint %s failed. Pull Request cancelled.\n\n\033[0m' "$chartPath" - failed=true + failed=1 fi printf '\033\033[0;34m- Running helm install --dry-run %s\n\033[0m' "$chartPath" @@ -26,12 +26,9 @@ for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" - failed=true + failed=1 fi fi done -if $failed ; then - exit 1 -fi -exit 0 +exit $failed From be1c69e35ca0294e0e0faab78809961cb613102c Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Hernandez Date: Tue, 10 Sep 2019 08:54:30 +0000 Subject: [PATCH 7/7] Implement suggestions 2 --- githooks/pre-push/helm-lint | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/githooks/pre-push/helm-lint b/githooks/pre-push/helm-lint index ea5ff33f4..edb088516 100755 --- a/githooks/pre-push/helm-lint +++ b/githooks/pre-push/helm-lint @@ -15,7 +15,7 @@ for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" + printf '\033[0;31m\U1F6AB helm lint %s failed. Push cancelled.\n\n\033[0m' "$chartPath" failed=1 fi @@ -25,7 +25,7 @@ for chartName in $( cut -d'/' -f1,2 <<< "$filesToBePushed" | uniq ); do 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. Pull Request cancelled.\n\n\033[0m' "$chartPath" + printf '\033[0;31m\U1F6AB helm install --dry-run %s failed. Push cancelled.\n\n\033[0m' "$chartPath" failed=1 fi fi