Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for version constraints in tfupdate #436

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Add support for version constraints in tfupdate
  • Loading branch information
MaxymVlasov committed Oct 3, 2022
commit 8e7a029eb1f796f1ff60ad8e07b911466381cdd1
69 changes: 65 additions & 4 deletions hooks/tfupdate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,41 @@ function per_dir_hook_unique_part {
local -r args="$1"
# shellcheck disable=SC2034 # Unused var.
local -r dir_path="$2"
#
# Expand array, but not substrings inside it.
# If no substrings - execute hook.
#
if [[ "$args" == *'"'* ]]; then
IFS='"' read -r expand_args version version2 <<< "$args"
elif [[ "$args" == *"'"* ]]; then
IFS="'" read -r expand_args version version2 <<< "$args"
else
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
tfupdate ${args[@]} .
# return exit code to common::per_dir_hook
local exit_code=$?
return $exit_code
fi

# Check that user pass vars to hook in right order.
# If not - swap elements to right order.
# Without this fix, wrong order make hook as PASSED for unknown reason.

# right order result:
# expand_args: provider aws --version
# version: ~> 4.2.0
# version2:
# wrong order result:
# expand_args: --version
# version: ~> 4.2.0
# version2: provider aws
if [[ -n $version2 ]]; then
expand_args="$version2 $expand_args"
fi

# pass the arguments to hook
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
tfupdate ${args[@]} .
tfupdate ${expand_args[@]} "$version" .

# return exit code to common::per_dir_hook
local exit_code=$?
Expand All @@ -49,11 +80,41 @@ function per_dir_hook_unique_part {
#######################################################################
function run_hook_on_whole_repo {
local -r args="$1"
#
# Expand array, but not substrings inside it.
# If no substrings - execute hook.
#
if [[ "$args" == *'"'* ]]; then
IFS='"' read -r expand_args version version2 <<< "$args"
elif [[ "$args" == *"'"* ]]; then
IFS="'" read -r expand_args version version2 <<< "$args"
else
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
tfupdate ${args[@]} --recursive .
# return exit code to common::per_dir_hook
local exit_code=$?
return $exit_code
fi

# Check that user pass args to hook in right order.
# If not - swap elements to right order.
# Without this fix, wrong order make hook as PASSED for unknown reason.

# right order result:
# expand_args: provider aws --version
# version: ~> 4.2.0
# version2:
# wrong order result:
# expand_args: --version
# version: ~> 4.2.0
# version2: provider aws
if [[ -n $version2 ]]; then
expand_args="$version2 $expand_args"
fi

# pass the arguments to hook
# shellcheck disable=SC2068 # hook fails when quoting is used ("$arg[@]")
# shellcheck disable=SC2048 # Use "${array[@]}" (with quotes) to prevent whitespace problems.
# shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting.
tfupdate ${args[*]} --recursive .
tfupdate ${expand_args[@]} "$version" --recursive .

# return exit code to common::per_dir_hook
local exit_code=$?
Expand Down