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 mangles tagged releases with 'tr' #207

Closed
mrpaws opened this issue Aug 6, 2020 · 2 comments
Closed

Min-required mangles tagged releases with 'tr' #207

mrpaws opened this issue Aug 6, 2020 · 2 comments

Comments

@mrpaws
Copy link
Contributor

mrpaws commented Aug 6, 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
Copy link
Contributor Author

mrpaws commented Aug 6, 2020

#206 resolves this issue

@mrpaws mrpaws changed the title Min-required mangles tagged releases and tries to install invalid versions Min-required mangles tagged releases and mangles version with 'tr' Aug 6, 2020
@mrpaws mrpaws changed the title Min-required mangles tagged releases and mangles version with 'tr' Min-required mangles tagged releases with 'tr' Aug 6, 2020
@Zordrak
Copy link
Collaborator

Zordrak commented Feb 6, 2021

Resolved by #206

@Zordrak Zordrak closed this as completed Feb 6, 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

No branches or pull requests

2 participants