// 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() (string, error) { log.Info("STARTING DEBIAN PACKAGE BUILD") // clean out old deb files globPattern := filepath.Join(me.homedir, "incoming", "*.deb") files, err := filepath.Glob(globPattern) if err != nil { return "Error during globbing", err } if len(files) > 0 { cmd := []string{"rm"} cmd = append(cmd, files...) _, err := fhelp.RunRealtimeError(cmd) return "rm incoming/* failed", err } initForge() found := gitpb.NewRepos() for check := range me.forge.Repos.IterAll() { if me.forge.Config.IsReadOnly(check.GetNamespace()) { continue } if me.forge.Config.IsPrivate(check.GetNamespace()) { if !argv.Build.Debian.Priv { continue } } if !check.IsBinary() { continue } found.Append(check) } found.ActualSort() footer := printPackagingTable(found) log.Info("This is what will and will not be built:", footer) me.forge.ConfigRill(16, 16) stats := me.forge.RunOnRepos(found, buildDeb) for s, stat := range stats { if stat.Err != nil { return "ERROR WITH buildDeb " + s, stat.Err } } if totalBuilt == 0 { if argv.DryRun { log.Info("") return "--dry-run TRUE (nothing done)", nil } // nothing built, no need to talk to mirrors return "everything is current", 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 "all .deb built ok", 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 { // NEVER EVER EVER BUILD DIRTY .deb PACKAGES // versioning with debian will prioritize the 'd' before numbers // so packages will be randomly upgraded based on the git hash // just do a commit. Do not 'fix' this. This is a good idea anyway. // This should be a policy everywhere. 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 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") } debname := me.forge.Config.DebName(repo.GetNamespace()) debname += "." + me.forge.GetPackageVersion(repo) + ".deb" if argv.DryRun { log.Info("RUN:", repo.FullPath, debname) log.Info("RUN:", cmd) return nil } log.Info("Building", debname, 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-dirty-junk" } return "/home/jcarr/incoming" }