guireleaser/prepareRelease.go

161 lines
4.0 KiB
Go
Raw Normal View History

package main
import (
"os"
"strings"
2025-01-19 10:48:16 -06:00
"time"
2025-01-19 10:48:16 -06:00
"go.wit.com/lib/gui/shell"
2024-12-17 23:59:08 -06:00
"go.wit.com/lib/protobuf/forgepb"
2024-12-16 00:19:03 -06:00
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func makePrepareRelease() {
me.Disable()
me.release.box.Disable()
defer me.Enable()
2024-12-02 08:45:13 -06:00
2024-12-17 23:59:08 -06:00
// run this each time something gets published successfully
rePrepareRelease()
if findNext() {
log.Info("prepare release findNext() returned true")
}
me.release.box.Enable()
}
func forceReleaseVersion(repo *gitpb.Repo) {
if argv.Minor {
// if v1.2.3 change to v.1.3.0
repo.IncrementTargetMinor()
} else {
// if v1.2.3 change to v.1.2.4
if repo.IncrementTargetRevision() {
// worked ok
} else {
log.Info("Failed to increment target revision", repo.GetFullPath())
os.Exit(-1)
}
2024-12-17 23:59:08 -06:00
}
// empty git notes
if result, err := repo.RunStrictNew([]string{"go-mod-clean", "--purge"}); err != nil {
2025-01-08 04:53:45 -06:00
log.Info("probably you don't have gomodclean")
log.Info(strings.Join(result.Stdout, "\n"))
log.Info(strings.Join(result.Stderr, "\n"))
repo.Run([]string{"git", "notes", "remove"})
os.Exit(-1)
}
2024-12-17 23:59:08 -06:00
2024-12-18 20:08:48 -06:00
if !runGoClean(repo, "--restore") {
2025-01-08 04:53:45 -06:00
log.Info("gomodclean probably failed here. that's ok", repo.GetGoPath())
2024-12-18 20:24:28 -06:00
// os.Exit(-1)
2024-12-17 23:59:08 -06:00
}
}
2025-01-19 10:48:16 -06:00
func rillGoModRestore(repo *gitpb.Repo) error {
if repo.GetTargetVersion() == "" {
// not set to upgrade
return nil
}
if repo.GetLastTag() == repo.GetTargetVersion() {
return nil
}
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
return nil
}
if me.forge.Config.IsPrivate(repo.GetGoPath()) {
return nil
}
runGoClean(repo, "--restore")
return nil
}
2024-12-17 23:59:08 -06:00
func rePrepareRelease() {
// reload the config
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
2025-01-19 10:48:16 -06:00
now := time.Now()
me.forge.RillFuncError(rillGoModRestore)
log.Printf("rillFixGodeps() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))
2024-12-18 20:24:28 -06:00
2025-01-19 10:48:16 -06:00
all := me.forge.Repos.SortByFullPath()
2024-12-12 02:05:47 -06:00
for all.Scan() {
check := all.Next()
2024-12-02 08:45:13 -06:00
2024-12-17 07:03:17 -06:00
if me.forge.Config.IsReadOnly(check.GetGoPath()) {
2024-12-13 02:21:39 -06:00
// can't release readonly repos
continue
}
2024-12-12 02:05:47 -06:00
// if master != lastTag, always increment
master := check.GetMasterVersion()
lastTag := check.GetLastTag()
if master != lastTag {
2024-12-16 00:19:03 -06:00
forceReleaseVersion(check)
2025-01-13 08:11:43 -06:00
me.found.AppendByGoPath(check)
2024-12-16 00:19:03 -06:00
continue
}
2025-01-17 14:19:26 -06:00
if alreadyDone(check) {
// means it was already published
// protects against logic errors that might result
// in an infinite loop
log.Info("WARNING already done", check.GetGoPath())
log.Info("WARNING already done", check.GetGoPath())
log.Info("WARNING already done", check.GetGoPath())
continue
}
2025-01-17 06:20:55 -06:00
if argv.Quick != nil {
// if argv has 'quick' don't do anything
// that doesn't actually have a patch
if master == lastTag {
continue
}
}
2024-12-17 07:03:17 -06:00
if argv.Protobuf && check.GetRepoType() == "protobuf" {
2024-12-16 00:19:03 -06:00
// if --protobuf, this will force upgrade each one
forceReleaseVersion(check)
2025-01-13 08:11:43 -06:00
me.found.AppendByGoPath(check)
2024-12-12 02:05:47 -06:00
continue
2024-12-02 08:45:13 -06:00
}
2024-12-12 02:05:47 -06:00
// if the repo is a go binary or plugin for a new release for
// any library version change
2024-12-17 07:03:17 -06:00
if check.GetRepoType() == "binary" || check.GetRepoType() == "plugin" {
// check if the package dependancies changed, if so, re-publish
2025-01-17 05:30:24 -06:00
if me.forge.FinalGoDepsCheckOk(check, false) {
log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
continue
}
log.Printf("dependancy checks indicate a new release is needed for %s\n", check.GetGoPath())
2024-12-16 00:19:03 -06:00
forceReleaseVersion(check)
2025-01-13 08:11:43 -06:00
me.found.AppendByGoPath(check)
}
}
2025-01-17 05:13:11 -06:00
me.forge.PrintHumanTable(me.found)
2024-12-16 00:19:03 -06:00
}
2025-01-17 14:19:26 -06:00
2025-01-18 05:52:41 -06:00
func printDone() {
for _, gopath := range me.done {
2025-01-20 05:09:28 -06:00
log.Info("printDone() THESE WERE PUBLISHED", gopath)
2025-01-18 05:52:41 -06:00
}
2025-01-20 05:09:28 -06:00
log.Sleep(1)
2025-01-18 05:52:41 -06:00
}
2025-01-17 14:19:26 -06:00
func alreadyDone(repo *gitpb.Repo) bool {
for _, gopath := range me.done {
2025-01-18 07:30:11 -06:00
// log.Info("WARNING already done", gopath, repo.GetGoPath())
// log.Info("WARNING already done", gopath, repo.GetGoPath())
// log.Info("WARNING already done", gopath, repo.GetGoPath())
2025-01-17 14:19:26 -06:00
if repo.GetGoPath() == gopath {
2025-01-18 07:30:11 -06:00
log.Info("FOUND. RETURN TRUE. already done", gopath, repo.GetGoPath())
2025-01-17 14:19:26 -06:00
return true
}
}
return false
}