Skip to content

Commit

Permalink
min-required correctly finds tagged release versions (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: Zordrak <Zordrak@users.noreply.github.com>
  • Loading branch information
mrpaws and Zordrak authored Jan 30, 2021
1 parent 7dc34a3 commit d63b34b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libexec/tfenv-min-required
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ see https://www.terraform.io/docs/configuration/terraform.html for details';
find_min_required() {
local root="${1}";

versions="$(grep -h -R required_version --include '*tf' "${root}"/* | tr -c -d '0-9. ~=!<>' )";
versions="$(grep -h -R required_version --include '*tf' "${root}"/* | grep -o '\([0-9]\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?')";

if [[ "${versions}" =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]* ]]; then
found_min_required="${BASH_REMATCH[1]}";
if [[ "${versions}" =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]*(-[a-z]+[0-9]+)? ]]; then
found_min_required="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"

if [[ "${found_min_required}" =~ ^!=.+ ]]; then
log 'debug' "Error: Min required version is a negation ($found_min_required) - we cannot guess the desired one.";
bailout;
else
found_min_required="$(echo "$found_min_required" | tr -c -d '0-9.')";
found_min_required="$(echo "$found_min_required")";
#echo "Min required version is detected as ${found_min_required}";
echo "${found_min_required}";
exit 0;
Expand Down
18 changes: 18 additions & 0 deletions test/test_use_minrequired.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ cleanup || log 'error' 'Cleanup failed?!';

v='0.8.8';
minv='0.8.0';
minv_tag='0.13.0-rc1'
(
tfenv install "${v}" || true;
tfenv use "${v}" || exit 1;
check_active_version "${v}" || exit 1;
) || error_and_proceed "Installing specific version ${v}";


log 'info' '### Install min-required normal version (#.#.#)';

echo "terraform {
required_version = \">=${minv}\"
Expand All @@ -73,6 +77,20 @@ check_active_version "${minv}" || error_and_proceed 'Min required version does n

cleanup || log 'error' 'Cleanup failed?!';

log 'info' '### Install min-required tagged version (#.#.#-tag#)'

echo "terraform {
required_version = \">=${minv_tag}\"
}" >> min_required.tf;

tfenv install min-required
tfenv use min-required

check_active_version "${minv_tag}" || error_and_proceed 'Min required version does not match';

cleanup || log 'error' 'Cleanup failed?!';

if [ "${#errors[@]}" -gt 0 ]; then
log 'warn' '===== The following use_minrequired tests failed =====';
for error in "${errors[@]}"; do
Expand Down

0 comments on commit d63b34b

Please sign in to comment.