guireleaser/main.go

189 lines
4.7 KiB
Go
Raw Normal View History

package main
import (
2024-11-07 03:10:21 -06:00
"embed"
"os"
"path/filepath"
2024-04-15 05:05:27 -05:00
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
"go.wit.com/lib/gui/shell"
2024-11-29 22:21:58 -06:00
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
)
2024-02-28 22:01:32 -06:00
var VERSION string
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)
// load the ~/.config/forge/ config
2024-11-29 22:21:58 -06:00
me.forge = forgepb.Init()
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-09 22:02:32 -06:00
// parse the command line
2024-12-02 08:45:13 -06:00
arg.MustParse(&argv)
2024-03-09 22:02:32 -06:00
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-11-07 01:39:26 -06:00
log.Info("shell ENV GUIRELEASE_REASON not set")
os.Exit(0)
}
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.mainBox = me.mainWindow.NewBox("bw hbox", true)
// start the http server for polling status
go startHTTP()
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) {
log.Info("go.work must be deleted")
os.Exit(0)
}
2024-11-13 17:03:03 -06:00
/*
// 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)
}
*/
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)
// 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()
2024-02-18 17:55:59 -06:00
2024-11-13 18:32:53 -06:00
// disable the gui until the repos are scanned
me.release.box.Disable()
me.Disable()
// register a Show/Hide function for the repo list table
me.repos.View.RegisterHideFunction(hideFunction)
// 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()
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
if me.forge.IsReadOnly(repo.GoPath()) {
repo.Status.SetReadOnly(true)
} else {
repo.Status.SetReadOnly(false)
}
if me.forge.IsPrivate(repo.GoPath()) {
repo.Status.SetPrivate(true)
} else {
repo.Status.SetPrivate(false)
}
}
2024-03-09 22:02:32 -06:00
// the repo from the command line
// var myrepo *repolist.RepoRow
2024-03-09 22:02:32 -06:00
// find myself. the guireleaser directory is used as a working scratchpad
// for running go commands that can mess up the go.* files
loop = me.repos.View.ReposSortByName()
2024-11-16 00:07:53 -06:00
for loop.Scan() {
repo := loop.Repo()
if repo.GoPath() == "go.wit.com/apps/guireleaser" {
if me.release.guireleaser == nil {
me.release.guireleaser = repo
}
}
2024-11-29 22:32:25 -06:00
log.Info("repolist.ReposSortByName() found", repo.GoPath())
/*
if repo.GoPath() == myargs.Repo {
myrepo = repo
}
*/
2024-03-09 22:02:32 -06:00
}
if me.release.guireleaser == nil {
log.Info("Can not release if guireleaser was not found")
os.Exit(0)
}
2024-02-18 17:55:59 -06:00
me.Enable()
2024-12-02 05:13:17 -06:00
// set all branches to master & findNext()
makePrepareRelease()
2024-02-18 17:55:59 -06:00
// 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()
})
}
2024-02-19 14:40:21 -06:00
// start the initail scan and make sure each repo is set
// to the master branch
func setAllBranchesToMaster() bool {
var worked bool = true
2024-11-16 00:07:53 -06:00
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
if repo.ReadOnly() {
continue
}
if repo.IsDirty() {
continue
}
2024-11-13 18:13:20 -06:00
if repo.Status.Whitelist {
2024-02-19 19:42:14 -06:00
continue
}
2024-02-18 17:55:59 -06:00
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
2024-02-18 17:55:59 -06:00
}
2024-02-19 19:42:14 -06:00
// repo.NewScan()
2024-02-18 17:55:59 -06:00
}
return worked
2024-02-19 14:40:21 -06:00
}