|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -eo pipefail |
| 3 | + |
| 4 | +# globals variables |
| 5 | +# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines |
| 6 | +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" |
| 7 | +# shellcheck source=_common.sh |
| 8 | +. "$SCRIPT_DIR/_common.sh" |
| 9 | + |
| 10 | +function main { |
| 11 | + common::initialize "$SCRIPT_DIR" |
| 12 | + common::parse_cmdline "$@" |
| 13 | + common::export_provided_env_vars "${ENV_VARS[@]}" |
| 14 | + common::parse_and_export_env_vars |
| 15 | + # JFYI: terragrunt providers lock color already suppressed via PRE_COMMIT_COLOR=never |
| 16 | + |
| 17 | + # shellcheck disable=SC2153 # False positive |
| 18 | + common::per_dir_hook "$HOOK_ID" "${#ARGS[@]}" "${ARGS[@]}" "${FILES[@]}" |
| 19 | +} |
| 20 | + |
| 21 | +####################################################################### |
| 22 | +# Unique part of `common::per_dir_hook`. The function is executed in loop |
| 23 | +# on each provided dir path. Run wrapped tool with specified arguments |
| 24 | +# Arguments: |
| 25 | +# dir_path (string) PATH to dir relative to git repo root. |
| 26 | +# Can be used in error logging |
| 27 | +# change_dir_in_unique_part (string/false) Modifier which creates |
| 28 | +# possibilities to use non-common chdir strategies. |
| 29 | +# Availability depends on hook. |
| 30 | +# parallelism_disabled (bool) if true - skip lock mechanism |
| 31 | +# args (array) arguments that configure wrapped tool behavior |
| 32 | +# Outputs: |
| 33 | +# If failed - print out hook checks status |
| 34 | +####################################################################### |
| 35 | +function per_dir_hook_unique_part { |
| 36 | + # shellcheck disable=SC2034 # Unused var. |
| 37 | + local -r dir_path="$1" |
| 38 | + # shellcheck disable=SC2034 # Unused var. |
| 39 | + local -r change_dir_in_unique_part="$2" |
| 40 | + # shellcheck disable=SC2034 # Unused var. |
| 41 | + local -r parallelism_disabled="$3" |
| 42 | + shift 3 |
| 43 | + local -a -r args=("$@") |
| 44 | + |
| 45 | + # pass the arguments to hook |
| 46 | + terragrunt providers lock "${args[@]}" |
| 47 | + |
| 48 | + # return exit code to common::per_dir_hook |
| 49 | + local exit_code=$? |
| 50 | + return $exit_code |
| 51 | +} |
| 52 | + |
| 53 | +####################################################################### |
| 54 | +# Unique part of `common::per_dir_hook`. The function is executed one time |
| 55 | +# in the root git repo |
| 56 | +# Arguments: |
| 57 | +# args (array) arguments that configure wrapped tool behavior |
| 58 | +####################################################################### |
| 59 | +function run_hook_on_whole_repo { |
| 60 | + local -a -r args=("$@") |
| 61 | + |
| 62 | + # pass the arguments to hook |
| 63 | + terragrunt run-all providers lock "${args[@]}" |
| 64 | + |
| 65 | + # return exit code to common::per_dir_hook |
| 66 | + local exit_code=$? |
| 67 | + return $exit_code |
| 68 | +} |
| 69 | + |
| 70 | +[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@" |
0 commit comments