211 lines
5.3 KiB
Go
211 lines
5.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"go.wit.com/dev/alexflint/arg"
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/gui/gowit"
|
|
"go.wit.com/lib/gui/repolist"
|
|
"go.wit.com/lib/gui/shell"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
var VERSION string
|
|
var myargs args
|
|
|
|
func main() {
|
|
me = new(autoType)
|
|
|
|
// parse the command line
|
|
arg.MustParse(&myargs)
|
|
|
|
// save the ENV var here
|
|
me.releaseReasonS = os.Getenv("GUIRELEASE_REASON")
|
|
|
|
if me.releaseReasonS == "" {
|
|
log.Info("GUIRELEASE_VERSION not set")
|
|
os.Exit(0)
|
|
}
|
|
|
|
// unset the go development ENV var to generate release files
|
|
// this is required for go mod init & tidy. Also, if the
|
|
// user drops to a shell or xterm, then they shouldn't be set there either
|
|
os.Unsetenv("GO111MODULE")
|
|
|
|
me.myGui = gui.New()
|
|
me.myGui.Default()
|
|
|
|
// our main window
|
|
me.mainWindow = me.myGui.NewWindow("GUI release manager " + VERSION)
|
|
me.mainBox = me.mainWindow.NewBox("bw hbox", true)
|
|
|
|
// sanity check of things that might be around that mess
|
|
// up things later
|
|
// if you have a go.work file, you must delete it
|
|
// TODO: check for go.work files anywhere
|
|
homeDir, _ := os.UserHomeDir()
|
|
gowork := filepath.Join(homeDir, "go/src/go.work")
|
|
if shell.Exists(gowork) {
|
|
log.Info("go.work must be deleted")
|
|
os.Exit(0)
|
|
}
|
|
|
|
// sanity check of things that might be around that mess
|
|
// up things later
|
|
// check to make sure we have a go.sum here
|
|
gosum := filepath.Join(homeDir, "go/src/go.wit.com/apps/guireleaser/go.sum")
|
|
if !shell.Exists(gosum) {
|
|
log.Info("go.sum must exist here")
|
|
os.Exit(0)
|
|
}
|
|
|
|
log.Info("Creating the Release Window")
|
|
|
|
// initialize the repo list window
|
|
// which should be all the git repositories in ~/go/src & the .config file
|
|
me.repos = makeRepoView()
|
|
|
|
if myargs.DumpVersions {
|
|
gowit.DumpVersions(me.repos.View)
|
|
os.Exit(0)
|
|
}
|
|
// the left side of the window options
|
|
globalDisplayOptions(me.mainBox)
|
|
|
|
// create the right side of the main window
|
|
createReleaseBox(me.mainBox)
|
|
|
|
// disable the open repo button. this isn't really important
|
|
// but does indicates the app (and toolkit) is working
|
|
// this can be removed later, but in these early days, I'm using this
|
|
// tool to release the code for this app, the gui and the gui toolkits
|
|
// and sometimes they lie, don't display stuff, don't even disable things
|
|
// so I can't trust even what I see. It's complicated right now still.
|
|
me.release.openrepo.Disable()
|
|
|
|
me.Disable()
|
|
|
|
// parse config file and scan for .git repos
|
|
me.repos.initRepoList()
|
|
setTargetVersion()
|
|
|
|
// register a Show/Hide function for the repo list table
|
|
me.repos.View.RegisterHideFunction(hideFunction)
|
|
|
|
// scan in the State of all the repos
|
|
// TODO: should not really be necessary directly after init()
|
|
me.repos.View.ScanRepositories()
|
|
|
|
// the repo from the command line
|
|
var myrepo *repolist.RepoRow
|
|
|
|
// find myself. the guireleaser directory is used as a working scratchpad
|
|
// for running go commands that can mess up the go.* files
|
|
for _, repo := range me.repos.View.AllRepos() {
|
|
if repo.GoPath() == "go.wit.com/apps/guireleaser" {
|
|
if me.release.guireleaser == nil {
|
|
me.release.guireleaser = repo
|
|
}
|
|
}
|
|
if repo.GoPath() == myargs.Repo {
|
|
myrepo = repo
|
|
}
|
|
}
|
|
|
|
if myargs.Repo != "" {
|
|
me.mainWindow.Hide()
|
|
if myrepo == nil {
|
|
log.Info("could not find", myargs.Repo)
|
|
os.Exit(0)
|
|
}
|
|
log.Info("only going to do repo:", myrepo.GoPath())
|
|
tmp := myargs.Reason
|
|
if tmp == "" {
|
|
tmp = os.Getenv("GUIRELEASE_REASON")
|
|
}
|
|
if tmp == "" {
|
|
tmp = "made by guireleaser"
|
|
}
|
|
|
|
// increment all the versions
|
|
for _, repo := range me.repos.View.AllRepos() {
|
|
if whitelist(repo.GoPath()) {
|
|
continue
|
|
}
|
|
if repo.ReadOnly() {
|
|
continue
|
|
}
|
|
lasttag := repo.Status.LastTag()
|
|
if repo.Status.GetCurrentVersion() == lasttag {
|
|
log.Info("skipping unchanged repo", repo.Status.GoPath())
|
|
repo.Status.SetTargetVersion(lasttag)
|
|
continue
|
|
}
|
|
repo.Status.IncrementRevisionVersion("go-clone")
|
|
}
|
|
// rescan all the repos
|
|
me.repos.View.ScanRepositories()
|
|
|
|
myrepo.Status.MakeRedomod()
|
|
myrepo.Status.IncrementRevisionVersion(tmp)
|
|
_, err := me.repos.View.CheckValidGoSum(myrepo)
|
|
if err != nil {
|
|
log.Info("go mod tidy not ok", err)
|
|
return
|
|
}
|
|
if !checkValidGoSum(myrepo) {
|
|
log.Info("go.sum checks failed")
|
|
os.Exit(0)
|
|
}
|
|
setCurrentRepo(myrepo, "should be good to release", "pretty sure")
|
|
log.Info("DO THE RELEASE HERE")
|
|
log.Info("going to release", myrepo.GoPath(), "as version", myrepo.Status.GetTargetVersion())
|
|
if myargs.DryRun {
|
|
log.Info("--dry-run == true")
|
|
} else {
|
|
doRelease()
|
|
}
|
|
os.Exit(0)
|
|
}
|
|
|
|
if me.release.guireleaser == nil {
|
|
log.Info("Can not release if guireleaser was not found")
|
|
os.Exit(0)
|
|
}
|
|
me.Enable()
|
|
|
|
// intermittently scans the status indefinitly
|
|
me.repos.View.Watchdog(func() {
|
|
log.Info("In main()")
|
|
// processing is done. update the repo summary box
|
|
// me.summary.Update()
|
|
})
|
|
}
|
|
|
|
// start the initail scan and make sure each repo is set
|
|
// to the master branch
|
|
func setAllBranchesToMaster() bool {
|
|
var worked bool = true
|
|
for _, repo := range me.repos.View.AllRepos() {
|
|
if repo.ReadOnly() {
|
|
continue
|
|
}
|
|
if repo.IsDirty() {
|
|
continue
|
|
}
|
|
if whitelist(repo.GoPath()) {
|
|
continue
|
|
}
|
|
if repo.Status.CheckoutMaster() {
|
|
log.Warn("git checkout master branch worked", repo.Name())
|
|
} else {
|
|
log.Warn("git checkout master branch failed", repo.Name())
|
|
worked = false
|
|
}
|
|
// repo.NewScan()
|
|
}
|
|
return worked
|
|
}
|