guireleaser/doRelease.go

248 lines
7.5 KiB
Go

// This is a simple example
package main
import (
"os"
"path/filepath"
"strings"
"github.com/go-cmd/cmd"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
func doRelease() bool {
log.Info("doRelease() on", me.current.Name())
// double check release version logic
if me.release.releaseVersionB.String() != "release version "+me.release.version.String() {
log.Warn("something went wrong with the release.version:", me.release.version.String())
return false
}
if strings.HasPrefix(me.release.version.String(), "v") {
log.Warn("everything is ok. version starts with v.", me.release.version.String())
} else {
log.Warn("version does not start with v.", me.release.version.String())
return false
}
if shell.Exists("go.mod") {
log.Info("go.mod exists ok")
} else {
log.Info("go.mod missing")
return false
/*
pwd, _ := os.Getwd()
log.Info("go.mod disappeared. need to run go mod init and go mod tidy here:", pwd)
shell.RunRealtime([]string{"go", "mod", "init"})
shell.RunRealtime([]string{"go", "mod", "tidy"})
shell.RunRealtime([]string{"go", "mod", "edit", "-go=1.20"})
*/
}
curName := me.current.Status.GetCurrentBranchName()
mName := me.current.Status.GetMasterBranchName()
if curName != mName {
log.Info("\trepo is not working from main branch", curName, "!=", mName)
return false
}
check := me.forge.Repos.FindByGoPath(me.current.GoPath())
if check == nil {
log.Info("boo, you didn't git clone", me.current.GoPath())
return false
}
if !me.forge.FinalGoDepsCheckOk(check) {
log.Info("the go.mod file is wrong. fix it here?", check.GetGoPath())
os.Exit(-1)
return false
}
log.Info("\ttag and push", curName, me.release.version.String(), me.releaseReasonS)
var all [][]string
all = append(all, []string{"git", "add", "-f", "go.mod"})
if ok, _ := check.IsPrimitive(); ok {
// don't add go.sum here. TODO: check for go.sum file and fail
} else {
all = append(all, []string{"git", "add", "-f", "go.sum"})
}
if ok, compiled, err := me.current.IsProtobuf(); ok {
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")
os.Exit(-1)
}
log.Info("\tshould add the protobuf files here")
log.Info("\tcompiled files found:", compiled)
for _, s := range compiled {
log.Info("\tcompiled file found:", s)
all = append(all, []string{"git", "add", "-f", s})
}
} else {
log.Info("\tIsProtobuf() == false")
}
all = append(all, []string{"git", "commit", "-m", me.releaseReasonS})
all = append(all, []string{"git", "push"})
all = append(all, []string{"git", "tag", "-m", me.releaseReasonS, me.release.version.String()})
all = append(all, []string{"git", "push", "origin", me.release.version.String()})
if !me.current.Status.DoAll(all) {
log.Info("failed to make new release", me.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
}
pb := me.forge.Repos.FindByGoPath(me.current.GoPath())
if pb != nil {
pb.UpdatePublished()
if !pb.GetGoPrimitive() {
loop := pb.Published.SortByGoPath()
for loop.Scan() {
t := loop.Next()
log.Info("new Published dep:", t.GetGoPath(), t.GetVersion())
}
}
me.forge.Repos.ConfigSave()
}
log.Info("PUBLISH OK")
// me.current.SetGoState("RELEASED")
// unwind and re-tag. Now that the go.mod and go.sum are published, revert
// to the development branch
if !me.current.Status.RevertMasterToDevel() {
log.Info("Revert Failed")
return false
}
// update tag
var retag [][]string
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()})
if !me.current.Status.DoAll(retag) {
log.Info("retag failed")
return false
}
log.Info("EVERYTHING OK. RERELEASED", me.current.Name())
// it's necessary to recreate the the files here
// safe to do this here. everything has been published
fixGodeps(check)
// update the values in the GUI
me.current.NewScan()
// attempt to find another repo to release
if !doReleaseFindNext() {
log.Info("doReleaseFindNext() could not find a new")
log.Info("THIS PROBABLY MEANS THAT ACTUALLY WE ARE TOTALLY DONE?")
os.Setenv("FindNextDone", "true")
return false
}
log.Info("GOOD TO RUN ANOTHER DAY ON:", me.current.Name())
return true
}
// try to figure out if there is another package to update
// returns true if it finds something
func doReleaseFindNext() bool {
// scan for new repo
if findNext() {
log.Info("findNext() found something")
} else {
// this means findNext() didn't find anything but there are
// still packages to release. start trying to fix the go.sum files
if findCounter != 0 {
findFix = true
}
log.Info("findNext() could not find anything")
return false
}
check := me.forge.Repos.FindByGoPath(me.current.GoPath())
if check == nil {
log.Info("boo, you didn't git clone", me.current.GoPath())
return false
}
if findFix {
fixGodeps(check)
}
if me.forge.FinalGoDepsCheckOk(check) {
// the go.sum file is ok to release
return true
}
return false
}
// this pulls the new tag from the golang package repository
// to insert the new version
func doPublishVersion() bool {
gopath := me.current.GoPath()
docmd := []string{"go", "get", "-v", gopath + "@" + me.release.version.String()}
log.Info("SHOULD RUN cmd HERE:", docmd)
// right now, you can't publish this because the go.* files in this project are screwed up
if me.release.guireleaser == nil {
log.Info("CAN NOT SELF UPDATE HERE. cmd =", docmd)
return false
}
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")
me.release.guireleaser.MakeRedoMod()
}
if me.current.Status.IsPrivate() {
// do not self update private repos
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")
log.Info("chdir to autotypist if it exists")
if shell.Exists("/home/jcarr/go/src/go.wit.com/apps/autotypist") {
os.Chdir("/home/jcarr/go/src/go.wit.com/apps/autotypist")
} else {
log.Info("need to chdir somewhere with go.sum & go.mod")
return false
}
// result = shell.PathRun("/home/jcarr/go/src/go.wit.com/apps/autotypist", docmd)
} else {
// 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
}
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
}
log.Info("SELF UPDATE OK. out =", result.Stdout)
log.Info("SELF UPDATE WORKED")
return true
}