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

Tweaking URL regex based on comment from aderuelle #225

Merged
merged 3 commits into from
May 11, 2022

Conversation

micahflattbuilt
Copy link
Contributor

URL tweaks based on changes to the hashicorp release site.

@allen-servedio
Copy link

allen-servedio commented May 9, 2022

@micahflattbuilt - sorry, too fast on that last comment. Confirmed that it works for:

terraform {
  required_version = ">= 1.0, < 2.0"
}
Reading required version from terraform file
Reading required version from constraint: >= 1.0, < 2.0
Matched version: 1.1.9
Creating directory for terraform binary at: /Users/user/.terraform.versions
Downloading to: /Users/user/.terraform.versions
20709155 bytes downloaded
Switched terraform to version "1.1.9"

allen-servedio pushed a commit to TheWeatherCompany/terraform-switcher that referenced this pull request May 9, 2022
@allen-servedio
Copy link

No @micahflattbuilt - I goofed and did not copy https://github.com/warrensbox/terraform-switcher/pull/225/files#diff-99b146ff8d948c450dfa0fe84cb71461f9b43acbfc52837fbf712e696ccea2f2R40 (a little too fast off the trigger). I am trying to get our automation back up...

@micahflattbuilt
Copy link
Contributor Author

I know all about trying to get your automation back up quickly... I posted my build to our CD servers to get things rolling again (with success). It's a bit of a silly patch but so far seems to work as a quick fix.

@sw-popop
Copy link

sw-popop commented May 9, 2022

^^^ merge please

@franviera92
Copy link

