summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go5
-rw-r--r--doPublish.go98
-rw-r--r--finalGoDepsCheckOk.go37
-rw-r--r--prepareReleaseNew.go135
4 files changed, 221 insertions, 54 deletions
diff --git a/argv.go b/argv.go
index dc376a9..61ab8f5 100644
--- a/argv.go
+++ b/argv.go
@@ -82,8 +82,9 @@ type UpgradeCmd struct {
}
type PublishCmd struct {
- All bool `arg:"--all" help:"show all the packages"`
- Gomod bool `arg:"--keep-gomod" help:"don't really do anything"`
+ Protobuf bool `arg:"--protobuf" help:"force all protobufs to be republished"`
+ Doit bool `arg:"--doit" help:"actually publish"`
+ // Gomod bool `arg:"--keep-gomod" help:"don't really do anything"`
}
type InstallCmd struct {
diff --git a/doPublish.go b/doPublish.go
index bd28a13..efa8af2 100644
--- a/doPublish.go
+++ b/doPublish.go
@@ -4,76 +4,70 @@
package main
import (
+ "errors"
"fmt"
- "os"
- "time"
- "go.wit.com/lib/fhelp"
- "go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/env"
"go.wit.com/lib/protobuf/argvpb"
- "go.wit.com/log"
)
func doPublish() error {
initForge()
- saferepo := me.forge.Repos.FindByNamespace("go.wit.com/lib/xgb") // safe to run things here
- if saferepo == nil {
- return log.Errorf("need a safe place to run GO commands from")
+ // publish := me.forge.RunOnReposNewDumb(me.forge.Repos, rePrepareReleaseNew) // doesn't use Rill()
+ publish := me.forge.RunOnReposNew(me.forge.Repos, rePrepareReleaseNew)
+ if publish != nil {
+ publish = publish.SortActual()
+ footer := publish.PrintPublishNewTB()
+ fmt.Printf("publish.len(%d) PrintPublishTable() footer: %s\n", publish.Len(), footer)
}
- os.Chdir(saferepo.FullPath)
+ if !env.True("--doit") {
+ return errors.New("run with --doit to actually try to publish")
+ }
+ // me.forge.RillFuncError(rillPurge)
- if os.Getenv("GUIRELEASE_REASON") == "" {
- log.Info("$ENV[GUIRELEASE_REASON] was not set")
- reason := fhelp.InputFromUser("set tag message:")
- if reason == "" {
- argvpb.BadExit("merge failed", fmt.Errorf("GUIRELEASE_REASON was blank"))
+ /*
+ saferepo := me.forge.Repos.FindByNamespace("go.wit.com/lib/xgb") // safe to run things here
+ if saferepo == nil {
+ return log.Errorf("need a safe place to run GO commands from")
}
- os.Setenv("GUIRELEASE_REASON", reason)
- }
+ os.Chdir(saferepo.FullPath)
- var cmd []string
+ if os.Getenv("GUIRELEASE_REASON") == "" {
+ log.Info("$ENV[GUIRELEASE_REASON] was not set")
+ reason := fhelp.InputFromUser("set tag message:")
+ if reason == "" {
+ argvpb.BadExit("merge failed", fmt.Errorf("GUIRELEASE_REASON was blank"))
+ }
+ os.Setenv("GUIRELEASE_REASON", reason)
+ }
- cmd = []string{"forge", "merge", "--all"}
- if _, err := shell.RunRealtimeError(cmd); err != nil {
- argvpb.BadExit("merge failed", nil)
- }
+ var cmd []string
- cmd = []string{"forge", "merge", "check"}
- if _, err := shell.RunRealtimeError(cmd); err != nil {
- if _, err := shell.RunVerbose(cmd); err != nil {
+ cmd = []string{"forge", "merge", "--all"}
+ if _, err := shell.RunRealtimeError(cmd); err != nil {
argvpb.BadExit("merge failed", nil)
}
- }
- // todo: os.Stat() file
- time.Sleep(time.Second)
- me.forge.Repos.Load()
- if err := doInstall(me.forge.Repos); err != nil {
- log.Info("doInstall() failed", err)
- argvpb.BadExit("merge failed", nil)
- }
+ cmd = []string{"forge", "merge", "check"}
+ if _, err := shell.RunRealtimeError(cmd); err != nil {
+ if _, err := shell.RunVerbose(cmd); err != nil {
+ argvpb.BadExit("merge failed", nil)
+ }
+ }
+ // todo: os.Stat() file
+ time.Sleep(time.Second)
+ me.forge.Repos.Load()
- if os.Getenv("GUIRELEASE_REASON") == "" {
- os.Setenv("GUIRELEASE_REASON", "automated")
- }
- cmd = []string{"guireleaser", "--gui", "andlabs", "--auto-run"}
- if argv.All {
- // publish everything. don't be quick about it
- // updates all go.mod and go.sum files for every repo
- // that has dependancy changes. todo: only do binaries
- } else {
- // only publish packages that have commits
- cmd = append(cmd, "quick")
- }
- if argv.Publish.Gomod {
- // don't delete the .pb.go and go.* files from the master branch right away
- cmd = append(cmd, "--keep-gomod")
- }
- if _, err := shell.RunRealtimeError(cmd); err != nil {
- log.Info("releaser failed", err)
- argvpb.BadExit("publishing failed", nil)
- }
+ if err := doInstall(me.forge.Repos); err != nil {
+ log.Info("doInstall() failed", err)
+ argvpb.BadExit("merge failed", nil)
+ }
+
+ if os.Getenv("GUIRELEASE_REASON") == "" {
+ os.Setenv("GUIRELEASE_REASON", "automated")
+ }
+ */
argvpb.GoodExit("PUBLISH WORKED")
return nil
diff --git a/finalGoDepsCheckOk.go b/finalGoDepsCheckOk.go
new file mode 100644
index 0000000..f492a32
--- /dev/null
+++ b/finalGoDepsCheckOk.go
@@ -0,0 +1,37 @@
+package main
+
+import (
+ "errors"
+ "fmt"
+ "path/filepath"
+
+ "go.wit.com/lib/env"
+ "go.wit.com/lib/protobuf/gitpb"
+)
+
+func finalGoDepsCheckOk(check *gitpb.Repo) error {
+ err := me.forge.FinalGoDepsCheckOk(check)
+ if err == nil {
+ // log.Info("FINDNEXT: forge.FinalGoDepsCheck(check) worked!")
+ return nil
+ }
+ // log.Printf("FINDNEXT: forge.FinalGoDepsCheck(check) err (%v)\n", err)
+ return err
+}
+
+func testGoDepsCheckOk(godeps *gitpb.GoDeps) error {
+ if godeps == nil {
+ return errors.New("testGoDepsCheckOk() godeps == nil")
+ }
+ all := godeps.SortByGoPath()
+ for all.Scan() {
+ depRepo := all.Next()
+ fullpath := filepath.Join(env.Get("gopath"), depRepo.GoPath)
+ found := me.forge.Repos.FindByFullPath(fullpath)
+ if found == nil {
+ continue
+ }
+ return fmt.Errorf("testGoDepsCheckOk() dep is being upgraded %s", depRepo.GoPath)
+ }
+ return nil
+}
diff --git a/prepareReleaseNew.go b/prepareReleaseNew.go
new file mode 100644
index 0000000..667f7b1
--- /dev/null
+++ b/prepareReleaseNew.go
@@ -0,0 +1,135 @@
+package main
+
+import (
+ "errors"
+ "fmt"
+
+ "go.wit.com/lib/env"
+ "go.wit.com/lib/protobuf/argvpb"
+ "go.wit.com/lib/protobuf/gitpb"
+ "go.wit.com/log"
+)
+
+func rePrepareReleaseNew(check *gitpb.Repo) error {
+ // me.forge.RillFuncError(rillRestore)
+
+ if me.forge.Config.IsReadOnly(check.GetGoPath()) {
+ // can't release readonly repos
+ return nil
+ }
+
+ if check.IsDirty() {
+ return errors.New("dirty")
+ }
+
+ master := check.GetMasterVersion()
+ lastTag := check.GetLastTag()
+
+ if me.forge.Config.IsPrivate(check.GetGoPath()) {
+ if master != lastTag {
+ return errors.New("WARNING: private repo")
+
+ }
+ return nil
+ }
+ // this is detailed. It makes sure the go.* files are absolutely perfect
+ if err := checkPublishedGodeps(check); err != nil {
+ // this means the published godeps are no longer up to date
+ // forceReleaseVersion(check)
+ // log.Info("checkPublishedGodeps failed with err", check.GetGoPath(), err)
+ return err
+ }
+
+ // if master != lastTag, always increment
+ if master != lastTag {
+ newmhash := check.GetTagHash(master)
+ oldlhash := check.GetTagHash(lastTag)
+ if newmhash == oldlhash {
+ // they are actually equal
+ return nil
+ }
+ b1, err := check.CountDiffObjects(oldlhash, newmhash)
+ if err != nil {
+ argvpb.BadExit("countdiff wrong", err)
+ }
+ b2, err := check.CountDiffObjects(newmhash, oldlhash)
+ if err != nil {
+ argvpb.BadExit("countdiff wrong", err)
+ }
+ if b1 != 0 {
+ log.Printf("HASH ERROR %-50s tag %s < %s\n", check.GetGoPath(), newmhash, oldlhash)
+ log.Info("old vs new count", b1, b2, "git merge", oldlhash)
+ }
+
+ if b1 == 0 && b2 == 0 {
+ log.Info("got to identical repo", check.GetGoPath(), b1, b2)
+ log.Info("got to identical repo", check.GetGoPath(), oldlhash, newmhash)
+ // actually identical. do nothing
+ return nil
+ }
+ if gitpb.IsGoTagVersionGreater(lastTag, master) {
+ // this function is not right really. the hash error above should catch it correctly
+ // log.Printf("PROBABLY NOT NEE %-50s tag %s < %s\n", check.GetGoPath(), lastTag, master)
+ s := fmt.Sprintf("gitpb.IsGoTagVersionGreater() LAST TAG %s != master %s", lastTag, master)
+ return errors.New(s)
+ }
+ log.Printf("NEED RELEASE FOR TAG %-50s tag %s != %s\n", check.GetGoPath(), master, lastTag)
+ // forceReleaseVersion(check)
+ return errors.New("master != lastTag")
+ }
+
+ if check.GetRepoType() == "protobuf" {
+ if env.True("--protobuf") {
+ // if --protobuf, this will force upgrade each one
+ s := log.Sprintf("NEED RELEASE FOR TYPE because --protobuf")
+ return errors.New(s)
+ }
+ }
+
+ // 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 err := finalGoDepsCheckOk(check); err == nil {
+ // log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
+ return nil
+ } else {
+ // go.sum has some version that isn't the current version
+ return err
+ }
+ return nil
+}
+
+// checks the published go.* files in ~/go/pkg/mod
+// checks the go.* files currently on disk in ~/go/src
+// TODO: compare these to each other // TODO: this is probably the missing piece to this whole thing not working right yet
+func checkPublishedGodeps(repo *gitpb.Repo) error {
+ godepsOld, err := repo.GoSumFromPkgDir()
+ if err != nil {
+ return err
+ }
+ if godepsOld != nil {
+ if err := testGoDepsCheckOk(godepsOld); err != nil {
+ return err
+ }
+ }
+ godepsNew, err := repo.GoSumFromRepo()
+ if err != nil {
+ return err
+ }
+ if godepsOld == nil {
+ if godepsNew == nil {
+ // is primative. probably very certainly so. this check seems to work
+ // log.Printf("%s published godeps == nil && real == nil\n", repo.GetGoPath())
+ // s := log.Sprintf("PRIMATIVE library? published godeps == nil && real == nil")
+ // return errors.New(s)
+ return nil
+ } else {
+ return fmt.Errorf("published godeps == nil vs real != nil")
+ }
+ }
+ if err := testGoDepsCheckOk(godepsNew); err != nil {
+ return err
+ }
+ return nil
+}