diff --git a/README.md b/README.md index 8122beac9..4fe512c5f 100644 --- a/README.md +++ b/README.md @@ -114,10 +114,8 @@ Set `-e PRE_COMMIT_COLOR=never` to disable the color output in `pre-commit`.
MacOS
-[`coreutils`](https://formulae.brew.sh/formula/coreutils) is required for hooks on MacOS (due to use of `realpath`). - ```bash -brew install pre-commit terraform-docs tflint tfsec coreutils checkov terrascan infracost tfupdate jq +brew install pre-commit terraform-docs tflint tfsec checkov terrascan infracost tfupdate jq ```
diff --git a/hooks/_common.sh b/hooks/_common.sh index 3ff717dd0..d88dc80b4 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -69,7 +69,7 @@ function common::is_hook_run_on_whole_repo { shift 1 local -a -r files=("$@") # get directory containing `.pre-commit-hooks.yaml` file - local -r root_config_dir="$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")" + local -r root_config_dir="$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)")" # get included and excluded files from .pre-commit-hooks.yaml file local -r hook_config_block=$(sed -n "/^- id: $hook_id$/,/^$/p" "$root_config_dir/.pre-commit-hooks.yaml") local -r included_files=$(awk '$1 == "files:" {print $2; exit}' <<< "$hook_config_block") diff --git a/hooks/infracost_breakdown.sh b/hooks/infracost_breakdown.sh index 86fa86499..3e7ea00e7 100755 --- a/hooks/infracost_breakdown.sh +++ b/hooks/infracost_breakdown.sh @@ -6,7 +6,7 @@ set -eo pipefail # shellcheck disable=SC2034 # Unused var. readonly HOOK_ID='infracost_breakdown' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terraform_checkov.sh b/hooks/terraform_checkov.sh index e648b0ee1..8bbf335d6 100755 --- a/hooks/terraform_checkov.sh +++ b/hooks/terraform_checkov.sh @@ -6,7 +6,7 @@ set -eo pipefail # shellcheck disable=SC2034 # Unused var. readonly HOOK_ID='terraform_checkov' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 9bfc94003..254d28eec 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -6,7 +6,7 @@ set -eo pipefail # shellcheck disable=SC2034 # Unused var. readonly HOOK_ID='terraform_docs' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terraform_fmt.sh b/hooks/terraform_fmt.sh index 62e70810e..497625eaa 100755 --- a/hooks/terraform_fmt.sh +++ b/hooks/terraform_fmt.sh @@ -6,7 +6,7 @@ set -eo pipefail # shellcheck disable=SC2034 # Unused var. readonly HOOK_ID='terraform_fmt' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terraform_providers_lock.sh b/hooks/terraform_providers_lock.sh index 011ee45eb..423ff6c6c 100755 --- a/hooks/terraform_providers_lock.sh +++ b/hooks/terraform_providers_lock.sh @@ -6,7 +6,7 @@ set -eo pipefail # hook ID, see `- id` for details in .pre-commit-hooks.yaml file readonly HOOK_ID='terraform_providers_lock' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terraform_tflint.sh b/hooks/terraform_tflint.sh index 814781c8a..8bdc0aa4d 100755 --- a/hooks/terraform_tflint.sh +++ b/hooks/terraform_tflint.sh @@ -6,7 +6,7 @@ set -eo pipefail # hook ID, see `- id` for details in .pre-commit-hooks.yaml file readonly HOOK_ID='terraform_tflint' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terraform_tfsec.sh b/hooks/terraform_tfsec.sh index b9273827a..81d4315a2 100755 --- a/hooks/terraform_tfsec.sh +++ b/hooks/terraform_tfsec.sh @@ -5,7 +5,7 @@ set -eo pipefail # hook ID, see `- id` for details in .pre-commit-hooks.yaml file readonly HOOK_ID='terraform_tfsec' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terraform_validate.sh b/hooks/terraform_validate.sh index 13db4b060..7a0492dea 100755 --- a/hooks/terraform_validate.sh +++ b/hooks/terraform_validate.sh @@ -6,7 +6,7 @@ set -eo pipefail # shellcheck disable=SC2034 # Unused var. readonly HOOK_ID='terraform_validate' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" @@ -110,7 +110,7 @@ function terraform_validate_ { if [[ -n "$(find "$dir_path" -maxdepth 1 -name '*.tf' -print -quit)" ]]; then - pushd "$(realpath "$dir_path")" > /dev/null + pushd "$(cd "$dir_path" && pwd -P)" > /dev/null if [ ! -d .terraform ]; then set +e diff --git a/hooks/terragrunt_fmt.sh b/hooks/terragrunt_fmt.sh index b2a5b0684..8a3d2dfce 100755 --- a/hooks/terragrunt_fmt.sh +++ b/hooks/terragrunt_fmt.sh @@ -5,7 +5,7 @@ set -eo pipefail # hook ID, see `- id` for details in .pre-commit-hooks.yaml file readonly HOOK_ID='terragrunt_fmt' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terragrunt_validate.sh b/hooks/terragrunt_validate.sh index 589b823c8..a05fa19a8 100755 --- a/hooks/terragrunt_validate.sh +++ b/hooks/terragrunt_validate.sh @@ -5,7 +5,7 @@ set -eo pipefail # hook ID, see `- id` for details in .pre-commit-hooks.yaml file readonly HOOK_ID='terragrunt_validate' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/terrascan.sh b/hooks/terrascan.sh index 5c6415456..5ac37ef44 100755 --- a/hooks/terrascan.sh +++ b/hooks/terrascan.sh @@ -5,7 +5,7 @@ set -eo pipefail # hook ID, see `- id` for details in .pre-commit-hooks.yaml file readonly HOOK_ID='terrascan' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh" diff --git a/hooks/tfupdate.sh b/hooks/tfupdate.sh index 317c53c76..57524b830 100755 --- a/hooks/tfupdate.sh +++ b/hooks/tfupdate.sh @@ -5,7 +5,7 @@ set -eo pipefail # hook ID, see `- id` for details in .pre-commit-hooks.yaml file readonly HOOK_ID='tfupdate' # shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines -readonly SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" # shellcheck source=_common.sh . "$SCRIPT_DIR/_common.sh"