From 579dc45fb40bc64c6742d42a9da78eddb0b70e1d Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Thu, 10 Feb 2022 20:48:17 +0200 Subject: [PATCH] feat: Improved speed of `pre-commit run -a` for multiple hooks (#338) --- hooks/terraform_tfsec.sh | 18 ++++++++++++++++++ hooks/terragrunt_fmt.sh | 18 ++++++++++++++++++ hooks/terragrunt_validate.sh | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/hooks/terraform_tfsec.sh b/hooks/terraform_tfsec.sh index b46dff426..b9273827a 100755 --- a/hooks/terraform_tfsec.sh +++ b/hooks/terraform_tfsec.sh @@ -43,4 +43,22 @@ function per_dir_hook_unique_part { return $exit_code } +####################################################################### +# Unique part of `common::per_dir_hook`. The function is executed one time +# in the root git repo +# Arguments: +# args (string with array) arguments that configure wrapped tool behavior +####################################################################### +function run_hook_on_whole_repo { + local -r args="$1" + + # pass the arguments to hook + # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") + tfsec "$(pwd)" ${args[@]} + + # return exit code to common::per_dir_hook + local exit_code=$? + return $exit_code +} + [ "${BASH_SOURCE[0]}" != "$0" ] || main "$@" diff --git a/hooks/terragrunt_fmt.sh b/hooks/terragrunt_fmt.sh index 4822fc3f8..b2a5b0684 100755 --- a/hooks/terragrunt_fmt.sh +++ b/hooks/terragrunt_fmt.sh @@ -40,4 +40,22 @@ function per_dir_hook_unique_part { return $exit_code } +####################################################################### +# Unique part of `common::per_dir_hook`. The function is executed one time +# in the root git repo +# Arguments: +# args (string with array) arguments that configure wrapped tool behavior +####################################################################### +function run_hook_on_whole_repo { + local -r args="$1" + + # pass the arguments to hook + # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") + terragrunt hclfmt "$(pwd)" ${args[@]} + + # return exit code to common::per_dir_hook + local exit_code=$? + return $exit_code +} + [ "${BASH_SOURCE[0]}" != "$0" ] || main "$@" diff --git a/hooks/terragrunt_validate.sh b/hooks/terragrunt_validate.sh index 58e20c46e..589b823c8 100755 --- a/hooks/terragrunt_validate.sh +++ b/hooks/terragrunt_validate.sh @@ -40,4 +40,22 @@ function per_dir_hook_unique_part { return $exit_code } +####################################################################### +# Unique part of `common::per_dir_hook`. The function is executed one time +# in the root git repo +# Arguments: +# args (string with array) arguments that configure wrapped tool behavior +####################################################################### +function run_hook_on_whole_repo { + local -r args="$1" + + # pass the arguments to hook + # shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]") + terragrunt run-all validate ${args[@]} + + # return exit code to common::per_dir_hook + local exit_code=$? + return $exit_code +} + [ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"