parse out the required golang version

This commit is contained in:
Jeff Carr 2024-12-18 00:41:52 -06:00
parent 063e4e57c8
commit 4879befeb3
4 changed files with 50 additions and 14 deletions

View File

@ -20,6 +20,9 @@ func cleanGoDepsCheckOk(check *gitpb.Repo) error {
var err error = nil
var fixes [][]string
log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
if check.GoDeps == nil {
return errors.New("check.GoDeps == nil")
}
all := check.GoDeps.SortByGoPath()
for all.Scan() {
depRepo := all.Next()

View File

@ -16,6 +16,8 @@ import (
var VERSION string
var BUILDTIME string
var golangVersion string = "1.21"
var pp *arg.Parser
var forge *forgepb.Forge

View File

@ -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
}

21
run.go
View File

@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
@ -69,40 +70,42 @@ func runStrict(wd string, cmd []string) {
}
}
func runVerbose(wd string, cmd []string) error {
func runVerbose(wd string, argv []string) (cmd.Status, error) {
var err error
log.DaemonMode(true)
defer log.DaemonMode(false)
if wd != "" {
if err = os.Chdir(wd); err != nil {
return fmt.Errorf("cd %s failed %v", wd, err)
var s cmd.Status
s.Stdout = []string{"notreal stdout from runVerbose()"}
return s, fmt.Errorf("cd %s failed %v", wd, err)
}
}
log.Info(wd, "running:", wd, cmd)
log.Info(wd, "running:", wd, argv)
// result := shell.Run(cmd)
result := shell.Run(cmd)
result := shell.Run(argv)
if result.Error != nil {
log.Info("cmd failed", wd, cmd, err)
log.Info("cmd failed", wd, argv, err)
for _, line := range result.Stdout {
log.Info(line)
}
for i, line := range result.Stderr {
log.Info("STDERR:", i, line)
}
return result.Error
return result, result.Error
}
if result.Exit != 0 {
log.Info("cmd failed", wd, cmd, err)
log.Info("cmd failed", wd, argv, err)
for _, line := range result.Stdout {
log.Info(line)
}
for i, line := range result.Stderr {
log.Info("STDERR:", i, line)
}
return fmt.Errorf("cmd failed with %d", result.Exit)
return result, fmt.Errorf("cmd failed with %d", result.Exit)
}
for _, line := range result.Stdout {
log.Info(line)
}
return nil
return result, nil
}