From 2d6e83cf3f601264d9e804d97b556e80cf361fed Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Wed, 13 Apr 2022 23:38:39 -0300 Subject: [PATCH] fix: nfpm conventional file names with GOAMD64 Fixes conventional file names when using GOAMD64 refs #3016 Signed-off-by: Carlos A Becker --- internal/pipe/nfpm/nfpm.go | 6 +- internal/pipe/nfpm/nfpm_test.go | 102 ++++++++++++++++++++++++++------ 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index c739860cd..fb474747a 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -118,7 +118,9 @@ func mergeOverrides(fpm config.NFPM, format string) (*config.NFPMOverridables, e } func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*artifact.Artifact) error { - arch := binaries[0].Goarch + binaries[0].Goarm + binaries[0].Gomips + binaries[0].Goamd64 + // TODO: improve mips handling on nfpm + infoArch := binaries[0].Goarch + binaries[0].Goarm + binaries[0].Gomips // key used for the ConventionalFileName et al + arch := infoArch + binaries[0].Goamd64 // unique arch key overridden, err := mergeOverrides(fpm, format) if err != nil { @@ -231,7 +233,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar log.WithField("files", destinations(contents)).Debug("all archive files") info := &nfpm.Info{ - Arch: arch, + Arch: infoArch, Platform: "linux", Name: fpm.PackageName, Version: ctx.Version, diff --git a/internal/pipe/nfpm/nfpm_test.go b/internal/pipe/nfpm/nfpm_test.go index 377065951..5abc644ae 100644 --- a/internal/pipe/nfpm/nfpm_test.go +++ b/internal/pipe/nfpm/nfpm_test.go @@ -284,7 +284,7 @@ func TestRunPipeConventionalNameTemplate(t *testing.T) { Homepage: "https://goreleaser.com/", Bindir: "/usr/bin", NFPMOverridables: config.NFPMOverridables{ - FileNameTemplate: "{{ .ConventionalFileName }}", + FileNameTemplate: `{{ trimsuffix (trimsuffix (trimsuffix .ConventionalFileName ".deb") ".rpm") ".apk" }}{{ if not (eq .Amd64 "v1")}}{{ .Amd64 }}{{ end }}`, PackageName: "foo", }, }, @@ -293,32 +293,100 @@ func TestRunPipeConventionalNameTemplate(t *testing.T) { ctx.Version = "1.0.0" ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} for _, goos := range []string{"linux", "darwin"} { - for _, goarch := range []string{"amd64", "386"} { - ctx.Artifacts.Add(&artifact.Artifact{ - Name: "subdir/mybin", - Path: binPath, - Goarch: goarch, - Goos: goos, - Type: artifact.Binary, - Extra: map[string]interface{}{ - artifact.ExtraID: "default", - }, - }) + for _, goarch := range []string{"amd64", "386", "arm64", "arm", "mips"} { + switch goarch { + case "arm": + for _, goarm := range []string{"6", "7"} { + ctx.Artifacts.Add(&artifact.Artifact{ + Name: "subdir/mybin", + Path: binPath, + Goarch: goarch, + Goos: goos, + Goarm: goarm, + Type: artifact.Binary, + Extra: map[string]interface{}{ + artifact.ExtraID: "default", + }, + }) + } + case "amd64": + for _, goamd64 := range []string{"v1", "v2", "v3", "v4"} { + ctx.Artifacts.Add(&artifact.Artifact{ + Name: "subdir/mybin", + Path: binPath, + Goarch: goarch, + Goos: goos, + Goamd64: goamd64, + Type: artifact.Binary, + Extra: map[string]interface{}{ + artifact.ExtraID: "default", + }, + }) + } + case "mips": + for _, gomips := range []string{"softfloat", "hardfloat"} { + ctx.Artifacts.Add(&artifact.Artifact{ + Name: "subdir/mybin", + Path: binPath, + Goarch: goarch, + Goos: goos, + Gomips: gomips, + Type: artifact.Binary, + Extra: map[string]interface{}{ + artifact.ExtraID: "default", + }, + }) + } + default: + ctx.Artifacts.Add(&artifact.Artifact{ + Name: "subdir/mybin", + Path: binPath, + Goarch: goarch, + Goos: goos, + Type: artifact.Binary, + Extra: map[string]interface{}{ + artifact.ExtraID: "default", + }, + }) + } } } require.NoError(t, Pipe{}.Run(ctx)) packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List() - require.Len(t, packages, 6) + require.Len(t, packages, 30) for _, pkg := range packages { format := pkg.Format() require.NotEmpty(t, format) require.Contains(t, []string{ - "foo_1.0.0_amd64.deb", - "foo_1.0.0_x86.apk", - "foo_1.0.0_i386.deb", - "foo_1.0.0_x86_64.apk", + "foo-1.0.0.aarch64.rpm", + "foo-1.0.0.armv6hl.rpm", + "foo-1.0.0.armv7hl.rpm", "foo-1.0.0.i386.rpm", + "foo-1.0.0.mipshardfloat.rpm", + "foo-1.0.0.mipssoftfloat.rpm", "foo-1.0.0.x86_64.rpm", + "foo-1.0.0.x86_64v2.rpm", + "foo-1.0.0.x86_64v3.rpm", + "foo-1.0.0.x86_64v4.rpm", + "foo_1.0.0_aarch64.apk", + "foo_1.0.0_amd64.deb", + "foo_1.0.0_amd64v2.deb", + "foo_1.0.0_amd64v3.deb", + "foo_1.0.0_amd64v4.deb", + "foo_1.0.0_arm64.deb", + "foo_1.0.0_armhf.apk", + "foo_1.0.0_armhf.deb", + "foo_1.0.0_armv7.apk", + "foo_1.0.0_i386.deb", + "foo_1.0.0_mipshardfloat.apk", + "foo_1.0.0_mipshardfloat.deb", + "foo_1.0.0_mipssoftfloat.apk", + "foo_1.0.0_mipssoftfloat.deb", + "foo_1.0.0_x86.apk", + "foo_1.0.0_x86_64.apk", + "foo_1.0.0_x86_64v2.apk", + "foo_1.0.0_x86_64v3.apk", + "foo_1.0.0_x86_64v4.apk", }, pkg.Name, "package name is not expected") require.Equal(t, "someid", pkg.ID()) require.ElementsMatch(t, []string{binPath}, sources(pkg.ExtraOr(extraFiles, files.Contents{}).(files.Contents)))