summaryrefslogtreecommitdiff
path: root/main.go
blob: 3f6be1e25874f096c837cbfd1d46977e501ce37e (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main

import (
	"embed"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"time"

	"go.wit.com/gui"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

// TODO: autocompute these in the gui
var releaseReasonS string
var releaseVersion string
var widgetVersion string

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

func main() {
	me = new(autoType)
	me.allrepos = make(map[string]*repo)

	// TODO: autocompute these in the gui
	releaseReasonS = os.Getenv("GUIRELEASE_REASON")
	releaseVersion = os.Getenv("GUIRELEASE_VERSION")
	widgetVersion = os.Getenv("GUIRELEASE_WIDGET")

	if releaseVersion == "" {
		log.Info("GUIRELEASE_VERSION not set")
		os.Exit(0)
	}

	me.myGui = gui.New()
	me.myGui.InitEmbed(resToolkit)
	me.myGui.Default()

	me.mainWindow = me.myGui.NewWindow("GUI release manager")
	me.mainBox = me.mainWindow.NewBox("bw hbox", true)

	globalDisplayOptions(me.mainBox)

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

	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)
	}

	repoworld()

	me.releaseReasonS = releaseReasonS

	for i, repo := range me.allrepos {
		if repo == nil {
			log.Info("initial scan i = nil", i)
			continue
		}

		log.Info("initial scan repo", repo.String())
		if repo.status == nil {
			log.Info("repo.status == nil", repo.String())
			continue
		}

		repo.status.UpdateNew()
		repo.newScan()

		if repo.String() == "go.wit.com/widget" {
			repo.targetVersion.SetText("v" + widgetVersion)
		} else {
			repo.targetVersion.SetText("v" + releaseVersion)
		}
		if strings.HasPrefix(repo.String(), "go.wit.com/dev/") {
			lasttag := repo.status.GetLastTagVersion()
			repo.targetVersion.SetText(lasttag)
		}
		// if repo.String() == "go.wit.com/apps/guireleaser" {
	}
	log.Info("Creating the Release Window")

	createReleaseBox(me.mainBox)
	// createUnreleaseBox(me.mainBox)

	for _, repo := range me.allrepos {
		if repo.status.ReadOnly() {
			continue
		}
		if whitelist(repo.String()) {
			continue
		}
		if repo.status.CheckoutMaster() {
			log.Warn("set master branch worked", repo.String())
			repo.newScan()
		} else {
			repo.newScan()
			log.Warn("set master branch failed", repo.String())
			log.Warn("set master branch failed", repo.String())
			log.Warn("set master branch failed", repo.String())
		}
	}

	showHideRepos()

	release.openrepo.Disable()

	// scan repos every 30 seconds
	// check every second for the checkbox changing
	var i int = 60
	myTicker(1*time.Second, "newScan()", func() {
		i += 1
		if !me.scanEveryMinute.Checked() {
			if i < 60 {
				i = 60
			}
			// print every 13 seconds
			if i%13 == 0 {
				log.Info("Not auto scanning", i)
			}
			return
		}
		if i < 60 {
			return
		}
		i = 0
		duration := timeFunction(func() {
			scanGoSum()
			for _, repo := range me.allrepos {
				repo.newScan()
			}
		})
		s := fmt.Sprint(duration)
		me.autoWorkingPwd.SetText(s)
	})
}