summaryrefslogtreecommitdiff
path: root/main.go
blob: 49b02cb7e3e744a4d4850d353f093b10cf104674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main

import (
	"embed"
	"errors"
	"fmt"
	"os"
	"path/filepath"

	"go.wit.com/lib/fhelp"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/prep"
	"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 BUILDTIME string

var ARGNAME string = "guireleaser"

//go:embed resources/*
var resources embed.FS

var argv args

func main() {
	me = new(autoType)
	me.myGui = prep.Gui()       // prepares the GUI package for go-args
	me.auto = prep.Bash3(&argv) // this line should be:  prep.Bash(&argv)

	me.forge = forgepb.Init()
	me.forge.ScanRepoDir() // looks for new dirs, checks existing repos for changes
	me.found = new(gitpb.Repos)

	fhelp.CheckGoModCleanExit()

	// me.forge.ConfigPrintTable()
	os.Setenv("REPO_WORK_PATH", me.forge.Config.ReposDir)

	// 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.Start() // loads the GUI toolkit

	// our main window
	me.mainWindow = gadgets.RawBasicWindow("GUI release manager " + VERSION)
	me.mainWindow.Custom = func() {
		log.Warn("Window closed. forge configsave")
		// sets the hidden flag to false so Toggle() works
		okExit("")
	}
	me.mainWindow.Make()
	me.mainWindow.Show()

	me.mainBox = me.mainWindow.Box()

	// 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")

	// 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()

	// todo: add this to forgepb
	me.startRepo = me.forge.FindWorkingDirRepo()

	if _, count, _, err := me.forge.IsEverythingOnMaster(); err != nil {
		log.Info("not everything is on the master branch (", count, "repos)")
		if argv.Quick != nil {
			// quick also means ignore the master branch check
			argv.Force = true
		}
		if !argv.Force {
			os.Exit(-1)
		}
	}

	if me.startRepo == nil {
		pwd, _ := os.Getwd()
		msg := fmt.Sprint("Can not run if pwd is not a repo", pwd)
		badExit(errors.New(msg))
	}

	me.forge.RillFuncError(rillPurge)

	// 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")
			okExit("found nothing")
		}
	}
	me.Enable()
	me.release.box.Enable()

	// start the http server for polling status
	startHTTP()
}