commit
1821c04126
|
@ -9,7 +9,6 @@ run:
|
||||||
- ".*Mock.*"
|
- ".*Mock.*"
|
||||||
- ".*_mock.*"
|
- ".*_mock.*"
|
||||||
- ".*_generated.*"
|
- ".*_generated.*"
|
||||||
go: "1.18"
|
|
||||||
|
|
||||||
output:
|
output:
|
||||||
sort-results: true
|
sort-results: true
|
||||||
|
@ -31,7 +30,6 @@ linters:
|
||||||
- goerr113
|
- goerr113
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- gosec
|
- gosec
|
||||||
- ifshort
|
|
||||||
- importas
|
- importas
|
||||||
- makezero
|
- makezero
|
||||||
- nilnil
|
- nilnil
|
||||||
|
@ -66,9 +64,4 @@ linters-settings:
|
||||||
- unreachable
|
- unreachable
|
||||||
- unusedresult
|
- unusedresult
|
||||||
staticcheck:
|
staticcheck:
|
||||||
go: "1.18"
|
|
||||||
checks: ["all", "-SA1019"]
|
checks: ["all", "-SA1019"]
|
||||||
|
|
||||||
issues:
|
|
||||||
new: true
|
|
||||||
fix: true
|
|
||||||
|
|
|
@ -20,6 +20,9 @@ const (
|
||||||
vendorDirectory = "vendor"
|
vendorDirectory = "vendor"
|
||||||
goModFile = "go.mod"
|
goModFile = "go.mod"
|
||||||
goSumFile = "go.sum"
|
goSumFile = "go.sum"
|
||||||
|
|
||||||
|
defaultCountModule = 100
|
||||||
|
depsFileComment = "#"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -58,7 +61,7 @@ func (a *action) Run(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read deps file line by line to upgrade
|
// Read deps file line by line to upgrade
|
||||||
successUpgradedModules := make([]Module, 0, 100)
|
successUpgradedModules := make([]Module, 0, defaultCountModule)
|
||||||
modulePaths := strings.Split(depsStr, "\n")
|
modulePaths := strings.Split(depsStr, "\n")
|
||||||
for _, modulePath := range modulePaths {
|
for _, modulePath := range modulePaths {
|
||||||
successUpgradedModules, err = a.runUpgradeModule(c, mapImportedModules, successUpgradedModules, modulePath)
|
successUpgradedModules, err = a.runUpgradeModule(c, mapImportedModules, successUpgradedModules, modulePath)
|
||||||
|
@ -92,7 +95,7 @@ func (a *action) runGetImportedModules(c *cli.Context) (map[string]struct{}, err
|
||||||
goOutputStr = strings.ReplaceAll(goOutputStr, "}{", "},{")
|
goOutputStr = strings.ReplaceAll(goOutputStr, "}{", "},{")
|
||||||
goOutputStr = "[" + goOutputStr + "]"
|
goOutputStr = "[" + goOutputStr + "]"
|
||||||
|
|
||||||
importedModules := make([]Module, 0, 100)
|
importedModules := make([]Module, 0, defaultCountModule)
|
||||||
if err := json.Unmarshal([]byte(goOutputStr), &importedModules); err != nil {
|
if err := json.Unmarshal([]byte(goOutputStr), &importedModules); err != nil {
|
||||||
return nil, fmt.Errorf("failed to json unmarshal: %w", err)
|
return nil, fmt.Errorf("failed to json unmarshal: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -154,10 +157,18 @@ func (a *action) runUpgradeModule(
|
||||||
modulePath string,
|
modulePath string,
|
||||||
) ([]Module, error) {
|
) ([]Module, error) {
|
||||||
modulePath = strings.TrimSpace(modulePath)
|
modulePath = strings.TrimSpace(modulePath)
|
||||||
|
|
||||||
|
// Ignore empty
|
||||||
if modulePath == "" {
|
if modulePath == "" {
|
||||||
return successUpgradedModules, nil
|
return successUpgradedModules, nil
|
||||||
}
|
}
|
||||||
a.log("Line: %s", modulePath)
|
|
||||||
|
// Ignore comment
|
||||||
|
if strings.HasPrefix(modulePath, depsFileComment) {
|
||||||
|
return successUpgradedModules, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
a.log("Module path: %s", modulePath)
|
||||||
|
|
||||||
// Check if modulePath is imported module, otherwise skip
|
// Check if modulePath is imported module, otherwise skip
|
||||||
if _, ok := mapImportedModules[modulePath]; !ok {
|
if _, ok := mapImportedModules[modulePath]; !ok {
|
||||||
|
@ -186,6 +197,8 @@ func (a *action) runUpgradeModule(
|
||||||
|
|
||||||
// Upgrade module
|
// Upgrade module
|
||||||
if a.flags.dryRun {
|
if a.flags.dryRun {
|
||||||
|
// Only print which module will be upgrade
|
||||||
|
// Don't do anything
|
||||||
color.PrintAppOK(name, fmt.Sprintf("Will upgrade [%s] version [%s] to [%s]", module.Path, module.Version, module.Update.Version))
|
color.PrintAppOK(name, fmt.Sprintf("Will upgrade [%s] version [%s] to [%s]", module.Path, module.Version, module.Update.Version))
|
||||||
return successUpgradedModules, nil
|
return successUpgradedModules, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue