From 5da4803927ded202f9efc0ebf7395ccd3b1819a7 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 21 Apr 2023 13:27:28 +0000 Subject: [PATCH] chore(release): version 1.77.3 [skip ci] ## [1.77.3](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.77.2...v1.77.3) (2023-04-21) ### Bug Fixes * Updates all dependencies used in Dockerfile and fix Docker image ([#507](https://github.com/antonbabenko/pre-commit-terraform/issues/507)) ([dc177fe](https://github.com/antonbabenko/pre-commit-terraform/commit/dc177fe29ed250fbb98702248c7de232bdb75f58)) --- CHANGELOG.md | 7 +++++++ hooks/_common.sh | 19 +++++++++++++++++-- hooks/terraform_tflint.sh | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aefce7346..5e366b8b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [1.77.3](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.77.2...v1.77.3) (2023-04-21) + + +### Bug Fixes + +* Updates all dependencies used in Dockerfile and fix Docker image ([#507](https://github.com/antonbabenko/pre-commit-terraform/issues/507)) ([dc177fe](https://github.com/antonbabenko/pre-commit-terraform/commit/dc177fe29ed250fbb98702248c7de232bdb75f58)) + ## [1.77.2](https://github.com/antonbabenko/pre-commit-terraform/compare/v1.77.1...v1.77.2) (2023-04-09) diff --git a/hooks/_common.sh b/hooks/_common.sh index 37b32d842..b73aef711 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -226,7 +226,10 @@ function common::per_dir_hook { # run hook for each path for dir_path in $(echo "${dir_paths[*]}" | tr ' ' '\n' | sort -u); do dir_path="${dir_path//__REPLACED__SPACE__/ }" - pushd "$dir_path" > /dev/null || continue + + if common::check_config_hook_flag_set "--skip-chdir"; then + pushd "$dir_path" > /dev/null || continue + fi per_dir_hook_unique_part "$dir_path" "${args[@]}" @@ -235,7 +238,10 @@ function common::per_dir_hook { final_exit_code=$exit_code fi - popd > /dev/null + if common::check_config_hook_flag_set "--skip-chdir"; then + popd > /dev/null + fi + done # restore errexit if it was set before the "for" loop @@ -334,3 +340,12 @@ function common::export_provided_env_vars { export $var_name="$var_value" done } + +####################################################################### +# Check if the conifg hook is set in the hook config +# Arguments: +# flag (string) name of the flag to check in the hook config +####################################################################### +function common::check_config_hook_flag_set { + [[ "${HOOK_CONFIG[*]}" =~ (^|[[:space:]])"${1};"($|[[:space:]]) ]] +} diff --git a/hooks/terraform_tflint.sh b/hooks/terraform_tflint.sh index d488cb734..98530e793 100755 --- a/hooks/terraform_tflint.sh +++ b/hooks/terraform_tflint.sh @@ -13,6 +13,12 @@ function main { common::parse_cmdline "$@" common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars + + # TODO: Switch the default behaviour in 2.0 + # if ! common::check_config_hook_flag_set "--skip-chdir"; then + # HOOK_CONFIG+=("--skip-chdir;") + # fi + # Support for setting PATH to repo root. for i in "${!ARGS[@]}"; do ARGS[i]=${ARGS[i]/__GIT_WORKING_DIR__/$(pwd)\/} @@ -50,12 +56,17 @@ function per_dir_hook_unique_part { shift local -a -r args=("$@") + DIR_ARGS="" + if common::check_config_hook_flag_set "--skip-chdir"; then + DIR_ARGS="--chdir=$dir_path" + fi + # Print checked PATH **only** if TFLint have any messages # shellcheck disable=SC2091,SC2068 # Suppress error output - $(tflint ${args[@]} 2>&1) 2> /dev/null || { + $(tflint "$DIR_ARGS" ${args[@]} 2>&1) 2> /dev/null || { common::colorify "yellow" "TFLint in $dir_path/:" - tflint "${args[@]}" + tflint "$DIR_ARGS" "${args[@]}" } # return exit code to common::per_dir_hook