2022-01-06 17:09:51 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -eo pipefail
|
|
|
|
|
|
2022-02-10 16:53:37 +01:00
|
|
|
# globals variables
|
2022-01-06 17:09:51 +02:00
|
|
|
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
|
2022-04-18 19:17:15 +03:00
|
|
|
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
2022-01-06 17:09:51 +02:00
|
|
|
# shellcheck source=_common.sh
|
|
|
|
|
. "$SCRIPT_DIR/_common.sh"
|
|
|
|
|
|
|
|
|
|
function main {
|
|
|
|
|
common::initialize "$SCRIPT_DIR"
|
|
|
|
|
common::parse_cmdline "$@"
|
2022-07-06 15:41:28 +03:00
|
|
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
2022-04-26 13:33:58 +03:00
|
|
|
common::parse_and_export_env_vars
|
2022-07-06 15:34:13 +03:00
|
|
|
# JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never
|
|
|
|
|
|
2022-01-06 17:09:51 +02:00
|
|
|
# shellcheck disable=SC2153 # False positive
|
2022-10-06 19:16:29 +03:00
|
|
|
common::per_dir_hook "$HOOK_ID" "${#ARGS[@]}" "${ARGS[@]}" "${FILES[@]}"
|
2022-01-06 17:09:51 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-11 15:54:42 +02:00
|
|
|
#######################################################################
|
|
|
|
|
# Unique part of `common::per_dir_hook`. The function is executed in loop
|
|
|
|
|
# on each provided dir path. Run wrapped tool with specified arguments
|
|
|
|
|
# Arguments:
|
|
|
|
|
# dir_path (string) PATH to dir relative to git repo root.
|
|
|
|
|
# Can be used in error logging
|
2023-05-08 11:32:06 -04:00
|
|
|
# change_dir_in_unique_part (string/false) Modifier which creates
|
|
|
|
|
# possibilities to use non-common chdir strategies.
|
|
|
|
|
# Availability depends on hook.
|
2022-10-06 19:16:29 +03:00
|
|
|
# args (array) arguments that configure wrapped tool behavior
|
2022-01-11 15:54:42 +02:00
|
|
|
# Outputs:
|
|
|
|
|
# If failed - print out hook checks status
|
|
|
|
|
#######################################################################
|
2022-01-06 17:09:51 +02:00
|
|
|
function per_dir_hook_unique_part {
|
|
|
|
|
# shellcheck disable=SC2034 # Unused var.
|
2022-10-06 19:16:29 +03:00
|
|
|
local -r dir_path="$1"
|
2023-05-08 11:32:06 -04:00
|
|
|
# shellcheck disable=SC2034 # Unused var.
|
|
|
|
|
local -r change_dir_in_unique_part="$2"
|
|
|
|
|
shift 2
|
2022-10-06 19:16:29 +03:00
|
|
|
local -a -r args=("$@")
|
2022-01-06 17:09:51 +02:00
|
|
|
|
|
|
|
|
# pass the arguments to hook
|
2022-10-06 19:16:29 +03:00
|
|
|
terragrunt validate "${args[@]}"
|
2022-01-06 17:09:51 +02:00
|
|
|
|
|
|
|
|
# return exit code to common::per_dir_hook
|
|
|
|
|
local exit_code=$?
|
|
|
|
|
return $exit_code
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 20:48:17 +02:00
|
|
|
#######################################################################
|
|
|
|
|
# Unique part of `common::per_dir_hook`. The function is executed one time
|
|
|
|
|
# in the root git repo
|
|
|
|
|
# Arguments:
|
2022-10-06 19:16:29 +03:00
|
|
|
# args (array) arguments that configure wrapped tool behavior
|
2022-02-10 20:48:17 +02:00
|
|
|
#######################################################################
|
|
|
|
|
function run_hook_on_whole_repo {
|
2022-10-06 19:16:29 +03:00
|
|
|
local -a -r args=("$@")
|
2022-02-10 20:48:17 +02:00
|
|
|
|
|
|
|
|
# pass the arguments to hook
|
2022-10-06 19:16:29 +03:00
|
|
|
terragrunt run-all validate "${args[@]}"
|
2022-02-10 20:48:17 +02:00
|
|
|
|
|
|
|
|
# return exit code to common::per_dir_hook
|
|
|
|
|
local exit_code=$?
|
|
|
|
|
return $exit_code
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-06 17:09:51 +02:00
|
|
|
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"
|