From 1f321bc8c3b7bb19f443d73334c6cdcc45a9c75a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 8 Oct 2025 01:23:12 -0500 Subject: usability cleanups --- Makefile | 4 ++ argv.go | 11 ++-- doBuild.debian.go | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ doDebian.go | 135 -------------------------------------------- doGit.go | 20 +++++++ structs.go | 1 + tablePackaging.go | 39 ++++++------- 7 files changed, 215 insertions(+), 161 deletions(-) create mode 100644 doBuild.debian.go delete mode 100644 doDebian.go diff --git a/Makefile b/Makefile index 85fec29..b1160b1 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,10 @@ deb: wit build deb --verbose forge normal +deb-forcedirty: + wit build deb --verbose --force + forge normal + deb-all: wit build deb --verbose --all forge normal diff --git a/argv.go b/argv.go index b6073f1..014cbf4 100644 --- a/argv.go +++ b/argv.go @@ -81,11 +81,12 @@ type DefaultCmd struct { } type GitCmd struct { - Log *EmptyCmd `arg:"subcommand:log" help:"git log"` - Who *EmptyCmd `arg:"subcommand:who" help:"git who"` - Tag *EmptyCmd `arg:"subcommand:tag" help:"show tags"` - Pull *EmptyCmd `arg:"subcommand:pull" help:"pull the wit standard paths"` - Push *EmptyCmd `arg:"subcommand:push" help:"push the wit standard paths"` + Log *EmptyCmd `arg:"subcommand:log" help:"git log"` + Who *EmptyCmd `arg:"subcommand:who" help:"git who"` + Tag *EmptyCmd `arg:"subcommand:tag" help:"show tags"` + Pull *EmptyCmd `arg:"subcommand:pull" help:"pull the wit standard paths"` + Push *EmptyCmd `arg:"subcommand:push" help:"push the wit standard paths"` + DeleteUntracked bool `arg:"--delete-untracked" help:"delete the untracked files"` } type EmptyCmd struct { diff --git a/doBuild.debian.go b/doBuild.debian.go new file mode 100644 index 0000000..e252074 --- /dev/null +++ b/doBuild.debian.go @@ -0,0 +1,166 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "os" + "path/filepath" + + "go.wit.com/lib/debian" + "go.wit.com/lib/fhelp" + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +var totalBuilt int + +func doBuildDeb() error { + // clean out old deb files + globPattern := filepath.Join(me.homedir, "incoming", "*.deb") + files, err := filepath.Glob(globPattern) + if err != nil { + log.Info("Error during globbing:", err) + return err + } + if len(files) > 0 { + cmd := []string{"rm"} + cmd = append(cmd, files...) + _, err := fhelp.RunRealtimeError(cmd) + return err + } + + initForge() + + found := gitpb.NewRepos() + for check := range me.forge.Repos.IterAll() { + if me.forge.Config.IsReadOnly(check.GetNamespace()) { + continue + } + + if !check.IsBinary() { + continue + } + + found.Append(check) + } + + printPackagingTable(found) + found.ActualSort() + printPackagingTable(found) + // me.forge.PrintTable(found) + + me.forge.ConfigRill(16, 16) + stats := me.forge.RunOnRepos(found, buildDeb) + for s, stat := range stats { + if stat.Err != nil { + log.Info("ERROR WITH buildDeb", s, stat.Err) + return stat.Err + } + } + if totalBuilt == 0 { + // nothing built, no need to talk to mirrors + return nil + } + + if _, err := shell.RunVerbose([]string{"ls", "-l", "/home/jcarr/incoming"}); err != nil { + me.sh.BadExit("aptly failed", nil) + } + + if _, err := fhelp.RunRealtimeError([]string{"do-aptly"}); err != nil { + me.sh.BadExit("aptly failed", nil) + } + return nil +} + +// avoids nil panics +func isDebianRelease() bool { + if argv.Build == nil { + return false + } + if argv.Build.Debian == nil { + return false + } + return argv.Build.Debian.Release +} + +func shouldBuild(repo *gitpb.Repo) string { + if repo.IsDirty() && !argv.Force { + return "no" + } + ver := repo.GetCurrentVersion() + debname := getDebFilename(repo) + if !debian.DebFilenameMatchesVersion(debname, ver) { + return "yes" + } + if argv.All { + return "yes" + } + return "" +} + +func buildDeb(repo *gitpb.Repo) error { + var cmd []string + + outdir := getOutdir(repo) + os.MkdirAll(outdir, 0755) + + if isDebianRelease() { + cmd = []string{"go-deb", "--release", "--namespace", repo.Namespace, "--dir", outdir} + } else { + cmd = []string{"go-deb", "--namespace", repo.Namespace, "--dir", outdir} + } + + if me.forge.Config.IsPrivate(repo.GetNamespace()) { + cmd = []string{"go-deb", "--namespace", repo.Namespace, "--dir", outdir} + // return nil + } + + if shouldBuild(repo) != "yes" { + return nil + } + + if argv.Verbose { + // log.Info("build cmd:", cmd) + cmd = append(cmd, "--verbose") + } + + if argv.DryRun { + log.Info("RUN:", repo.FullPath, cmd) + return nil + } + + log.Info("Building .deb", me.forge.GetPackageVersion(repo), cmd) + var err error + if _, err = repo.RunVerboseOnError(cmd); err != nil { + log.Info(repo.FullPath, cmd) + return err + } + + totalBuilt += 1 + log.Info("build worked", cmd, repo.FullPath) + return nil +} + +func getOutdir(repo *gitpb.Repo) string { + if me.forge.Config.IsPrivate(repo.GetNamespace()) { + return "/home/jcarr/incoming-private" + } + if argv.Force { + return "/home/jcarr/incoming" + } + if repo.GetLastTag() != repo.GetMasterVersion() { + return "/home/jcarr/incoming-devel" + } + + if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() { + return "/home/jcarr/incoming-devel" + } + + if repo.CheckDirty() { + return "/home/jcarr/incoming-devel" + } + + return "/home/jcarr/incoming" +} diff --git a/doDebian.go b/doDebian.go deleted file mode 100644 index 00a62bb..0000000 --- a/doDebian.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2017-2025 WIT.COM Inc. All rights reserved. -// Use of this source code is governed by the GPL 3.0 - -package main - -import ( - "os" - "path/filepath" - - "go.wit.com/lib/fhelp" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func doBuildDeb() error { - // clean out old deb files - globPattern := filepath.Join(me.homedir, "incoming", "*.deb") - files, err := filepath.Glob(globPattern) - if err != nil { - log.Info("Error during globbing:", err) - return err - } - if len(files) > 0 { - cmd := []string{"rm"} - cmd = append(cmd, files...) - _, err := fhelp.RunRealtimeError(cmd) - return err - } - - initForge() - - found := gitpb.NewRepos() - for check := range me.forge.Repos.IterAll() { - if me.forge.Config.IsReadOnly(check.GetNamespace()) { - continue - } - - if !check.IsBinary() { - continue - } - - if shouldBuild(check) == "yes" { - found.Append(check) - } - } - - printPackagingTable(found) - - me.forge.ConfigRill(16, 16) - stats := me.forge.RunOnRepos(found, buildDeb) - for s, stat := range stats { - if stat.Err != nil { - log.Info("ERROR WITH buildDeb", s, stat.Err) - return stat.Err - } - } - if _, err := fhelp.RunRealtimeError([]string{"do-aptly"}); err != nil { - me.sh.BadExit("aptly failed", nil) - } - return nil -} - -// avoids nil panics -func isDebianRelease() bool { - if argv.Build == nil { - return false - } - if argv.Build.Debian == nil { - return false - } - return argv.Build.Debian.Release -} - -var totalBuilt int - -func buildDeb(check *gitpb.Repo) error { - var cmd []string - - outdir := getOutdir(check) - os.MkdirAll(outdir, 0755) - - if isDebianRelease() { - cmd = []string{"go-deb", "--release", "--namespace", check.Namespace, "--dir", outdir} - } else { - cmd = []string{"go-deb", "--namespace", check.Namespace, "--dir", outdir} - } - - if me.forge.Config.IsPrivate(check.GetNamespace()) { - cmd = []string{"go-deb", "--namespace", check.Namespace, "--dir", outdir} - // return nil - } - - if argv.Verbose { - // log.Info("build cmd:", cmd) - cmd = append(cmd, "--verbose") - } - - if argv.DryRun { - log.Info("RUN:", check.FullPath, cmd) - return nil - } - - log.Info("Building .deb", cmd) - var err error - if _, err = check.RunVerboseOnError(cmd); err != nil { - totalBuilt += 1 - log.Info(check.FullPath, cmd) - return err - } - - log.Info("build worked", cmd, check.FullPath) - return nil -} - -func getOutdir(repo *gitpb.Repo) string { - if me.forge.Config.IsPrivate(repo.GetNamespace()) { - return "/home/jcarr/incoming-private" - } - if argv.Force { - return "/home/jcarr/incoming" - } - if repo.GetLastTag() != repo.GetMasterVersion() { - return "/home/jcarr/incoming-devel" - } - - if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() { - return "/home/jcarr/incoming-devel" - } - - if repo.CheckDirty() { - return "/home/jcarr/incoming-devel" - } - - return "/home/jcarr/incoming" -} diff --git a/doGit.go b/doGit.go index f8335e5..333ed57 100644 --- a/doGit.go +++ b/doGit.go @@ -63,6 +63,26 @@ func doGit() error { me.sh.GoodExit("") } + if argv.Git.DeleteUntracked { + initForge() + for repo := range me.forge.Repos.IterAll() { + if !strings.HasPrefix(repo.Namespace, "go.wit.com") { + continue + } + files, _ := repo.GitDeleteOthers() + log.Info(len(files), repo.Namespace) + log.Info(strings.Join(files, "\n")) + if argv.Force { + if len(files) > 0 { + cmd := []string{"rm"} + cmd = append(cmd, files...) + _, err := fhelp.RunRealtimeError(cmd) + return err + } + } + } + } + return nil } diff --git a/structs.go b/structs.go index 3ef197d..5d267d9 100644 --- a/structs.go +++ b/structs.go @@ -26,6 +26,7 @@ type mainType struct { func initForge() { if me.forge == nil { me.forge = forgepb.Init() + me.forge.ScanRepoDir() me.forge.Config.DumpENV() } initMachine() diff --git a/tablePackaging.go b/tablePackaging.go index 497a9d9..0da43b1 100644 --- a/tablePackaging.go +++ b/tablePackaging.go @@ -38,39 +38,29 @@ func getDebFilename(repo *gitpb.Repo) string { return "" } -func shouldBuild(repo *gitpb.Repo) string { - if repo.IsDirty() { - return "no" - } - ver := repo.GetCurrentVersion() - debname := getDebFilename(repo) - if !debian.DebFilenameMatchesVersion(debname, ver) { - return "yes" - } - if argv.All { - return "yes" - } - return "" +func printPackagingTable(pb *gitpb.Repos) { + tablePB := makePackagingTable(pb) + tablePB.PrintTable() + log.Printf("wit.packagingTable() %d repos\n", pb.Len()) } -func printPackagingTable(pb *gitpb.Repos) { +func makePackagingTable(pb *gitpb.Repos) *gitpb.ReposTable { tablePB := pb.NewTable("deb details") tablePB.NewUuid() - var col *gitpb.RepoFunc - col = tablePB.AddNamespace() - col.Width = 32 + col = tablePB.AddFullPath() + col.Width = 56 col = tablePB.AddStringFunc("RepoType", func(r *gitpb.Repo) string { return me.forge.GetRepoType(r) }) col.Width = 8 - col = tablePB.AddStringFunc("Build Version", func(r *gitpb.Repo) string { + col = tablePB.AddStringFunc("new .deb Version", func(r *gitpb.Repo) string { return me.forge.GetPackageVersion(r) }) - col.Width = 12 + col.Width = 16 /* col = tablePB.AddStringFunc("is old", func(r *gitpb.Repo) string { @@ -111,6 +101,14 @@ func printPackagingTable(pb *gitpb.Repos) { }) col.Width = 4 + col = tablePB.AddStringFunc("dirty", func(r *gitpb.Repo) string { + if r.IsDirty() { + return "yes" + } + return "" + }) + col.Width = 5 + col = tablePB.AddStringFunc("build", func(r *gitpb.Repo) string { return shouldBuild(r) }) @@ -128,6 +126,5 @@ func printPackagingTable(pb *gitpb.Repos) { }) col.Width = -1 - tablePB.PrintTable() - log.Printf("wit.packagingTable() %d repos\n", pb.Len()) + return tablePB } -- cgit v1.2.3