2024-02-09 11:50:16 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func doRelease() bool {
|
2024-02-14 12:14:33 -06:00
|
|
|
log.Info("doRelease() on", release.current.String())
|
|
|
|
// double check release version logic
|
2024-02-09 11:50:16 -06:00
|
|
|
if release.releaseVersionB.String() != "release version "+release.version.String() {
|
|
|
|
log.Warn("something went wrong with the release.version:", release.version.String())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(release.version.String(), "v") {
|
|
|
|
log.Warn("everything is ok. version starts with v.", release.version.String())
|
|
|
|
} else {
|
|
|
|
log.Warn("version does not start with v.", release.version.String())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch release.status.String() {
|
|
|
|
case "PRIMATIVE":
|
|
|
|
log.Warn("can do PRIMATIVE", release.version.String())
|
|
|
|
case "GOOD":
|
|
|
|
log.Warn("GOOD. lots of go.sum checks passed", release.version.String())
|
|
|
|
case "manually chosen":
|
|
|
|
log.Warn("attempting manual release", release.version.String())
|
2024-02-14 12:14:33 -06:00
|
|
|
/*
|
2024-02-09 11:50:16 -06:00
|
|
|
case "NOT READY":
|
|
|
|
log.Warn("attempting to release. TODO: recheck go.sum here", release.version.String())
|
|
|
|
log.Warn("Sleep 10")
|
|
|
|
log.Sleep(10)
|
|
|
|
case "UNRELEASED":
|
|
|
|
log.Warn("attempting to release. TODO: dig deep on go.sum here", release.version.String())
|
|
|
|
log.Warn("Sleep 10")
|
|
|
|
log.Sleep(10)
|
2024-02-14 12:14:33 -06:00
|
|
|
*/
|
2024-02-09 11:50:16 -06:00
|
|
|
default:
|
|
|
|
log.Warn("what is this?", release.version.String(), release.status.String())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if release.current.status.ReadOnly() {
|
|
|
|
log.Info("sorry, it's read-only")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if release.current.status.CheckDirty() {
|
|
|
|
log.Info("sorry, it's still dirty")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
curName := release.current.status.GetCurrentBranchName()
|
|
|
|
mName := release.current.status.GetMasterBranchName()
|
|
|
|
if curName != mName {
|
|
|
|
log.Info("\trepo is not working from main branch", curName, "!=", mName)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("\ttag and push", curName, release.version.String(), me.releaseReasonS)
|
|
|
|
|
|
|
|
var all [][]string
|
|
|
|
all = append(all, []string{"git", "add", "-f", "go.mod"})
|
|
|
|
if release.current.status.CheckPrimativeGoMod() {
|
|
|
|
// don't add go.sum here. TODO: check for go.sum file and fail
|
|
|
|
} else {
|
|
|
|
all = append(all, []string{"git", "add", "-f", "go.sum"})
|
|
|
|
}
|
|
|
|
all = append(all, []string{"git", "commit", "-m", me.releaseReasonS})
|
|
|
|
all = append(all, []string{"git", "push"})
|
|
|
|
all = append(all, []string{"git", "tag", "-m", me.releaseReasonS, release.version.String()})
|
|
|
|
all = append(all, []string{"git", "push", "origin", release.version.String()})
|
|
|
|
|
2024-02-14 12:14:33 -06:00
|
|
|
if !release.current.status.DoAll(all) {
|
|
|
|
log.Info("failed to make new release", release.version.String())
|
|
|
|
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")
|
|
|
|
release.current.setGoSumStatus("RELEASED")
|
|
|
|
|
|
|
|
// unwind and re-tag. Now that the go.mod and go.sum are published, revert
|
|
|
|
// to the development branch
|
|
|
|
if ! release.current.status.RevertMasterToDevel() {
|
|
|
|
log.Info("Revert Failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// update tag
|
|
|
|
var retag [][]string
|
|
|
|
retag = append(retag, []string{"git", "tag", "--delete", release.version.String()})
|
|
|
|
retag = append(retag, []string{"git", "push", "--delete", "origin", release.version.String()})
|
|
|
|
retag = append(retag, []string{"git", "tag", "-m", me.releaseReasonS, release.version.String()})
|
|
|
|
retag = append(retag, []string{"git", "push", "origin", release.version.String()})
|
|
|
|
|
|
|
|
if !release.current.status.DoAll(retag) {
|
|
|
|
log.Info("retag failed")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Info("EVERYTHING OK. RERELEASED", release.current.String())
|
|
|
|
|
|
|
|
// update the package versions used for checking go.sum validity
|
|
|
|
release.current.status.UpdateCurrent()
|
|
|
|
cbname := release.current.status.GetCurrentBranchName()
|
|
|
|
cbversion := release.current.status.GetCurrentBranchVersion()
|
|
|
|
lasttag := release.current.status.GetLastTagVersion()
|
|
|
|
// update the values in the GUI
|
|
|
|
release.current.lastTag.SetLabel(lasttag)
|
|
|
|
release.current.vLabel.SetLabel(cbname + " " + cbversion)
|
|
|
|
|
|
|
|
// attempt to find another repo to release
|
|
|
|
if ! doReleaseFindNext() {
|
|
|
|
log.Info("doReleaseFindNext() could not find a new")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Info("GOOD TO RUN ANOTHER DAY ON:", release.current.String())
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to figure out if there is another package to update
|
|
|
|
func doReleaseFindNext() bool {
|
|
|
|
// scan for new repo
|
|
|
|
if findNextDirty("") {
|
|
|
|
log.Info("findNextDirty() found something")
|
|
|
|
} else {
|
|
|
|
log.Info("findNextDirty() could not find anything")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
release.current.status.CheckSafeGoSumRemake()
|
|
|
|
if release.current.status.MakeRedomod() {
|
|
|
|
log.Info("Redo mod ok")
|
|
|
|
} else {
|
|
|
|
log.Info("go mod tidy not ok")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if ok, _ := release.current.status.CheckGoSum(); ok {
|
|
|
|
log.Info("repo has go.sum requirements that are clean")
|
|
|
|
// release.current.setGoSumStatus("CLEAN")
|
|
|
|
release.status.SetValue("GOOD")
|
|
|
|
release.notes.SetValue("CheckGoSum() does not seem to lie")
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// this pulls the new tag from the golang package repository
|
|
|
|
// to insert the new version
|
|
|
|
func doPublishVersion() bool {
|
|
|
|
gopath := release.current.String()
|
|
|
|
cmd := []string{"go", "get", "-v", gopath + "@" + release.version.String()}
|
|
|
|
log.Info("SHOULD RUN cmd HERE:", cmd)
|
|
|
|
|
|
|
|
// right now, you can't publish this because the go.* files in this project are screwed up
|
|
|
|
if release.guireleaser == nil {
|
|
|
|
log.Info("CAN NOT SELF UPDATE HERE. cmd =", cmd)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
os.Unsetenv("GO111MODULE")
|
|
|
|
log.Info("TRYING TO SELF UPDATE HERE. cmd =", cmd)
|
|
|
|
err, out := release.guireleaser.status.RunCmd(cmd)
|
|
|
|
if gopath == "go.wit.com/apps/guireleaser" {
|
|
|
|
// ignore errors on updating myself
|
|
|
|
log.Info("IGNORE SELF UPDATE ERROR. cmd =", cmd)
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
log.Info("SELF UPDATE OK. out =", out)
|
|
|
|
log.Info("SELF UPDATE WORKED")
|
|
|
|
release.current.setGoSumStatus("RELEASED")
|
|
|
|
return true
|
|
|
|
}
|
2024-02-09 11:50:16 -06:00
|
|
|
return false
|
|
|
|
}
|