we need this change please! merge :(

@jukie
Copy link
Collaborator

jukie commented May 9, 2022

I pushed a temp release to my fork with these changes in the meantime - https://github.com/Jukie/terraform-switcher/releases/tag/0.13.12345

@@ -27,16 +27,17 @@ func GetTFList(mirrorURL string, preRelease bool) ([]string, error) {
var semver string
if preRelease == true {
// Getting versions from body; should return match /X.X.X-@/ where X is a number,@ is a word character between a-z or A-Z
semver = `\/(\d+\.\d+\.\d+)(-[a-zA-z]+\d*)?\/`
semver = `\/(\d+\.\d+\.\d+)(-[a-zA-z]+\d*)?\"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of interest: what is the reason to quote double quote in regex? does it have any special meaning? or is this used down the code and is enclosed in double quotes? (the latter explain the need to quote)
also might probably need to adjust comment above this line to replace last char of regex.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • escaping is not needed in raw string literals
  • could use word characters class \w for the '@' part
  • we also could accomodate for possible reintroduction of trailing '/'

Not tested:

Suggested change
semver = `\/(\d+\.\d+\.\d+)(-[a-zA-z]+\d*)?\"`
semver = `/(\d+.\d+.\d+)(-\w+)?/?"`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the double quote in the regex, I was finding that it was capturing both pre release and full release versions every time. The double quote acts as an ending delimiter so that the right versions are found when ignoring pre-release versions.

Copy link
Collaborator

@yermulnik yermulnik May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though the double quote doesn't need to be escaped, right? Oops, please disregard, I didn't make it to see the new commit to this PR by the time of writing the comment.

}
r, _ := regexp.Compile(semver)
for i := range result {
if r.MatchString(result[i]) {
str := r.FindString(result[i])
trimstr := strings.Trim(str, "/") //remove "/" from /X.X.X/
trimstr := strings.Trim(str, "/\"") //remove "/" from /X.X.X/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might probably need to adjust comment on this line to reflect regex pattern change.

@yermulnik
Copy link
Collaborator

Also may probably worth to switch to their new API?
https://www.hashicorp.com/blog/announcing-the-hashicorp-releases-api

} else if preRelease == false {
// Getting versions from body; should return match /X.X.X/ where X is a number
semver = `\/(\d+\.\d+\.\d+)\/`
// without the ending '"' pre-release folders would be tried and break.
semver = `\/(\d+\.\d+\.\d+)\"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, not tested:

Suggested change
semver = `\/(\d+\.\d+\.\d+)\"`
semver = `/(\d+.\d+.\d+)/?"`

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now works on interactive mode. Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the escape of the double quote and added the optional ending slash. My local tests still work with the additions.

@roys8
Copy link

roys8 commented May 10, 2022

Hello Team,

May we expect this to be available today, we have some CRQ going and we got stuck due to this 😄

@smailc
Copy link

smailc commented May 10, 2022

+1

4 similar comments
@JanisOrlovs
Copy link

+1

@toniokaluza
Copy link

+1

@andrewinci
Copy link

+1

@kstormp
Copy link

kstormp commented May 10, 2022

+1

@franviera92
Copy link

No one assigned (15h)

@micahflattbuilt
Copy link
Contributor Author

@yermulnik , I agree that the release API would be the way to go. This PR just tries to provide a quick path for recovery.

@kizzie
Copy link

kizzie commented May 10, 2022

No one assigned (15h)

I expect there are timezone differences to see as well :) but bumping this some more!

@yermulnik
Copy link
Collaborator

yermulnik commented May 10, 2022

@yermulnik , I agree that the release API would be the way to go. This PR just tries to provide a quick path for recovery.

Got you. Makes sense. Thanks.

@smailc
Copy link

smailc commented May 10, 2022

Is it going to be merged today? I need to know if we need to change our build tools to not use tfswitch to make them work

@mantoniocc
Copy link

mantoniocc commented May 10, 2022

I pushed a temp release to my fork with these changes in the meantime - https://github.com/Jukie/terraform-switcher/releases/tag/0.13.12345

We are using temporally @jukie fork in our pipelines and work fine!

We apply the following fix to our docker images.
curl -O -L https://github.com/Jukie/terraform-switcher/releases/download/0.13.12345/terraform-switcher_0.13.12345_linux_amd64.tar.gz && \ tar -xvzf terraform-switcher_0.13.12345_linux_amd64.tar.gz && \ mv tfswitch /bin/tfswitch

kizzie pushed a commit to ovotech/circleci-orbs that referenced this pull request May 10, 2022
…iner

There is a current issue with the original tfswitch as hashicorp changed
their website and so the bit of tfswitch which scrapes that info is
failing. This is a temporary fix until the PR is merged on tfswitch.

github issue: warrensbox/terraform-switcher#225
differences between versions: warrensbox/terraform-switcher@master...Jukie:fix-release-downloads
@gabelazo
Copy link

We switched to tfenv. https://github.com/tfutils/tfenv

allen-servedio pushed a commit to TheWeatherCompany/terraform-switcher that referenced this pull request May 10, 2022
@llamahunter
Copy link

@warrensbox any chance of getting this merged soon?

@allen-servedio
Copy link

@micahflattbuilt - I found a couple more places around the "pre-release" tests:

From 64b541bb42d23ae395cfd5b28f77e9de6724b2c9 Mon Sep 17 00:00:00 2001
From: Allen Servedio
Date: Tue, 10 May 2022 15:19:29 -0400
Subject: [PATCH] Fix pre-versions

---
 lib/list_versions.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/list_versions.go b/lib/list_versions.go
index c072955..1802e5e 100644
--- a/lib/list_versions.go
+++ b/lib/list_versions.go
@@ -58,12 +58,12 @@ func GetTFLatest(mirrorURL string) (string, error) {
 		return "", error
 	}
 	// Getting versions from body; should return match /X.X.X/ where X is a number
-	semver := `\/(\d+\.\d+\.\d+)\/`
+	semver := `\/(\d+\.\d+\.\d+)\/?"`
 	r, _ := regexp.Compile(semver)
 	for i := range result {
 		if r.MatchString(result[i]) {
 			str := r.FindString(result[i])
-			trimstr := strings.Trim(str, "/") //remove "/" from /X.X.X/
+			trimstr := strings.Trim(str, "/\"") //remove '/' or '"' from /X.X.X/" or /X.X.X"
 			return trimstr, nil
 		}
 	}
@@ -81,7 +81,7 @@ func GetTFLatestImplicit(mirrorURL string, preRelease bool, version string) (str
 			return "", error
 		}
 		// Getting versions from body; should return match /X.X.X-@/ where X is a number,@ is a word character between a-z or A-Z
-		semver := fmt.Sprintf(`\/(%s{1}\.\d+\-[a-zA-z]+\d*)\/`, version)
+		semver := fmt.Sprintf(`\/(%s{1}\.\d+\-[a-zA-z]+\d*)\/?"`, version)
 		r, err := regexp.Compile(semver)
 		if err != nil {
 			return "", err
@@ -89,7 +89,7 @@ func GetTFLatestImplicit(mirrorURL string, preRelease bool, version string) (str
 		for i := range versions {
 			if r.MatchString(versions[i]) {
 				str := r.FindString(versions[i])
-				trimstr := strings.Trim(str, "/") //remove "/" from /X.X.X/
+				trimstr := strings.Trim(str, "/\"") //remove '/' or '"' from /X.X.X/" or /X.X.X"
 				return trimstr, nil
 			}
 		}
--
2.32.0 (Apple Git-132)

@micahflattbuilt
Copy link
Contributor Author

I found a couple more places around the "pre-release" tests:

@allen-servedio applied your diff as a new commit.

@jukie
Copy link
Collaborator

jukie commented May 11, 2022

Sorry to piggyback the PR but was anyone able to get the releases api working for anything past the most recent releases(e.g. first batch from whatever's passed in for limit)?
after doesn't appear to be working as intended.

@jphuynh
Copy link

jphuynh commented May 11, 2022

@warrensbox Is it possible to release this as a temporary hotfix?

I appreciate that there are conversations around a more reliable implementation using the releases API but suppose that can be addressed in a further release. A hotfix from this PR would be great in the mean time.

Copy link

@alxdrl alxdrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@leolorenzoluis leolorenzoluis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! MERGE😜! 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀

kizzie pushed a commit to ovotech/circleci-orbs that referenced this pull request May 11, 2022
github issue: warrensbox/terraform-switcher#225
differences between versions: warrensbox/[email protected]:fix-release-downloads
@smailc
Copy link

smailc commented May 11, 2022

Thanks @jukie - fix works great

@warrensbox warrensbox merged commit 31a5b91 into warrensbox:master May 11, 2022
@warrensbox
Copy link
Owner

https://www.hashicorp.com/blog/announcing-the-hashicorp-releases-api

This is fixed and released

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.

None yet