-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_deps.go
53 lines (46 loc) · 1.29 KB
/
update_deps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package depbump
import (
"regexp"
"github.com/yyle88/erero"
"github.com/yyle88/eroticgo"
"github.com/yyle88/neatjson/neatjsons"
"github.com/yyle88/osexec"
"github.com/yyle88/zaplog"
)
func UpdateModule(projectPath string, modulePath string) error {
output, err := osexec.NewOsCommand().WithPath(projectPath).WithMatchPipe(func(line string) bool {
upgradeInfo, matched := MatchUpgrade(line)
if matched {
zaplog.SUG.Debugln("match-output-message:", eroticgo.GREEN.Sprint(neatjsons.S(upgradeInfo)))
}
return matched
}).ExecInPipe("go", "get", "-u", modulePath)
if err != nil {
if len(output) > 0 {
zaplog.SUG.Warnln(string(output))
}
return erero.Wro(err)
}
zaplog.SUG.Debugln(string(output))
return nil
}
type UpgradeInfo struct {
Module string `json:"module"`
OldVersion string `json:"old_version"`
NewVersion string `json:"new_version"`
}
func MatchUpgrade(outputLine string) (*UpgradeInfo, bool) {
pattern := `go: upgraded ([^\s]+) ([^\s]+) => ([^\s]+)`
re := regexp.MustCompile(pattern)
// Match the input string
matches := re.FindStringSubmatch(outputLine)
if len(matches) != 4 {
return nil, false
}
// Extract module, old version, and new version
return &UpgradeInfo{
Module: matches[1],
OldVersion: matches[2],
NewVersion: matches[3],
}, true
}