// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "errors" "fmt" "os" "path/filepath" "go.wit.com/lib/env" "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func rillRestore(repo *gitpb.Repo) error { if me.forge.Config.IsReadOnly(repo.GetGoPath()) { return nil } if me.forge.Config.IsPrivate(repo.GetGoPath()) { return nil } cmd := []string{"go-mod-clean", "lax"} if env.True("--strict") { cmd = []string{"go-mod-clean", "purge"} repo.RunQuiet(cmd) cmd = []string{"go-mod-clean", "--restore"} } var err error if env.Verbose() { _, err = repo.RunQuiet(cmd) } else { _, err = repo.RunQuiet(cmd) } if env.True("--strict") { cmd = []string{"go-mod-clean", "strict"} _, err = repo.RunQuiet(cmd) } if err != nil { errs := fmt.Sprintf("%v failed (%v)", cmd, err) return errors.New(errs) } return nil } // fuck you prior self. this code is garbage // nevermind, I knew that when I wrote it. // I'm back now to fix it. Thank you for making it work until I got back here // shame you aren't as smart as fabrice. you might have done this on the first go around // fine though, you have different talents. Also, Mariam loves you. func doPublish() error { initForge() env.PrintTable() log.Printf("Running go-mod-clean on (%d) repos. (1 second per hundred)\n", me.forge.Repos.Len()) restored := me.forge.RunOnRepos(me.forge.Repos, rillRestore) restored = restored.SortActual() footer := restored.PrintPublishNewTB() fmt.Printf("restored.len(%d) with errors: %s\n", restored.Len(), footer) // publish := me.forge.RunOnReposSlow(me.forge.Repos, rePrepareReleaseNew) // doesn't use Rill() publish := me.forge.RunOnRepos(me.forge.Repos, rePrepareReleaseNew) if publish == nil { return errors.New("nothing to publish. you actually have to write code first") } for repo := range publish.IterAll() { err := me.forge.CheckUpdatingGoDeps(repo.GoInfo.GoDeps, publish) if err != nil { repo.State = fmt.Sprintf("%s err (%v)\n", repo.Namespace, err) } else { cmd := []string{"go-mod-clean", "strict"} repo.RunRealtime(cmd) } } for repo := range publish.IterAll() { // update the target version // repo.IncrementTargetMinor() repo.IncrementTargetRevision() } publish = publish.SortActual() footer = publish.PrintPublishNewTB() fmt.Printf("publish.len(%d) PrintPublishTable() footer: %s\n", publish.Len(), footer) tryme := findNext(publish) if len(tryme) == 0 { return errors.New("can't find something safe to publish") } startRepo := me.forge.Repos.FindByNamespace("go.wit.com/lib/xgb") if startRepo == nil { return errors.New("a startRepo can't be found") } releaseReason := "new attempt" for _, repo := range tryme { log.Printf("tryme: %s reason(%s)\n", repo.FullPath, repo.State) gomod, err := os.ReadFile(filepath.Join(repo.FullPath, "go.mod")) if err != nil { panic("go.mod missing") } log.Info(string(gomod)) if env.True("--doit") { log.Printf("RUNNING: doRelease(%s, %s, %s) %s\n", repo.Namespace, startRepo.Namespace, releaseReason, repo.GetTargetVersion()) err := doRelease(repo, startRepo, releaseReason) if err != nil { return err } } else { log.Printf("WOULD HAVE RUN: doRelease(%s, %s, %s) %s\n", repo.Namespace, startRepo.Namespace, releaseReason, repo.GetTargetVersion()) } } for _, repo := range tryme { log.Printf("tryme: %s reason(%s)\n", repo.FullPath, repo.State) } if !env.True("--doit") { return errors.New("run with --doit to actually try to publish") } argvpb.GoodExit("PUBLISH WORKED") return nil }