mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
feat: Improve performance during pre-commit --all (-a) run (#327)
This commit is contained in:
parent
a80d3835d4
commit
7e7c91643e
11 changed files with 106 additions and 7 deletions
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
# globals variables
|
||||
# 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]}")")"
|
||||
# shellcheck source=_common.sh
|
||||
|
|
@ -10,7 +13,7 @@ function main {
|
|||
common::initialize "$SCRIPT_DIR"
|
||||
common::parse_cmdline "$@"
|
||||
# shellcheck disable=SC2153 # False positive
|
||||
common::per_dir_hook "${ARGS[*]}" "${FILES[@]}"
|
||||
common::per_dir_hook "${ARGS[*]}" "$HOOK_ID" "${FILES[@]}"
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
|
|
@ -37,4 +40,22 @@ function per_dir_hook_unique_part {
|
|||
return $exit_code
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
# Unique part of `common::per_dir_hook`. The function is executed one time
|
||||
# in the root git repo
|
||||
# Arguments:
|
||||
# args (string with array) arguments that configure wrapped tool behavior
|
||||
#######################################################################
|
||||
function run_hook_on_whole_repo {
|
||||
local -r args="$1"
|
||||
|
||||
# pass the arguments to hook
|
||||
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
|
||||
terrascan scan -i terraform ${args[@]}
|
||||
|
||||
# return exit code to common::per_dir_hook
|
||||
local exit_code=$?
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue