Skip to content

Commit a2a2990

Browse files
fix(non-linux): Bash environment variables in arguments not expanded + Add trace log level (#645)
--------- Co-authored-by: George L. Yermulnik <[email protected]>
1 parent 051dcd5 commit a2a2990

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ If you are using `pre-commit-terraform` already or want to support its developme
3838
* [All hooks: Usage of environment variables in `--args`](#all-hooks-usage-of-environment-variables-in---args)
3939
* [All hooks: Set env vars inside hook at runtime](#all-hooks-set-env-vars-inside-hook-at-runtime)
4040
* [All hooks: Disable color output](#all-hooks-disable-color-output)
41+
* [All hooks: Log levels](#all-hooks-log-levels)
4142
* [Many hooks: Parallelism](#many-hooks-parallelism)
4243
* [checkov (deprecated) and terraform\_checkov](#checkov-deprecated-and-terraform_checkov)
4344
* [infracost\_breakdown](#infracost_breakdown)
@@ -341,6 +342,18 @@ To disable color output for all hooks, set `PRE_COMMIT_COLOR=never` var. Eg:
341342
PRE_COMMIT_COLOR=never pre-commit run
342343
```
343344

345+
### All hooks: Log levels
346+
347+
In case you need to debug hooks, you can set `PCT_LOG=trace`.
348+
349+
For example:
350+
351+
```bash
352+
PCT_LOG=trace pre-commit run -a
353+
```
354+
355+
Less verbose log levels will be implemented in [#562](https://github.com/antonbabenko/pre-commit-terraform/issues/562).
356+
344357
### Many hooks: Parallelism
345358

346359
> All, except deprecated hooks: `checkov`, `terraform_docs_replace` and hooks which can't be paralleled this way: `infracost_breakdown`, `terraform_wrapper_module_for_each`.

hooks/_common.sh

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4+
if [[ $PCT_LOG == trace ]]; then
5+
6+
echo "BASH path: '$BASH'"
7+
echo "BASH_VERSION: $BASH_VERSION"
8+
echo "BASHOPTS: $BASHOPTS"
9+
echo "OSTYPE: $OSTYPE"
10+
11+
# ${FUNCNAME[*]} - function calls in reversed order. Each new function call is appended to the beginning
12+
# ${BASH_SOURCE##*/} - get filename
13+
# $LINENO - get line number
14+
export PS4='\e[2m
15+
trace: ${FUNCNAME[*]}
16+
${BASH_SOURCE##*/}:$LINENO: \e[0m'
17+
18+
set -x
19+
fi
420
# Hook ID, based on hook filename.
521
# Hook filename MUST BE same with `- id` in .pre-commit-hooks.yaml file
622
# shellcheck disable=SC2034 # Unused var.
@@ -112,7 +128,7 @@ function common::parse_and_export_env_vars {
112128
while true; do
113129
# Check if at least 1 env var exists in `$arg`
114130
# shellcheck disable=SC2016 # '${' should not be expanded
115-
if [[ "$arg" =~ .*'${'[A-Z_][A-Z0-9_]+?'}'.* ]]; then
131+
if [[ "$arg" =~ '${'[A-Z_][A-Z0-9_]*'}' ]]; then
116132
# Get `ENV_VAR` from `.*${ENV_VAR}.*`
117133
local env_var_name=${arg#*$\{}
118134
env_var_name=${env_var_name%%\}*}

0 commit comments

Comments
 (0)