From bec36795baf2610da63a818bdd1954c94cb2ad6f Mon Sep 17 00:00:00 2001 From: Andrew Humphrey Date: Fri, 7 May 2021 10:29:41 +1200 Subject: [PATCH 1/5] Merge in https://github.com/99designs/iamy/pull/63 --- go.mod | 1 + go.sum | 2 ++ iamy.go | 40 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3a6943e..eede542 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect github.com/aws/aws-sdk-go v1.16.23 + github.com/blang/semver v3.5.1+incompatible github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.7.0 github.com/ghodss/yaml v1.0.0 diff --git a/go.sum b/go.sum index 7ddc201..e1bc504 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZq github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aws/aws-sdk-go v1.16.23 h1:MwBOBeez0XEFVh6DCc888X+nHVBCjUDLnnWXSGGWUgM= github.com/aws/aws-sdk-go v1.16.23/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= +github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/iamy.go b/iamy.go index 0814e13..a17ac47 100644 --- a/iamy.go +++ b/iamy.go @@ -5,14 +5,20 @@ import ( "log" "os" "path/filepath" + "regexp" + "github.com/blang/semver" "gopkg.in/alecthomas/kingpin.v2" ) +const versionTooOldError = `Your version of IAMy (%s) is out of date compared to what the local +project expects. You should upgrade to %s to use this project.` + var ( - Version string = "dev" - defaultDir string - dryRun *bool + Version string = "dev" + defaultDir string + dryRun *bool + versionFileName string = ".iamy-version" ) type logWriter struct{ *log.Logger } @@ -61,6 +67,8 @@ func main() { log.SetOutput(ioutil.Discard) } + performVersionChecks() + switch cmd { case push.FullCommand(): PushCommand(ui, PushCommandInput{ @@ -87,3 +95,29 @@ func init() { } defaultDir = filepath.Clean(dir) } + +func performVersionChecks() { + currentIAMyVersion, _ := semver.Make(Version) + log.Printf("current version is %s", currentIAMyVersion) + + if _, err := os.Stat(versionFileName); !os.IsNotExist(err) { + log.Printf("%s found", versionFileName) + fileBytes, _ := ioutil.ReadFile(versionFileName) + fileContents := string(fileBytes) + + if fileContents != "" { + re := regexp.MustCompile(`\d\.\d+\.\d(\+\w+)?`) + match := re.FindStringSubmatch(fileContents) + localDesiredVersion, _ := semver.Make(match[0]) + log.Printf("local project wants version %s", localDesiredVersion) + + // We don't want to notify users if the `Version` is "dev" as it's not + // actually too old. It could be that they are running non-released + // versions. + if Version != "dev" && currentIAMyVersion.LE(localDesiredVersion) { + fmt.Printf(versionTooOldError, currentIAMyVersion, localDesiredVersion) + os.Exit(1) + } + } + } +} From 9040e6f593cc3dc349361bf99a52822f1c96b86f Mon Sep 17 00:00:00 2001 From: Andrew Humphrey Date: Fri, 7 May 2021 10:51:30 +1200 Subject: [PATCH 2/5] include required packages --- iamy.go | 1 + 1 file changed, 1 insertion(+) diff --git a/iamy.go b/iamy.go index a17ac47..f5e1092 100644 --- a/iamy.go +++ b/iamy.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "os" + "fmt" "path/filepath" "regexp" From 872870ef410965319dc9dbb65ea350769733c4d2 Mon Sep 17 00:00:00 2001 From: Andrew Humphrey Date: Fri, 7 May 2021 14:43:39 +1200 Subject: [PATCH 3/5] Upgrade to semver v4 --- go.mod | 2 +- go.sum | 4 ++-- iamy.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index eede542..b787db7 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect github.com/aws/aws-sdk-go v1.16.23 - github.com/blang/semver v3.5.1+incompatible + github.com/blang/semver/v4 v4.0.0 github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.7.0 github.com/ghodss/yaml v1.0.0 diff --git a/go.sum b/go.sum index e1bc504..50aef8c 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZq github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aws/aws-sdk-go v1.16.23 h1:MwBOBeez0XEFVh6DCc888X+nHVBCjUDLnnWXSGGWUgM= github.com/aws/aws-sdk-go v1.16.23/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= -github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= +github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/iamy.go b/iamy.go index f5e1092..ac6b235 100644 --- a/iamy.go +++ b/iamy.go @@ -8,7 +8,7 @@ import ( "path/filepath" "regexp" - "github.com/blang/semver" + "github.com/blang/semver/v4" "gopkg.in/alecthomas/kingpin.v2" ) From e328b3dde0e40b39694dbcce12473c80e4f0ad0d Mon Sep 17 00:00:00 2001 From: Andrew Humphrey Date: Fri, 7 May 2021 14:46:20 +1200 Subject: [PATCH 4/5] Consider build tags requirements too --- iamy.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/iamy.go b/iamy.go index ac6b235..f7baf58 100644 --- a/iamy.go +++ b/iamy.go @@ -7,6 +7,8 @@ import ( "fmt" "path/filepath" "regexp" + "strings" + "reflect" "github.com/blang/semver/v4" "gopkg.in/alecthomas/kingpin.v2" @@ -14,6 +16,8 @@ import ( const versionTooOldError = `Your version of IAMy (%s) is out of date compared to what the local project expects. You should upgrade to %s to use this project.` +const buildVersionMismatch = `Your version of IAMy (%s) does not match have the build tag the +local project expects. You should upgrade to %s to use this project.` var ( Version string = "dev" @@ -98,8 +102,8 @@ func init() { } func performVersionChecks() { - currentIAMyVersion, _ := semver.Make(Version) - log.Printf("current version is %s", currentIAMyVersion) + currentIAMyVersion, _ := semver.Make(strings.TrimPrefix(Version,"v")) + log.Printf("current versions is %s\n", currentIAMyVersion) if _, err := os.Stat(versionFileName); !os.IsNotExist(err) { log.Printf("%s found", versionFileName) @@ -107,17 +111,24 @@ func performVersionChecks() { fileContents := string(fileBytes) if fileContents != "" { - re := regexp.MustCompile(`\d\.\d+\.\d(\+\w+)?`) + re := regexp.MustCompile(`\d\.\d+\.\d\+?\w*`) match := re.FindStringSubmatch(fileContents) localDesiredVersion, _ := semver.Make(match[0]) - log.Printf("local project wants version %s", localDesiredVersion) + log.Printf("local project wants version %s\n", localDesiredVersion) // We don't want to notify users if the `Version` is "dev" as it's not // actually too old. It could be that they are running non-released // versions. - if Version != "dev" && currentIAMyVersion.LE(localDesiredVersion) { - fmt.Printf(versionTooOldError, currentIAMyVersion, localDesiredVersion) - os.Exit(1) + if Version != "dev" { + if currentIAMyVersion.LT(localDesiredVersion) { + fmt.Printf(versionTooOldError, currentIAMyVersion, localDesiredVersion) + os.Exit(1) + } + // Pay attention to build tags as well + if ! reflect.DeepEqual(localDesiredVersion.Build, currentIAMyVersion.Build) { + fmt.Printf(buildVersionMismatch, currentIAMyVersion, localDesiredVersion) + os.Exit(1) + } } } } From 46a09fa35c490f692bddacd91285fe6c617a2f48 Mon Sep 17 00:00:00 2001 From: Andrew Humphrey Date: Fri, 7 May 2021 14:56:52 +1200 Subject: [PATCH 5/5] Go fmt, one day we'll be friends --- iamy.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iamy.go b/iamy.go index f7baf58..722f508 100644 --- a/iamy.go +++ b/iamy.go @@ -1,14 +1,14 @@ package main import ( + "fmt" "io/ioutil" "log" "os" - "fmt" "path/filepath" + "reflect" "regexp" "strings" - "reflect" "github.com/blang/semver/v4" "gopkg.in/alecthomas/kingpin.v2" @@ -102,7 +102,7 @@ func init() { } func performVersionChecks() { - currentIAMyVersion, _ := semver.Make(strings.TrimPrefix(Version,"v")) + currentIAMyVersion, _ := semver.Make(strings.TrimPrefix(Version, "v")) log.Printf("current versions is %s\n", currentIAMyVersion) if _, err := os.Stat(versionFileName); !os.IsNotExist(err) { @@ -125,7 +125,7 @@ func performVersionChecks() { os.Exit(1) } // Pay attention to build tags as well - if ! reflect.DeepEqual(localDesiredVersion.Build, currentIAMyVersion.Build) { + if !reflect.DeepEqual(localDesiredVersion.Build, currentIAMyVersion.Build) { fmt.Printf(buildVersionMismatch, currentIAMyVersion, localDesiredVersion) os.Exit(1) }