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

Conversation

mrpaws
Copy link
Contributor

@mrpaws mrpaws commented Aug 4, 2020

Problem: 'tfenv <install|use> min-required' incorrectly interprets a tagged release (ie rc1,beta2,alpha3).

For example, ">=0.13.0-rc1" is mangled by the translation and results in interpreting min-required as "0.13.1". This is a bug because at worst results can install and use an undesired version, but mostly is annoying for testing tagged versions.

Solution
The solution is to use a basic regex with 'grep' instead of 'tr' to properly acquire both normal and tagged release versions. An extra test was added to account for this; the results are below.

Notes

  • This makes 'tfenv min-required' usable with every release of terraform to date (https://releases.hashicorp.com/terraform/) - - 'grep' is used with basic regex instead of an extended regular expression (egrep/grep -E) to facilitate maximum cross-compatibility between platforms and varying implementations of grep.

Problem in practice (debug):

++ grep -h -R required_version --include '*tf' <FILES SCANNED>
++ tr -c -d '0-9. ~=!<>'
+ versions='     = >=0.13.01'
+ [[      = >=0.13.01 =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]* ]]
+ found_min_required='>=0.13.01'
+ [[ >=0.13.01 =~ ^!=.+ ]]
++ echo '>=0.13.01'
++ tr -c -d 0-9.
+ found_min_required=0.13.01
+ echo 0.13.01
+ exit 0
No installed versions of terraform matched 'min-required'

Solution in practice (debug):

++ grep -h -R required_version --include '*tf' <FILES SCANNED>
++ grep -o '\(\d\+\.\?\)\{2,3\}\(-[a-z]\+[0-9]\+\)\?'
+ versions=0.13.0-rc1
+ [[ 0.13.0-rc1 =~ ([~=!<>]{0,2}[[:blank:]]*[0-9]+[0-9.]+)[^0-9]*(-[a-z]+[0-9]+)? ]]
+ found_min_required=0.13.0-rc1
+ [[ 0.13.0-rc1 =~ ^!=.+ ]]
++ echo 0.13.0-rc1
+ found_min_required=0.13.0-rc1
+ echo 0.13.0-rc1
+ exit 0
Installing Terraform v0.13.0-rc1
Downloading release tarball from https://releases.hashicorp.com/terraform/0.13.0-rc1/terraform_0.13.0-rc1_darwin_amd64.zip
######################################################################## 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/0.13.0-rc1/terraform_0.13.0-rc1_SHA256SUMS
No keybase install found, skipping OpenPGP signature verification
Archive:  tfenv_download.Lubb4P/terraform_0.13.0-rc1_darwin_amd64.zip
  inflating: tfenv/versions/0.13.0-rc1/terraform
Installation of terraform v0.13.0-rc1 successful. To make this your default version, run 'tfenv use 0.13.0-rc1

@mrpaws mrpaws marked this pull request as ready for review August 5, 2020 00:40
@mrpaws
Copy link
Contributor Author

mrpaws commented Aug 7, 2020

Reference Issue: #207 (comment)

@Zordrak Zordrak merged commit d63b34b into tfutils:master Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants