guireleaser/main.go

143 lines
3.2 KiB
Go
Raw Normal View History

package main
import (
2024-11-07 03:10:21 -06:00
"embed"
2024-12-15 17:03:51 -06:00
"errors"
"fmt"
"os"
"path/filepath"
2024-04-15 05:05:27 -05:00
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
2025-01-17 05:13:11 -06:00
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
2024-11-29 22:21:58 -06:00
"go.wit.com/lib/protobuf/forgepb"
2024-12-17 21:58:14 -06:00
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
2024-02-28 22:01:32 -06:00
var VERSION string
2025-01-17 06:20:55 -06:00
var ARGNAME string = "guireleaser"
2024-11-07 03:10:21 -06:00
//go:embed resources/*
var resources embed.FS
2024-12-02 08:45:13 -06:00
var argv args
2024-02-28 22:01:32 -06:00
func main() {
me = new(autoType)
2025-01-17 06:20:55 -06:00
// 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
2024-11-29 22:21:58 -06:00
me.forge = forgepb.Init()
2024-12-17 21:58:14 -06:00
me.found = new(gitpb.Repos)
2025-01-17 05:13:11 -06:00
fhelp.CheckGoModCleanExit()
2024-12-01 10:42:49 -06:00
// me.forge.ConfigPrintTable()
2024-11-29 22:21:58 -06:00
os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc())
2024-03-02 20:47:10 -06:00
// save the ENV var here
me.releaseReasonS = os.Getenv("GUIRELEASE_REASON")
2024-03-02 20:47:10 -06:00
if me.releaseReasonS == "" {
2024-12-15 17:03:51 -06:00
badExit(errors.New("shell ENV GUIRELEASE_REASON not set"))
}
2024-02-20 06:53:07 -06:00
// 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()
2024-11-07 03:10:21 -06:00
me.myGui.InitEmbed(resources)
me.myGui.Default()
2024-02-18 15:09:04 -06:00
// our main window
2024-02-28 22:01:32 -06:00
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)
2024-02-18 15:09:04 -06:00
// 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) {
2024-12-15 17:03:51 -06:00
badExit(errors.New("go.work must be deleted"))
}
2024-02-18 17:55:59 -06:00
log.Info("Creating the Release Window")
// initialize the repo list window
// which should be all the git repositories in ~/go/src & the .config file
2024-02-18 15:09:04 -06:00
me.repos = makeRepoView()
2024-02-18 17:55:59 -06:00
// the left side of the window options
globalDisplayOptions(me.mainBox)
2024-02-18 17:55:59 -06:00
// create the right side of the main window
createReleaseBox(me.mainBox)
2024-11-13 18:32:53 -06:00
// disable the gui until the repos are scanned
me.release.box.Disable()
me.Disable()
// scan in the State of all the repos
2024-02-18 17:55:59 -06:00
// TODO: should not really be necessary directly after init()
me.repos.View.ScanRepositories()
2024-12-15 22:53:01 -06:00
// todo: add this to forgepb
2024-12-16 00:19:03 -06:00
me.startRepo = me.forge.FindWorkingDirRepo()
2024-12-15 22:53:01 -06:00
2024-12-13 19:30:12 -06:00
if me.startRepo == nil {
2024-12-16 00:21:32 -06:00
pwd, _ := os.Getwd()
msg := fmt.Sprint("Can not run if pwd is not a repo", pwd)
2024-12-15 17:03:51 -06:00
badExit(errors.New(msg))
}
2024-02-18 17:55:59 -06:00
2025-01-28 11:36:06 -06:00
// 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)
}
}
2025-01-29 16:41:01 -06:00
me.Enable()
me.release.box.Enable()
2024-12-02 05:13:17 -06:00
2025-01-30 01:15:00 -06:00
/*
// 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()
2024-02-18 17:55:59 -06:00
}