Skip to content

Commit 579dc45

Browse files
authored
feat: Improved speed of pre-commit run -a for multiple hooks (#338)
1 parent c266d40 commit 579dc45

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

hooks/terraform_tfsec.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,22 @@ function per_dir_hook_unique_part {
4343
return $exit_code
4444
}
4545

46+
#######################################################################
47+
# Unique part of `common::per_dir_hook`. The function is executed one time
48+
# in the root git repo
49+
# Arguments:
50+
# args (string with array) arguments that configure wrapped tool behavior
51+
#######################################################################
52+
function run_hook_on_whole_repo {
53+
local -r args="$1"
54+
55+
# pass the arguments to hook
56+
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
57+
tfsec "$(pwd)" ${args[@]}
58+
59+
# return exit code to common::per_dir_hook
60+
local exit_code=$?
61+
return $exit_code
62+
}
63+
4664
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"

hooks/terragrunt_fmt.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,22 @@ function per_dir_hook_unique_part {
4040
return $exit_code
4141
}
4242

43+
#######################################################################
44+
# Unique part of `common::per_dir_hook`. The function is executed one time
45+
# in the root git repo
46+
# Arguments:
47+
# args (string with array) arguments that configure wrapped tool behavior
48+
#######################################################################
49+
function run_hook_on_whole_repo {
50+
local -r args="$1"
51+
52+
# pass the arguments to hook
53+
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
54+
terragrunt hclfmt "$(pwd)" ${args[@]}
55+
56+
# return exit code to common::per_dir_hook
57+
local exit_code=$?
58+
return $exit_code
59+
}
60+
4361
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"

hooks/terragrunt_validate.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,22 @@ function per_dir_hook_unique_part {
4040
return $exit_code
4141
}
4242

43+
#######################################################################
44+
# Unique part of `common::per_dir_hook`. The function is executed one time
45+
# in the root git repo
46+
# Arguments:
47+
# args (string with array) arguments that configure wrapped tool behavior
48+
#######################################################################
49+
function run_hook_on_whole_repo {
50+
local -r args="$1"
51+
52+
# pass the arguments to hook
53+
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
54+
terragrunt run-all validate ${args[@]}
55+
56+
# return exit code to common::per_dir_hook
57+
local exit_code=$?
58+
return $exit_code
59+
}
60+
4361
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"

0 commit comments

Comments
 (0)