@@ -90,7 +90,7 @@ func runUpgrade(targetVersion string) (string, error) {
90
90
func runUpgradeCommand (targetVersion string ) error {
91
91
ctx , _ := context .WithTimeout (context .Background (), time .Minute * 3 ) //nolint
92
92
spongeVersion := "github.com/go-dev-frame/sponge/cmd/sponge@" + targetVersion
93
- if targetVersion != latestVersion && targetVersion < "v1.11.2" {
93
+ if compareVersion ( separatedVersion , targetVersion ) {
94
94
spongeVersion = strings .ReplaceAll (spongeVersion , "go-dev-frame" , "zhufuyi" )
95
95
}
96
96
result := gobash .Run (ctx , "go" , "install" , spongeVersion )
@@ -118,6 +118,9 @@ func copyToTempDir(targetVersion string) (string, error) {
118
118
if targetVersion == latestVersion {
119
119
// find the new version of the sponge code directory
120
120
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
+ }
121
124
result , err = gobash .Exec ("ls" , adaptPathDelimiter (arg ))
122
125
if err != nil {
123
126
return "" , fmt .Errorf ("execute command failed, %v" , err )
@@ -132,6 +135,9 @@ func copyToTempDir(targetVersion string) (string, error) {
132
135
}
133
136
134
137
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
+ }
135
141
destDir := adaptPathDelimiter (GetSpongeDir () + "/" )
136
142
targetDir := adaptPathDelimiter (destDir + ".sponge" )
137
143
@@ -214,7 +220,7 @@ func getLatestVersion(s string) string {
214
220
func updateSpongeInternalPlugin (targetVersion string ) error {
215
221
ctx , _ := context .WithTimeout (context .Background (), time .Minute ) //nolint
216
222
genGinVersion := "github.com/go-dev-frame/sponge/cmd/protoc-gen-go-gin@" + targetVersion
217
- if targetVersion < "v1.11.2" {
223
+ if compareVersion ( separatedVersion , targetVersion ) {
218
224
genGinVersion = strings .ReplaceAll (genGinVersion , "go-dev-frame" , "zhufuyi" )
219
225
}
220
226
result := gobash .Run (ctx , "go" , "install" , genGinVersion )
@@ -227,7 +233,7 @@ func updateSpongeInternalPlugin(targetVersion string) error {
227
233
228
234
ctx , _ = context .WithTimeout (context .Background (), time .Minute ) //nolint
229
235
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 ) {
231
237
genRPCVersion = strings .ReplaceAll (genRPCVersion , "go-dev-frame" , "zhufuyi" )
232
238
}
233
239
result = gobash .Run (ctx , "go" , "install" , genRPCVersion )
@@ -242,7 +248,7 @@ func updateSpongeInternalPlugin(targetVersion string) error {
242
248
if ! strings .HasPrefix (targetVersion , "v1" ) {
243
249
ctx , _ = context .WithTimeout (context .Background (), time .Minute ) //nolint
244
250
genJSONVersion := "github.com/go-dev-frame/sponge/cmd/protoc-gen-json-field@" + targetVersion
245
- if targetVersion < "v1.11.2" {
251
+ if compareVersion ( separatedVersion , targetVersion ) {
246
252
genJSONVersion = strings .ReplaceAll (genJSONVersion , "go-dev-frame" , "zhufuyi" )
247
253
}
248
254
result = gobash .Run (ctx , "go" , "install" , genJSONVersion )
@@ -256,3 +262,32 @@ func updateSpongeInternalPlugin(targetVersion string) error {
256
262
257
263
return nil
258
264
}
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