143 lines
3.2 KiB
Go
143 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"go.wit.com/dev/alexflint/arg"
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/fhelp"
|
|
"go.wit.com/lib/gui/shell"
|
|
"go.wit.com/lib/protobuf/forgepb"
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
var VERSION string
|
|
var ARGNAME string = "guireleaser"
|
|
|
|
//go:embed resources/*
|
|
var resources embed.FS
|
|
|
|
var argv args
|
|
|
|
func main() {
|
|
me = new(autoType)
|
|
|
|
// parse the command line
|
|
me.pp = arg.MustParse(&argv)
|
|
|
|
if argv.Bash {
|
|
argv.doBash()
|
|
os.Exit(0)
|
|
}
|
|
if len(argv.BashAuto) != 0 {
|
|
argv.doBashAuto()
|
|
os.Exit(0)
|
|
}
|
|
|
|
// load the ~/.config/forge/ config
|
|
me.forge = forgepb.Init()
|
|
me.found = new(gitpb.Repos)
|
|
|
|
fhelp.CheckGoModCleanExit()
|
|
|
|
// me.forge.ConfigPrintTable()
|
|
os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc())
|
|
|
|
// save the ENV var here
|
|
me.releaseReasonS = os.Getenv("GUIRELEASE_REASON")
|
|
|
|
if me.releaseReasonS == "" {
|
|
badExit(errors.New("shell ENV GUIRELEASE_REASON not set"))
|
|
}
|
|
|
|
// 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.InitEmbed(resources)
|
|
me.myGui.Default()
|
|
|
|
// our main window
|
|
me.mainWindow = me.myGui.NewWindow("GUI release manager " + VERSION)
|
|
me.mainWindow.Custom = func() {
|
|
log.Warn("Window closed. forge configsave")
|
|
// sets the hidden flag to false so Toggle() works
|
|
me.forge.ConfigSave()
|
|
okExit("")
|
|
}
|
|
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) {
|
|
badExit(errors.New("go.work must be deleted"))
|
|
}
|
|
|
|
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()
|
|
|
|
// the left side of the window options
|
|
globalDisplayOptions(me.mainBox)
|
|
|
|
// create the right side of the main window
|
|
createReleaseBox(me.mainBox)
|
|
|
|
// disable the gui until the repos are scanned
|
|
me.release.box.Disable()
|
|
me.Disable()
|
|
|
|
// scan in the State of all the repos
|
|
// TODO: should not really be necessary directly after init()
|
|
me.repos.View.ScanRepositories()
|
|
|
|
// todo: add this to forgepb
|
|
me.startRepo = me.forge.FindWorkingDirRepo()
|
|
|
|
if me.startRepo == nil {
|
|
pwd, _ := os.Getwd()
|
|
msg := fmt.Sprint("Can not run if pwd is not a repo", pwd)
|
|
badExit(errors.New(msg))
|
|
}
|
|
|
|
// run this each time something gets published successfully
|
|
rePrepareRelease()
|
|
|
|
if findNext() {
|
|
log.Info("prepare release findNext() returned true")
|
|
} else {
|
|
// check if nothing is found an exit?
|
|
if me.found.Len() == 0 {
|
|
log.Info("nothing found to publish")
|
|
os.Exit(0)
|
|
}
|
|
}
|
|
me.Enable()
|
|
me.release.box.Enable()
|
|
|
|
/*
|
|
// intermittently scans the status indefinitly
|
|
me.repos.View.Watchdog(func() {
|
|
log.Info("In main()")
|
|
log.Sleep(10)
|
|
// processing is done. update the repo summary box
|
|
// me.summary.Update()
|
|
})
|
|
*/
|
|
// start the http server for polling status
|
|
startHTTP()
|
|
}
|