// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "fmt" "os" "path/filepath" "strings" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func doDebian() 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 := shell.RunRealtimeError(cmd) return err } initForge() // doInstallScan() 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) } printRepos(found) // func (f *Forge) isInstalled(repo *gitpb.Repo) string { // return "X" // } if !argv.DryRun { me.forge.ConfigRill(16, 16) stats := me.forge.RunOnRepos(found, doInstallRepo) for s, stat := range stats { if stat.Err == nil { continue } dur := stat.End.Sub(stat.Start) log.Info("CRAP. INSTALL FAILED", shell.FormatDuration(dur), s, stat.Err) return stat.Err } } me.forge.ConfigRill(16, 16) log.Info("STARTING .deb BUILDS repo len =", found.Len()) 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 argv.DryRun { return nil } _, err = shell.RunRealtimeError([]string{"do-aptly"}) return err } func getStatusEnd(repo *gitpb.Repo) string { var end string manufactured := repo.GetCurrentVersion() ver := trimNonNumericFromStart(manufactured) name := me.forge.Config.DebName(repo.GetGoPath()) var realver string if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil { realver = installedPackage.Version } if actualp := me.machine.FindByVersion(name, ver); actualp != nil { // end += " (version match) " + actualp.Version + " " + ver + " " // repo.State = "on mirrors" } else { if realver != "" { end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver) } // end += "" + ver + " " } debname := name + "_" + ver + "_amd64.deb" // debnames[repo] = debname outdir := getOutdir(repo) _, err := os.Stat(filepath.Join(outdir, debname)) if err == nil { // log.Info("exists", filepath.Join(outdir, debname)) repo.State = "in incoming" } else { // log.Info(debname, "does not exist") } if strings.HasPrefix(repo.GetState(), "unknown bran") { end += " (will build) " } if repo.State == "" { end += " (will build) " } if repo.State == "need to build" { end += " (will build) " } if name == "" { // err := fmt.Sprintf("name is blank error %+v", repo) log.Warn("name is blank error", repo.GetGoPath()) } return end } func shouldBuild(repo *gitpb.Repo) bool { if argv.Force { return true } if strings.HasPrefix(repo.GetState(), "unknown bran") { return true } if repo.State == "" { return true } if repo.State == "need to build" { return true } return false } // 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 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 !shouldBuild(check) { return nil } if argv.Verbose || argv.Force { // 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 { 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" } func doOnlyDebianPackages() 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 := shell.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) } printRepos(found) me.forge.ConfigRill(16, 16) log.Info("STARTING .deb BUILDS repo len =", found.Len()) 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 } } return nil }