#8 new flag UpMajor.

This commit is contained in:
Gorbunov Kirill Andreevich
2024-03-17 15:41:25 +03:00
parent 3a60ffbf91
commit 974c685136
5 changed files with 84 additions and 14 deletions

View File

@@ -30,7 +30,7 @@ import (
"go.unistack.org/micro/v4/logger"
"go.unistack.org/micro/v4/options"
"golang.org/x/mod/modfile"
"golang.org/x/mod/semver"
"gopkg.in/yaml.v2"
)
@@ -147,19 +147,28 @@ func main() {
mvs := make(map[string]modules.Update)
updateOptions := modules.UpdateOptions{
Pre: false,
Major: false,
Cached: true,
Pre: false,
Major: false,
UpMajor: false,
Cached: true,
OnUpdate: func(u modules.Update) {
var modpath string // new mod path with major
if u.Err != nil {
logger.Errorf(ctx, "%s: failed: %v", u.Module.Path, u.Err)
return
}
v, ok := modules.ModMajor(u.Module.Path)
if ok && !strings.Contains(u.Version, v) {
u.Module.Path = u.Module.Path[:len(u.Module.Path)-2] + v
modpath = u.Module.Path
v := semver.Major(u.Version)
p := modules.ModPrefix(modpath)
if !strings.HasPrefix(u.Module.Version, v) && v != "v1" && v != "v0" {
switch strings.HasPrefix(u.Module.Path, "gopkg.in") {
case true:
modpath = p + "." + v
case false:
modpath = p + "/" + v
}
}
mvs[u.Module.Path] = u
mvs[modpath] = u
},
}