Files
nfpm/rpm/builder.go
db22372bfb fix: add context to deb and rpm errors (#1088)
* chore: improve nfpm maintenance path

* test: Address error context review feedback

Replace the byte-counting writer with errWriter and buffer archive headers
so the failure occurs during the body write. Assert diagnostic context
alongside wrapped causes in each deb and rpm regression case.

Addresses the outstanding review feedback in #1088.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b0096264-a208-4a57-a1b0-b902e47faddd
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Maya Chen <275405107+otjdiepluong@users.noreply.github.com>
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b0096264-a208-4a57-a1b0-b902e47faddd
Copilot-Session: ea527b37-94d2-489a-8305-66cef357f4ba
2026-10-12 17:37:30 +00:00

85 lines
1.8 KiB
Go

package rpm
import (
"io"
"strings"
"github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/internal/modtime"
"go.digitalxero.dev/rpm"
)
// packageRPM builds a binary RPM and writes it to w.
func (r *RPM) packageRPM(info *nfpm.Info, w io.Writer) error {
b := rpm.NewPackage()
if err := applyMetadata(b, info); err != nil {
return err
}
if err := applyRelations(b, info); err != nil {
return err
}
if err := applyScripts(b, info); err != nil {
return err
}
if err := applyChangelog(b, info); err != nil {
return err
}
if err := addContents(b, info); err != nil {
return err
}
if fn := signFunc(info); fn != nil {
b.WithPGPSignFunc(fn)
}
pkg, err := b.Build()
if err != nil {
return err
}
_, err = pkg.WriteTo(w)
return err
}
// applyMetadata maps the nfpm.Info scalar metadata onto the package builder.
func applyMetadata(b rpm.PackageBuilder, info *nfpm.Info) error {
b.WithName(info.Name)
b.WithVersion(formatVersion(info))
b.WithRelease(defaultTo(info.Release, "1"))
b.WithSummary(defaultTo(info.RPM.Summary, strings.Split(info.Description, "\n")[0]))
b.WithDescription(info.Description)
b.WithArch(info.Arch)
if info.Platform != "" {
b.WithOS(info.Platform)
}
b.WithLicense(info.License)
b.WithURL(info.Homepage)
b.WithVendor(info.Vendor)
b.WithGroup(info.RPM.Group)
b.WithPackager(defaultTo(info.RPM.Packager, info.Maintainer))
if len(info.RPM.Prefixes) > 0 {
b.WithPrefixes(info.RPM.Prefixes...)
}
b.WithBuildTime(modtime.Get(info.MTime))
host, err := buildHost(info)
if err != nil {
return err
}
b.WithBuildHost(host)
if epoch, ok, err := parseEpoch(info); err != nil {
return err
} else if ok {
b.WithEpoch(epoch)
}
comp, err := parseCompression(info.RPM.Compression)
if err != nil {
return err
}
b.WithCompressor(comp)
return nil
}