@@ -90,7 +90,7 @@ func runUpgrade(targetVersion string) (string, error) {
9090func runUpgradeCommand (targetVersion string ) error {
9191 ctx , _ := context .WithTimeout (context .Background (), time .Minute * 3 ) //nolint
9292 spongeVersion := "github.com/go-dev-frame/sponge/cmd/sponge@" + targetVersion
93- if targetVersion != latestVersion && targetVersion < "v1.11.2" {
93+ if compareVersion ( separatedVersion , targetVersion ) {
9494 spongeVersion = strings .ReplaceAll (spongeVersion , "go-dev-frame" , "zhufuyi" )
9595 }
9696 result := gobash .Run (ctx , "go" , "install" , spongeVersion )
@@ -118,6 +118,9 @@ func copyToTempDir(targetVersion string) (string, error) {
118118 if targetVersion == latestVersion {
119119 // find the new version of the sponge code directory
120120 arg := fmt .Sprintf ("%s/pkg/mod/github.com/go-dev-frame" , gopath )
121+ if compareVersion (separatedVersion , targetVersion ) {
122+ arg = strings .ReplaceAll (arg , "go-dev-frame" , "zhufuyi" )
123+ }
121124 result , err = gobash .Exec ("ls" , adaptPathDelimiter (arg ))
122125 if err != nil {
123126 return "" , fmt .Errorf ("execute command failed, %v" , err )
@@ -132,6 +135,9 @@ func copyToTempDir(targetVersion string) (string, error) {
132135 }
133136
134137 srcDir := adaptPathDelimiter (fmt .Sprintf ("%s/pkg/mod/github.com/go-dev-frame/%s" , gopath , spongeDirName ))
138+ if compareVersion (separatedVersion , targetVersion ) {
139+ srcDir = strings .ReplaceAll (srcDir , "go-dev-frame" , "zhufuyi" )
140+ }
135141 destDir := adaptPathDelimiter (GetSpongeDir () + "/" )
136142 targetDir := adaptPathDelimiter (destDir + ".sponge" )
137143
@@ -214,7 +220,7 @@ func getLatestVersion(s string) string {
214220func updateSpongeInternalPlugin (targetVersion string ) error {
215221 ctx , _ := context .WithTimeout (context .Background (), time .Minute ) //nolint
216222 genGinVersion := "github.com/go-dev-frame/sponge/cmd/protoc-gen-go-gin@" + targetVersion
217- if targetVersion < "v1.11.2" {
223+ if compareVersion ( separatedVersion , targetVersion ) {
218224 genGinVersion = strings .ReplaceAll (genGinVersion , "go-dev-frame" , "zhufuyi" )
219225 }
220226 result := gobash .Run (ctx , "go" , "install" , genGinVersion )
@@ -227,7 +233,7 @@ func updateSpongeInternalPlugin(targetVersion string) error {
227233
228234 ctx , _ = context .WithTimeout (context .Background (), time .Minute ) //nolint
229235 genRPCVersion := "github.com/go-dev-frame/sponge/cmd/protoc-gen-go-rpc-tmpl@" + targetVersion
230- if targetVersion < "v1.11.2" {
236+ if compareVersion ( separatedVersion , targetVersion ) {
231237 genRPCVersion = strings .ReplaceAll (genRPCVersion , "go-dev-frame" , "zhufuyi" )
232238 }
233239 result = gobash .Run (ctx , "go" , "install" , genRPCVersion )
@@ -242,7 +248,7 @@ func updateSpongeInternalPlugin(targetVersion string) error {
242248 if ! strings .HasPrefix (targetVersion , "v1" ) {
243249 ctx , _ = context .WithTimeout (context .Background (), time .Minute ) //nolint
244250 genJSONVersion := "github.com/go-dev-frame/sponge/cmd/protoc-gen-json-field@" + targetVersion
245- if targetVersion < "v1.11.2" {
251+ if compareVersion ( separatedVersion , targetVersion ) {
246252 genJSONVersion = strings .ReplaceAll (genJSONVersion , "go-dev-frame" , "zhufuyi" )
247253 }
248254 result = gobash .Run (ctx , "go" , "install" , genJSONVersion )
@@ -256,3 +262,32 @@ func updateSpongeInternalPlugin(targetVersion string) error {
256262
257263 return nil
258264}
265+
266+ // v1 >= v2 return true
267+ // v1 < v2 return false
268+ func compareVersion (v1 , v2 string ) bool {
269+ if v1 == "latest" {
270+ return true
271+ }
272+ if v2 == "latest" {
273+ return false
274+ }
275+
276+ v1 = strings .ReplaceAll (v1 , "v" , "" )
277+ v2 = strings .ReplaceAll (v2 , "v" , "" )
278+ v1s := strings .Split (v1 , "." )
279+ v2s := strings .Split (v2 , "." )
280+ if len (v1s ) < 3 || len (v2s ) < 3 {
281+ return false
282+ }
283+
284+ if v1s [0 ] != v2s [0 ] {
285+ return utils .StrToInt (v1s [0 ]) > utils .StrToInt (v2s [0 ])
286+ }
287+
288+ if v1s [1 ] != v2s [1 ] {
289+ return utils .StrToInt (v1s [1 ]) > utils .StrToInt (v2s [1 ])
290+ }
291+
292+ return utils .StrToInt (v1s [2 ]) > utils .StrToInt (v2s [2 ])
293+ }
0 commit comments