2024-02-09 11:50:16 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2024-02-14 16:06:52 -06:00
|
|
|
"path/filepath"
|
2024-02-09 11:50:16 -06:00
|
|
|
"strings"
|
|
|
|
|
2024-11-08 06:45:12 -06:00
|
|
|
"github.com/go-cmd/cmd"
|
|
|
|
|
2024-02-20 06:53:07 -06:00
|
|
|
"go.wit.com/lib/gui/repolist"
|
2024-02-14 16:06:52 -06:00
|
|
|
"go.wit.com/lib/gui/shell"
|
2024-02-09 11:50:16 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-11-07 05:15:54 -06:00
|
|
|
func doRelease() bool {
|
|
|
|
log.Info("doRelease() on", me.current.Name())
|
2024-02-14 12:14:33 -06:00
|
|
|
// double check release version logic
|
2024-02-20 16:11:00 -06:00
|
|
|
if me.release.releaseVersionB.String() != "release version "+me.release.version.String() {
|
|
|
|
log.Warn("something went wrong with the release.version:", me.release.version.String())
|
2024-02-09 11:50:16 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-20 16:11:00 -06:00
|
|
|
if strings.HasPrefix(me.release.version.String(), "v") {
|
|
|
|
log.Warn("everything is ok. version starts with v.", me.release.version.String())
|
2024-02-09 11:50:16 -06:00
|
|
|
} else {
|
2024-02-20 16:11:00 -06:00
|
|
|
log.Warn("version does not start with v.", me.release.version.String())
|
2024-02-09 11:50:16 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-11-16 04:59:21 -06:00
|
|
|
if shell.Exists("go.mod") {
|
|
|
|
log.Info("go.mod exists ok")
|
|
|
|
} else {
|
|
|
|
pwd, _ := os.Getwd()
|
|
|
|
log.Info("go.mod disappeared. need to run go mod init and go mod tidy here:", pwd)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-20 16:11:00 -06:00
|
|
|
curName := me.current.Status.GetCurrentBranchName()
|
|
|
|
mName := me.current.Status.GetMasterBranchName()
|
2024-02-09 11:50:16 -06:00
|
|
|
if curName != mName {
|
|
|
|
log.Info("\trepo is not working from main branch", curName, "!=", mName)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-20 16:11:00 -06:00
|
|
|
if !checkValidGoSum(me.current) {
|
2024-02-20 06:53:07 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-20 16:11:00 -06:00
|
|
|
log.Info("\ttag and push", curName, me.release.version.String(), me.releaseReasonS)
|
2024-02-09 11:50:16 -06:00
|
|
|
|
|
|
|
var all [][]string
|
|
|
|
all = append(all, []string{"git", "add", "-f", "go.mod"})
|
2024-02-20 16:11:00 -06:00
|
|
|
if me.current.Status.IsPrimitive() {
|
2024-02-09 11:50:16 -06:00
|
|
|
// don't add go.sum here. TODO: check for go.sum file and fail
|
|
|
|
} else {
|
|
|
|
all = append(all, []string{"git", "add", "-f", "go.sum"})
|
|
|
|
}
|
2024-11-06 20:28:31 -06:00
|
|
|
if ok, compiled, err := me.current.Status.IsProtobuf(); ok {
|
2024-11-05 05:57:59 -06:00
|
|
|
log.Info("\tIsProtobuf() == true")
|
|
|
|
if err != nil {
|
|
|
|
log.Info("\tERROR: There are protobuf files, but they are not compiled")
|
|
|
|
log.Info("\tERROR: can not continue")
|
2024-11-06 20:28:31 -06:00
|
|
|
os.Exit(-1)
|
2024-11-05 05:57:59 -06:00
|
|
|
}
|
|
|
|
log.Info("\tshould add the protobuf files here")
|
2024-11-06 20:28:31 -06:00
|
|
|
log.Info("\tcompiled files found:", compiled)
|
|
|
|
for _, s := range compiled {
|
|
|
|
log.Info("\tcompiled file found:", s)
|
|
|
|
all = append(all, []string{"git", "add", "-f", s})
|
|
|
|
}
|
2024-11-05 05:57:59 -06:00
|
|
|
} else {
|
|
|
|
log.Info("\tIsProtobuf() == false")
|
2024-11-05 04:46:59 -06:00
|
|
|
}
|
2024-02-09 11:50:16 -06:00
|
|
|
all = append(all, []string{"git", "commit", "-m", me.releaseReasonS})
|
|
|
|
all = append(all, []string{"git", "push"})
|
2024-02-20 16:11:00 -06:00
|
|
|
all = append(all, []string{"git", "tag", "-m", me.releaseReasonS, me.release.version.String()})
|
|
|
|
all = append(all, []string{"git", "push", "origin", me.release.version.String()})
|
2024-02-09 11:50:16 -06:00
|
|
|
|
2024-02-20 16:11:00 -06:00
|
|
|
if !me.current.Status.DoAll(all) {
|
|
|
|
log.Info("failed to make new release", me.release.version.String())
|
2024-02-14 12:14:33 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Info("RELEASE OK")
|
|
|
|
|
|
|
|
// 'publish' the version to the golang package versioning system
|
|
|
|
if !doPublishVersion() {
|
|
|
|
log.Info("PUBLISH FAILED")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("PUBLISH OK")
|
2024-02-29 21:57:13 -06:00
|
|
|
// me.current.SetGoState("RELEASED")
|
2024-02-14 12:14:33 -06:00
|
|
|
|
|
|
|
// unwind and re-tag. Now that the go.mod and go.sum are published, revert
|
|
|
|
// to the development branch
|
2024-02-20 16:11:00 -06:00
|
|
|
if !me.current.Status.RevertMasterToDevel() {
|
2024-02-14 12:14:33 -06:00
|
|
|
log.Info("Revert Failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// update tag
|
|
|
|
var retag [][]string
|
2024-02-20 16:11:00 -06:00
|
|
|
retag = append(retag, []string{"git", "tag", "--delete", me.release.version.String()})
|
|
|
|
retag = append(retag, []string{"git", "push", "--delete", "origin", me.release.version.String()})
|
|
|
|
retag = append(retag, []string{"git", "tag", "-m", me.releaseReasonS, me.release.version.String()})
|
|
|
|
retag = append(retag, []string{"git", "push", "origin", me.release.version.String()})
|
2024-02-14 12:14:33 -06:00
|
|
|
|
2024-02-20 16:11:00 -06:00
|
|
|
if !me.current.Status.DoAll(retag) {
|
2024-02-14 12:14:33 -06:00
|
|
|
log.Info("retag failed")
|
|
|
|
return false
|
|
|
|
}
|
2024-02-20 16:11:00 -06:00
|
|
|
log.Info("EVERYTHING OK. RERELEASED", me.current.Name())
|
2024-02-14 12:14:33 -06:00
|
|
|
|
|
|
|
// update the values in the GUI
|
2024-02-20 16:11:00 -06:00
|
|
|
me.current.NewScan()
|
2024-02-14 12:14:33 -06:00
|
|
|
|
|
|
|
// attempt to find another repo to release
|
2024-02-14 16:06:52 -06:00
|
|
|
if !doReleaseFindNext() {
|
2024-02-14 12:14:33 -06:00
|
|
|
log.Info("doReleaseFindNext() could not find a new")
|
2024-11-17 06:26:25 -06:00
|
|
|
log.Info("THIS PROBABLY MEANS THAT ACTUALLY WE ARE TOTALLY DONE?")
|
|
|
|
os.Setenv("FindNextDone", "true")
|
2024-02-14 12:14:33 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-20 16:11:00 -06:00
|
|
|
log.Info("GOOD TO RUN ANOTHER DAY ON:", me.current.Name())
|
2024-02-14 12:14:33 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-02-23 09:01:58 -06:00
|
|
|
func checkValidGoSum(repo *repolist.RepoRow) bool {
|
2024-02-20 06:53:07 -06:00
|
|
|
ok, err := me.repos.View.CheckValidGoSum(repo)
|
|
|
|
if err != nil {
|
2024-11-05 05:57:59 -06:00
|
|
|
log.Info("go mod tidy not ok", err)
|
2024-02-20 06:53:07 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
log.Info("repo has go.sum requirements that are clean")
|
2024-02-20 16:11:00 -06:00
|
|
|
// me.current.setGoSumStatus("CLEAN")
|
|
|
|
me.release.status.SetValue("GOOD")
|
|
|
|
me.release.notes.SetValue("CheckValidGoSum() does not seem to lie")
|
2024-02-20 06:53:07 -06:00
|
|
|
return true
|
|
|
|
}
|
2024-02-20 16:11:00 -06:00
|
|
|
me.release.notes.SetValue("CheckValidGoSum() failed")
|
2024-02-20 06:53:07 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-14 12:14:33 -06:00
|
|
|
// try to figure out if there is another package to update
|
|
|
|
func doReleaseFindNext() bool {
|
|
|
|
// scan for new repo
|
2024-02-20 20:42:54 -06:00
|
|
|
if findNext() {
|
|
|
|
log.Info("findNext() found something")
|
2024-02-14 12:14:33 -06:00
|
|
|
} else {
|
2024-02-20 20:42:54 -06:00
|
|
|
log.Info("findNext() could not find anything")
|
2024-02-14 12:14:33 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-20 16:11:00 -06:00
|
|
|
if checkValidGoSum(me.current) {
|
2024-02-14 12:14:33 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// this pulls the new tag from the golang package repository
|
|
|
|
// to insert the new version
|
|
|
|
func doPublishVersion() bool {
|
2024-02-20 16:11:00 -06:00
|
|
|
gopath := me.current.GoPath()
|
2024-11-08 06:45:12 -06:00
|
|
|
docmd := []string{"go", "get", "-v", gopath + "@" + me.release.version.String()}
|
|
|
|
log.Info("SHOULD RUN cmd HERE:", docmd)
|
2024-02-14 12:14:33 -06:00
|
|
|
|
|
|
|
// right now, you can't publish this because the go.* files in this project are screwed up
|
2024-02-20 16:11:00 -06:00
|
|
|
if me.release.guireleaser == nil {
|
2024-11-08 06:45:12 -06:00
|
|
|
log.Info("CAN NOT SELF UPDATE HERE. cmd =", docmd)
|
2024-02-14 12:14:33 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-14 16:06:52 -06:00
|
|
|
homeDir, _ := os.UserHomeDir()
|
|
|
|
gosum := filepath.Join(homeDir, "go/src/go.wit.com/apps/guireleaser/go.sum")
|
|
|
|
if !shell.Exists(gosum) {
|
|
|
|
log.Info("go.sum must exist here")
|
2024-02-20 16:11:00 -06:00
|
|
|
me.release.guireleaser.Status.MakeRedomod()
|
2024-02-14 16:06:52 -06:00
|
|
|
}
|
2024-02-23 11:31:07 -06:00
|
|
|
if me.current.Status.IsPrivate() {
|
|
|
|
// do not self update private repos
|
2024-11-08 06:45:12 -06:00
|
|
|
log.Info("This is a private repo and can not be self checked")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to pull from google
|
|
|
|
var result cmd.Status
|
|
|
|
if gopath == "go.wit.com/apps/guireleaser" {
|
|
|
|
log.Info("CAN NOT SELF UPDATE. cmd =", docmd)
|
|
|
|
log.Info("go get must be run from somewhere else other than guireleaser")
|
|
|
|
result = shell.PathRun("/home/jcarr/go/src/go.wit.com/apps/autotypist", docmd)
|
2024-02-23 11:31:07 -06:00
|
|
|
} else {
|
2024-11-08 06:45:12 -06:00
|
|
|
// publish go.mod & go.sum for use with go
|
|
|
|
os.Unsetenv("GO111MODULE")
|
|
|
|
log.Info("TRYING TO SELF UPDATE HERE. cmd =", docmd)
|
|
|
|
result = me.release.guireleaser.Status.Run(docmd)
|
|
|
|
}
|
|
|
|
if result.Error != nil {
|
|
|
|
log.Info("SELF UPDATE FAILED. error =", result.Error)
|
|
|
|
log.Info("SELF UPDATE FAILED. exit =", result.Exit)
|
|
|
|
log.Info("SELF UPDATE FAILED. out =", result.Stdout)
|
|
|
|
log.Info("SELF UPDATE FAILED")
|
|
|
|
return false
|
2024-02-14 12:14:33 -06:00
|
|
|
}
|
2024-11-08 06:45:12 -06:00
|
|
|
if result.Exit != 0 {
|
|
|
|
log.Info("SELF UPDATE FAILED. error =", result.Error)
|
|
|
|
log.Info("SELF UPDATE FAILED. exit =", result.Exit)
|
|
|
|
log.Info("SELF UPDATE FAILED. out =", result.Stdout)
|
|
|
|
log.Info("SELF UPDATE FAILED")
|
|
|
|
return false
|
2024-02-14 12:14:33 -06:00
|
|
|
}
|
2024-11-08 06:45:12 -06:00
|
|
|
log.Info("SELF UPDATE OK. out =", result.Stdout)
|
|
|
|
log.Info("SELF UPDATE WORKED")
|
|
|
|
return true
|
2024-02-09 11:50:16 -06:00
|
|
|
}
|