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

min-required correctly finds tagged release versions #206

Merged
merged 2 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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