From f070f939e125075b2e385ec39323d5f3ca9d2459 Mon Sep 17 00:00:00 2001 From: Elia Bracci Date: Tue, 20 Dec 2022 16:47:21 +0100 Subject: [PATCH 1/2] Added M1 fix for old tg version --- install.sh | 2 +- lib/install.go | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) mode change 100644 => 100755 install.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index d2a0c11..c187a03 --- a/install.sh +++ b/install.sh @@ -337,7 +337,7 @@ End of functions from https://github.com/client9/shlib EOF PROJECT_NAME="tgswitch" -OWNER=warrensbox +OWNER=EliaBracciSumo REPO="tgswitch" BINARY=tgswitch FORMAT=tar.gz diff --git a/lib/install.go b/lib/install.go index e71741c..fc0681d 100644 --- a/lib/install.go +++ b/lib/install.go @@ -9,6 +9,8 @@ import ( "regexp" "runtime" "strings" + + semver "github.com/hashicorp/go-version" ) const ( @@ -140,7 +142,7 @@ func GetRecentVersions() ([]string, error) { return nil, nil } -//CreateRecentFile : create a recent file +// CreateRecentFile : create a recent file func CreateRecentFile(requestedVersion string) { installLocation = GetInstallLocation() @@ -168,7 +170,7 @@ func ValidVersionFormat(version string) bool { return semverRegex.MatchString(version) } -//Install : Install the provided version in the argument +// Install : Install the provided version in the argument func Install(tgversion string, usrBinPath string, mirrorURL string) string { /* Check to see if user has permission to the default bin location which is "/usr/local/bin/terragrunt" * If user does not have permission to default bin location, proceed to create $HOME/bin and install the tgswitch there @@ -182,6 +184,15 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string { goarch := runtime.GOARCH goos := runtime.GOOS + versionObj, err := semver.NewVersion(tgversion) + + // Constraint for darwin M1. Terragrunt started release arm64 versions for linux and darwin OS from version 0.28.12 included. + // However, amd64 versions work on darwin arm64. To be tested on linux platforms. + darwinM1constraint, err := semver.NewConstraint("< 0.28.12") + if darwinM1constraint.Check(versionObj) && goarch == "arm64" && goos == "darwin" { + fmt.Printf("%s satisfies constraints %s", versionObj, darwinM1constraint) + goarch = "amd64" + } /* check if selected version already downloaded */ installFileVersionPath := ConvertExecutableExt(filepath.Join(installLocation, installVersion+tgversion)) @@ -244,9 +255,9 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string { return "" } -//InstallableBinLocation : Checks if terragrunt is installable in the location provided by the user. -//If not, create $HOME/bin. Ask users to add $HOME/bin to $PATH -//Return $HOME/bin as install location +// InstallableBinLocation : Checks if terragrunt is installable in the location provided by the user. +// If not, create $HOME/bin. Ask users to add $HOME/bin to $PATH +// Return $HOME/bin as install location func InstallableBinLocation(userBinPath string) string { usr, errCurr := user.Current() @@ -294,7 +305,7 @@ func PrintCreateDirStmt(unableDir string, writable string) { fmt.Printf("RUN `export PATH=$PATH:%s` to append bin to $PATH\n", writable) } -//ConvertExecutableExt : convert excutable with local OS extension +// ConvertExecutableExt : convert excutable with local OS extension func ConvertExecutableExt(fpath string) string { switch runtime.GOOS { case "windows": From 90ac97367f667c7a6d39cb279e44d246d6c20d0e Mon Sep 17 00:00:00 2001 From: Elia Bracci Date: Tue, 20 Dec 2022 16:59:41 +0100 Subject: [PATCH 2/2] Added case test for M1 --- lib/install.go | 2 +- test-tgswitch.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/install.go b/lib/install.go index fc0681d..5637ac9 100644 --- a/lib/install.go +++ b/lib/install.go @@ -236,7 +236,7 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string { /* rename unzipped file to terragrunt version name - terraform_x.x.x */ RenameFile(downloadedFile, installFileVersionPath) - err := os.Chmod(installFileVersionPath, 0755) + err = os.Chmod(installFileVersionPath, 0755) if err != nil { log.Println(err) } diff --git a/test-tgswitch.sh b/test-tgswitch.sh index c1789bf..e7be098 100755 --- a/test-tgswitch.sh +++ b/test-tgswitch.sh @@ -82,3 +82,5 @@ runtestdir "tgswitchrc" "test_tgswitchrc" "v0.33.0" runtestdir ".toml" "test_tgswitchtoml" "v0.34.0" runtestenv "env variable" "0.37.1" "v0.37.1" runtestarg "passing argument" "0.36.1" "v0.36.1" +# M1 darwin arm64 test +runtestarg "passing argument" "0.28.0" "v0.28.0" \ No newline at end of file