package main import ( "os" "strings" "time" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func makePrepareRelease() { me.Disable() me.release.box.Disable() defer me.Enable() // run this each time something gets published successfully rePrepareRelease() if findNext() { log.Info("prepare release findNext() returned true") } me.release.box.Enable() } func forceReleaseVersion(repo *gitpb.Repo) { if argv.Minor { // if v1.2.3 change to v.1.3.0 repo.IncrementTargetMinor() } else { // if v1.2.3 change to v.1.2.4 if repo.IncrementTargetRevision() { // worked ok } else { log.Info("Failed to increment target revision", repo.GetFullPath()) os.Exit(-1) } } // empty git notes if result, err := repo.RunStrictNew([]string{"go-mod-clean", "--purge"}); err != nil { log.Info("probably you don't have gomodclean") log.Info(strings.Join(result.Stdout, "\n")) log.Info(strings.Join(result.Stderr, "\n")) repo.Run([]string{"git", "notes", "remove"}) os.Exit(-1) } if !runGoClean(repo, "--restore") { log.Info("gomodclean probably failed here. that's ok", repo.GetGoPath()) // os.Exit(-1) } } func rillGoModRestore(repo *gitpb.Repo) error { if repo.GetTargetVersion() == "" { // not set to upgrade return nil } if repo.GetLastTag() == repo.GetTargetVersion() { return nil } if me.forge.Config.IsReadOnly(repo.GetGoPath()) { return nil } if me.forge.Config.IsPrivate(repo.GetGoPath()) { return nil } runGoClean(repo, "--restore") return nil } func rePrepareRelease() { // reload the config me.forge = forgepb.Init() me.found = new(gitpb.Repos) now := time.Now() me.forge.RillFuncError(rillGoModRestore) log.Printf("rillFixGodeps() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now))) all := me.forge.Repos.SortByFullPath() for all.Scan() { check := all.Next() if me.forge.Config.IsReadOnly(check.GetGoPath()) { // can't release readonly repos continue } // if master != lastTag, always increment master := check.GetMasterVersion() lastTag := check.GetLastTag() if master != lastTag { forceReleaseVersion(check) me.found.AppendByGoPath(check) continue } if alreadyDone(check) { // means it was already published // protects against logic errors that might result // in an infinite loop log.Info("WARNING already done", check.GetGoPath()) log.Info("WARNING already done", check.GetGoPath()) log.Info("WARNING already done", check.GetGoPath()) continue } if argv.Quick != nil { // if argv has 'quick' don't do anything // that doesn't actually have a patch if master == lastTag { continue } } if argv.Protobuf && check.GetRepoType() == "protobuf" { // if --protobuf, this will force upgrade each one forceReleaseVersion(check) me.found.AppendByGoPath(check) continue } // if the repo is a go binary or plugin for a new release for // any library version change if check.GetRepoType() == "binary" || check.GetRepoType() == "plugin" { // check if the package dependancies changed, if so, re-publish if me.forge.FinalGoDepsCheckOk(check, false) { log.Printf("go.sum is perfect! %s\n", check.GetGoPath()) continue } log.Printf("dependancy checks indicate a new release is needed for %s\n", check.GetGoPath()) forceReleaseVersion(check) me.found.AppendByGoPath(check) } } me.forge.PrintHumanTable(me.found) } func printDone() { for _, gopath := range me.done { log.Info("printDone() THESE SHOULD NEVER REPEAT: already done:", gopath) } log.Sleep(5) } func alreadyDone(repo *gitpb.Repo) bool { for _, gopath := range me.done { // log.Info("WARNING already done", gopath, repo.GetGoPath()) // log.Info("WARNING already done", gopath, repo.GetGoPath()) // log.Info("WARNING already done", gopath, repo.GetGoPath()) if repo.GetGoPath() == gopath { log.Info("FOUND. RETURN TRUE. already done", gopath, repo.GetGoPath()) return true } } return false }