summaryrefslogtreecommitdiff
path: root/doPublish.go
blob: bd28a1341a9f49dc398d9da2ad422224fc3c2b62 (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"
	"os"
	"time"

	"go.wit.com/lib/fhelp"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/argvpb"
	"go.wit.com/log"
)

func doPublish() error {
	initForge()

	saferepo := me.forge.Repos.FindByNamespace("go.wit.com/lib/xgb") // safe to run things here
	if saferepo == nil {
		return log.Errorf("need a safe place to run GO commands from")
	}
	os.Chdir(saferepo.FullPath)

	if os.Getenv("GUIRELEASE_REASON") == "" {
		log.Info("$ENV[GUIRELEASE_REASON] was not set")
		reason := fhelp.InputFromUser("set tag message:")
		if reason == "" {
			argvpb.BadExit("merge failed", fmt.Errorf("GUIRELEASE_REASON was blank"))
		}
		os.Setenv("GUIRELEASE_REASON", reason)
	}

	var cmd []string

	cmd = []string{"forge", "merge", "--all"}
	if _, err := shell.RunRealtimeError(cmd); err != nil {
		argvpb.BadExit("merge failed", nil)
	}

	cmd = []string{"forge", "merge", "check"}
	if _, err := shell.RunRealtimeError(cmd); err != nil {
		if _, err := shell.RunVerbose(cmd); err != nil {
			argvpb.BadExit("merge failed", nil)
		}
	}
	// todo: os.Stat() file
	time.Sleep(time.Second)
	me.forge.Repos.Load()

	if err := doInstall(me.forge.Repos); err != nil {
		log.Info("doInstall() failed", err)
		argvpb.BadExit("merge failed", nil)
	}

	if os.Getenv("GUIRELEASE_REASON") == "" {
		os.Setenv("GUIRELEASE_REASON", "automated")
	}
	cmd = []string{"guireleaser", "--gui", "andlabs", "--auto-run"}
	if argv.All {
		// publish everything. don't be quick about it
		// updates all go.mod and go.sum files for every repo
		// that has dependancy changes. todo: only do binaries
	} else {
		// only publish packages that have commits
		cmd = append(cmd, "quick")
	}
	if argv.Publish.Gomod {
		// don't delete the .pb.go and go.* files from the master branch right away
		cmd = append(cmd, "--keep-gomod")
	}
	if _, err := shell.RunRealtimeError(cmd); err != nil {
		log.Info("releaser failed", err)
		argvpb.BadExit("publishing failed", nil)
	}

	argvpb.GoodExit("PUBLISH WORKED")
	return nil
}