From 98cdf38a59c91d1b517fa1060cf608717609225d Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Fri, 27 May 2022 20:16:02 +0300 Subject: [PATCH 1/7] Fail CircleCI early * Fail CircleCI pipeline on any error by switching from `set +e` to `set -e` * While here remove trailing whitespaces from CircleCI config file --- .circleci/config.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f012825..ca06917e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,9 +11,9 @@ jobs: steps: - checkout - - run: - command: | - set +e + - run: + command: | + set -e echo "Building website" sudo apt-get update sudo apt-get install python3 python3-pip @@ -22,7 +22,7 @@ jobs: mkdocs gh-deploy --force cd .. - echo "Building application" + echo "Building application" go get -v -t -d ./... go vet -tests=false ./... go test -v ./... @@ -38,11 +38,11 @@ jobs: steps: - checkout - - run: + - run: command: | - set +e + set +e source version - export RELEASE_VERSION; + export RELEASE_VERSION; RELEASE_VERSION=$RELEASE_VERSION.${CIRCLE_BUILD_NUM} export RELEASE_VERSION; echo $RELEASE_VERSION @@ -54,7 +54,7 @@ jobs: git tag -a ${RELEASE_VERSION} -m "Release Version" git push origin ${RELEASE_VERSION} curl -sL https://git.io/goreleaser | bash - + workflows: version: 2 @@ -70,6 +70,6 @@ workflows: - build filters: branches: - only: + only: - release From 4ab85e43716ef6b7237c6f445e40d60c31e6695d Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Fri, 27 May 2022 20:37:26 +0300 Subject: [PATCH 2/7] Drop `xargs` in favour of `while` loop and switch one another `set +e` --- .circleci/config.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ca06917e..a5b49ff5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,9 @@ jobs: go test -v ./... mkdir -p build go build -v -o build/tfswitch - find ./test-data/* -type d | xargs -n 1 ./build/tfswitch -c + find ./test-data/* -type d -print0 | while read -r -d $'\0' TEST_PATH; do + ./build/tfswitch -c "${TEST_PATH}" || exit 1 + done release: docker: @@ -40,7 +42,7 @@ jobs: - checkout - run: command: | - set +e + set -e source version export RELEASE_VERSION; RELEASE_VERSION=$RELEASE_VERSION.${CIRCLE_BUILD_NUM} From 49579b9ae16c322c25af686a6460d167a3566f0d Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Fri, 27 May 2022 20:42:20 +0300 Subject: [PATCH 3/7] Push breaking change for testing --- test-data/test_tfswitchtoml/.tfswitch.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/test_tfswitchtoml/.tfswitch.toml b/test-data/test_tfswitchtoml/.tfswitch.toml index f234e9cc..808d303d 100644 --- a/test-data/test_tfswitchtoml/.tfswitch.toml +++ b/test-data/test_tfswitchtoml/.tfswitch.toml @@ -1,2 +1,2 @@ -bin = "/usr/local/bin/terraform" +bin = "/usr/local/NONEXISTENT/bin/terraform" version = "0.11.3" From 518152ccc77e9e8717681ad0cb6471dd8ff440be Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Fri, 27 May 2022 20:43:48 +0300 Subject: [PATCH 4/7] Revert last change --- test-data/test_tfswitchtoml/.tfswitch.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/test_tfswitchtoml/.tfswitch.toml b/test-data/test_tfswitchtoml/.tfswitch.toml index 808d303d..f234e9cc 100644 --- a/test-data/test_tfswitchtoml/.tfswitch.toml +++ b/test-data/test_tfswitchtoml/.tfswitch.toml @@ -1,2 +1,2 @@ -bin = "/usr/local/NONEXISTENT/bin/terraform" +bin = "/usr/local/bin/terraform" version = "0.11.3" From 6c622c585e554e15a4eaee615216bfd610dfaa85 Mon Sep 17 00:00:00 2001 From: afreyermuth98 <56300858+afreyermuth98@users.noreply.github.com> Date: Wed, 15 Jun 2022 17:53:28 +0200 Subject: [PATCH 5/7] :bug: Corrected bad installations if user doesn't input 2 dots in version The constraint with only one dot returns the first version in the list, the last published. --- lib/list_versions.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/list_versions.go b/lib/list_versions.go index 1802e5e9..5021e641 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -73,7 +73,6 @@ func GetTFLatest(mirrorURL string) (string, error) { //GetTFLatestImplicit : Get the latest implicit terraform version given the hashicorp url func GetTFLatestImplicit(mirrorURL string, preRelease bool, version string) (string, error) { - if preRelease == true { //TODO: use GetTFList() instead of GetTFURLBody versions, error := GetTFURLBody(mirrorURL) @@ -94,6 +93,9 @@ func GetTFLatestImplicit(mirrorURL string, preRelease bool, version string) (str } } } else if preRelease == false { + if strings.Count(version, string(".")) == 1 { + version += ".0" + } listAll := false tflist, _ := GetTFList(mirrorURL, listAll) //get list of versions version = fmt.Sprintf("~> %v", version) From 585ed9724c097d9d143d61442586421d44abe3db Mon Sep 17 00:00:00 2001 From: "anthony.freyermuth" Date: Thu, 16 Jun 2022 09:18:38 +0200 Subject: [PATCH 6/7] :memo: Updated documentation instead of code --- lib/list_versions.go | 3 --- main.go | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/list_versions.go b/lib/list_versions.go index 5021e641..1656e5fb 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -93,9 +93,6 @@ func GetTFLatestImplicit(mirrorURL string, preRelease bool, version string) (str } } } else if preRelease == false { - if strings.Count(version, string(".")) == 1 { - version += ".0" - } listAll := false tflist, _ := GetTFList(mirrorURL, listAll) //get list of versions version = fmt.Sprintf("~> %v", version) diff --git a/main.go b/main.go index 4951b54c..6f44443e 100644 --- a/main.go +++ b/main.go @@ -56,7 +56,7 @@ func main() { listAllFlag := getopt.BoolLong("list-all", 'l', "List all versions of terraform - including beta and rc") latestPre := getopt.StringLong("latest-pre", 'p', defaultLatest, "Latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest)") showLatestPre := getopt.StringLong("show-latest-pre", 'P', defaultLatest, "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 (latest)") - latestStable := getopt.StringLong("latest-stable", 's', defaultLatest, "Latest implicit version. Ex: tfswitch --latest-stable 0.13 downloads 0.13.7 (latest)") + latestStable := getopt.StringLong("latest-stable", 's', defaultLatest, "Latest implicit version based on a constraint. Ex: tfswitch --latest-stable 0.13.0 downloads 0.13.7 and 0.13 downloads 0.15.5 (latest)") showLatestStable := getopt.StringLong("show-latest-stable", 'S', defaultLatest, "Show latest implicit version. Ex: tfswitch --show-latest-stable 0.13 prints 0.13.7 (latest)") latestFlag := getopt.BoolLong("latest", 'u', "Get latest stable version") showLatestFlag := getopt.BoolLong("show-latest", 'U', "Show latest stable version") From cc619834c156bfcebdb6cf3bae805acee6773ebf Mon Sep 17 00:00:00 2001 From: chrispruitt Date: Sun, 19 Jun 2022 08:23:37 -0400 Subject: [PATCH 7/7] adjust regex to get all terraform versinos from mirror --- lib/list_versions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/list_versions.go b/lib/list_versions.go index 1802e5e9..a751178b 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -27,7 +27,7 @@ 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*)?/?"` } else if preRelease == false { // Getting versions from body; should return match /X.X.X/ where X is a number // without the ending '"' pre-release folders would be tried and break.