summaryrefslogtreecommitdiff
path: root/redoGoMod.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-18 00:41:52 -0600
committerJeff Carr <[email protected]>2024-12-18 00:41:52 -0600
commit4879befeb3ad89f0357f995413afcab904296599 (patch)
tree5cd9ebfab4f1b2275d34512383f29b89322a4fce /redoGoMod.go
parent063e4e57c87c5e6c37709c9b327cf60ad80709d6 (diff)
parse out the required golang versionv0.0.18
Diffstat (limited to 'redoGoMod.go')
-rw-r--r--redoGoMod.go38
1 files changed, 33 insertions, 5 deletions
diff --git a/redoGoMod.go b/redoGoMod.go
index cbd6d05..4593b2f 100644
--- a/redoGoMod.go
+++ b/redoGoMod.go
@@ -5,7 +5,9 @@ package main
import (
"errors"
"os"
+ "strings"
+ "github.com/go-cmd/cmd"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -21,7 +23,6 @@ func eraseGoMod(repo *gitpb.Repo) {
// sets the required golang version in go.mod
func setGoVersion(repo *gitpb.Repo, version string) error {
- // most things should build with golang after 1.21
if err := repo.StrictRun([]string{"go", "mod", "edit", "-go=" + version}); err != nil {
log.Warn(repo.GetGoPath(), "go mod edit failed", err)
return err
@@ -29,6 +30,14 @@ func setGoVersion(repo *gitpb.Repo, version string) error {
return nil
}
+func goTidy(fullpath string) (cmd.Status, error) {
+ if result, err := runVerbose(fullpath, []string{"go", "mod", "tidy", "-go=" + golangVersion}); err == nil {
+ return result, nil
+ } else {
+ return result, err
+ }
+}
+
// wrapper around 'go mod init' and 'go mod tidy'
func redoGoMod(repo *gitpb.Repo) error {
// unset the go development ENV var to generate release files
@@ -41,13 +50,16 @@ func redoGoMod(repo *gitpb.Repo) error {
log.Warn("go mod init failed", err)
return err
}
- if err := runVerbose(repo.FullPath, []string{"go", "mod", "tidy", "-go=1.21"}); err != nil {
- log.Warn("go mod tidy failed", err)
- return err
+ if result, err := goTidy(repo.FullPath); err != nil {
+ if tinyFixer(result) {
+ if _, err := goTidy(repo.FullPath); err != nil {
+ return err
+ }
+ }
}
// most things should build with golang after 1.21 // todo: allow this to be set somewhere
- if err := setGoVersion(repo, "1.21"); err != nil {
+ if err := setGoVersion(repo, golangVersion); err != nil {
log.Warn(repo.GetGoPath(), "go mod edit failed", err)
return err
}
@@ -87,3 +99,19 @@ func redoGoMod(repo *gitpb.Repo) error {
_, err := repo.ParseGoSum()
return err
}
+
+func tinyFixer(result cmd.Status) bool {
+ for _, line := range result.Stdout {
+ if strings.Contains(line, "requires go@") {
+ log.Info("tinyFixer:", line)
+ parts := strings.Split(line, "requires go@")
+ if len(parts) == 2 {
+ parts = strings.Split(parts[1], ",")
+ golangVersion = parts[0]
+ return true
+ }
+ log.Info("tinyFixer:", line, "golangVersion", golangVersion)
+ }
+ }
+ return false
+}