From ad359a4712afa46f8bd4259d6ca14b7783d68b2c Mon Sep 17 00:00:00 2001 From: Arsen6331 Date: Wed, 2 Nov 2022 18:30:06 +0000 Subject: [PATCH] feat: implement nfpm archlinux packages (#3470) This PR implements the Archlinux packages that were added in nfpm v2.20.0, as well as tests and documentation for them. goreleaser/nfpm#133 goreleaser/nfpm#543 Fixes #3469 Co-authored-by: Carlos Alexandro Becker --- .goreleaser.yaml | 1 + internal/pipe/nfpm/nfpm.go | 15 +++++++++++--- internal/pipe/nfpm/nfpm_test.go | 36 ++++++++++++++++++++++++++------- pkg/config/config.go | 12 +++++++++++ www/docs/customization/nfpm.md | 19 ++++++++++++++++- 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3d1ecfc6839..16af0b0e792 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -242,6 +242,7 @@ nfpms: - apk - deb - rpm + - archlinux dependencies: - git recommends: diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index 1af3c5942b6..186c728fea2 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -22,9 +22,10 @@ import ( "github.com/goreleaser/nfpm/v2/files" "github.com/imdario/mergo" - _ "github.com/goreleaser/nfpm/v2/apk" // blank import to register the format - _ "github.com/goreleaser/nfpm/v2/deb" // blank import to register the format - _ "github.com/goreleaser/nfpm/v2/rpm" // blank import to register the format + _ "github.com/goreleaser/nfpm/v2/apk" // blank import to register the format + _ "github.com/goreleaser/nfpm/v2/arch" // blank import to register the format + _ "github.com/goreleaser/nfpm/v2/deb" // blank import to register the format + _ "github.com/goreleaser/nfpm/v2/rpm" // blank import to register the format ) const ( @@ -355,6 +356,14 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar PostUpgrade: overridden.APK.Scripts.PostUpgrade, }, }, + ArchLinux: nfpm.ArchLinux{ + Pkgbase: overridden.ArchLinux.Pkgbase, + Packager: overridden.ArchLinux.Packager, + Scripts: nfpm.ArchLinuxScripts{ + PreUpgrade: overridden.ArchLinux.Scripts.PreUpgrade, + PostUpgrade: overridden.ArchLinux.Scripts.PostUpgrade, + }, + }, }, } diff --git a/internal/pipe/nfpm/nfpm_test.go b/internal/pipe/nfpm/nfpm_test.go index 742d2b16b93..1316fd8c5d4 100644 --- a/internal/pipe/nfpm/nfpm_test.go +++ b/internal/pipe/nfpm/nfpm_test.go @@ -10,6 +10,7 @@ import ( "github.com/goreleaser/goreleaser/internal/testlib" "github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/context" + "github.com/goreleaser/nfpm/v2" "github.com/goreleaser/nfpm/v2/files" "github.com/stretchr/testify/require" ) @@ -92,7 +93,7 @@ func TestRunPipe(t *testing.T) { ID: "someid", Bindir: "/usr/bin", Builds: []string{"default"}, - Formats: []string{"deb", "rpm", "apk", "termux.deb"}, + Formats: []string{"deb", "rpm", "apk", "termux.deb", "archlinux"}, Section: "somesection", Priority: "standard", Description: "Some description with {{ .Env.DESC }}", @@ -223,7 +224,7 @@ func TestRunPipe(t *testing.T) { } require.NoError(t, Pipe{}.Run(ctx)) packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List() - require.Len(t, packages, 40) + require.Len(t, packages, 51) for _, pkg := range packages { format := pkg.Format() require.NotEmpty(t, format) @@ -237,10 +238,21 @@ func TestRunPipe(t *testing.T) { if pkg.Gomips != "" { arch += "_" + pkg.Gomips } + + ext := "." + format + if format != "termux.deb" { + packager, err := nfpm.Get(format) + require.NoError(t, err) + + if packager, ok := packager.(nfpm.PackagerWithExtension); ok { + ext = packager.ConventionalExtension() + } + } + if pkg.Goos == "linux" { - require.Equal(t, "foo_1.0.0_Tux_"+arch+"-10-20."+format, pkg.Name) + require.Equal(t, "foo_1.0.0_Tux_"+arch+"-10-20"+ext, pkg.Name) } else { - require.Equal(t, "foo_1.0.0_ios_arm64-10-20."+format, pkg.Name) + require.Equal(t, "foo_1.0.0_ios_arm64-10-20"+ext, pkg.Name) } require.Equal(t, "someid", pkg.ID()) require.ElementsMatch(t, []string{ @@ -289,7 +301,7 @@ func TestRunPipeConventionalNameTemplate(t *testing.T) { { ID: "someid", Builds: []string{"default"}, - Formats: []string{"deb", "rpm", "apk"}, + Formats: []string{"deb", "rpm", "apk", "archlinux"}, Section: "somesection", Priority: "standard", Description: "Some description ", @@ -299,7 +311,7 @@ func TestRunPipeConventionalNameTemplate(t *testing.T) { Homepage: "https://goreleaser.com/", Bindir: "/usr/bin", NFPMOverridables: config.NFPMOverridables{ - FileNameTemplate: `{{ trimsuffix (trimsuffix (trimsuffix .ConventionalFileName ".deb") ".rpm") ".apk" }}{{ if not (eq .Amd64 "v1")}}{{ .Amd64 }}{{ end }}`, + FileNameTemplate: `{{ trimsuffix (trimsuffix (trimsuffix (trimsuffix .ConventionalFileName ".pkg.tar.zst") ".deb") ".rpm") ".apk" }}{{ if not (eq .Amd64 "v1")}}{{ .Amd64 }}{{ end }}`, PackageName: "foo", }, }, @@ -368,7 +380,7 @@ func TestRunPipeConventionalNameTemplate(t *testing.T) { } require.NoError(t, Pipe{}.Run(ctx)) packages := ctx.Artifacts.Filter(artifact.ByType(artifact.LinuxPackage)).List() - require.Len(t, packages, 30) + require.Len(t, packages, 40) for _, pkg := range packages { format := pkg.Format() require.NotEmpty(t, format) @@ -402,6 +414,16 @@ func TestRunPipeConventionalNameTemplate(t *testing.T) { "foo_1.0.0_x86_64v2.apk", "foo_1.0.0_x86_64v3.apk", "foo_1.0.0_x86_64v4.apk", + "foo-1.0.0-1-aarch64.pkg.tar.zst", + "foo-1.0.0-1-armv6h.pkg.tar.zst", + "foo-1.0.0-1-armv7h.pkg.tar.zst", + "foo-1.0.0-1-i686.pkg.tar.zst", + "foo-1.0.0-1-x86_64.pkg.tar.zst", + "foo-1.0.0-1-x86_64v2.pkg.tar.zst", + "foo-1.0.0-1-x86_64v3.pkg.tar.zst", + "foo-1.0.0-1-x86_64v4.pkg.tar.zst", + "foo-1.0.0-1-mipssoftfloat.pkg.tar.zst", + "foo-1.0.0-1-mipshardfloat.pkg.tar.zst", }, pkg.Name, "package name is not expected") require.Equal(t, "someid", pkg.ID()) require.ElementsMatch(t, []string{binPath}, sources(artifact.ExtraOr(*pkg, extraFiles, files.Contents{}))) diff --git a/pkg/config/config.go b/pkg/config/config.go index 67828378ac5..6060202c23b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -634,6 +634,17 @@ type NFPMAPK struct { Signature NFPMAPKSignature `yaml:"signature,omitempty" json:"signature,omitempty"` } +type NFPMArchLinuxScripts struct { + PreUpgrade string `yaml:"preupgrade,omitempty" json:"preupgrade,omitempty"` + PostUpgrade string `yaml:"postupgrade,omitempty" json:"postupgrade,omitempty"` +} + +type NFPMArchLinux struct { + Pkgbase string `yaml:"pkgbase,omitempty" json:"pkgbase,omitempty"` + Packager string `yaml:"packager,omitempty" json:"packager,omitempty"` + Scripts NFPMArchLinuxScripts `yaml:"scripts,omitempty" json:"scripts,omitempty"` +} + // NFPMOverridables is used to specify per package format settings. type NFPMOverridables struct { FileNameTemplate string `yaml:"file_name_template,omitempty" json:"file_name_template,omitempty"` @@ -654,6 +665,7 @@ type NFPMOverridables struct { RPM NFPMRPM `yaml:"rpm,omitempty" json:"rpm,omitempty"` Deb NFPMDeb `yaml:"deb,omitempty" json:"deb,omitempty"` APK NFPMAPK `yaml:"apk,omitempty" json:"apk,omitempty"` + ArchLinux NFPMArchLinux `yaml:"archlinux,omitempty" json:"archlinux,omitempty"` } // SBOM config. diff --git a/www/docs/customization/nfpm.md b/www/docs/customization/nfpm.md index 9f2056e97d2..8bc4960ff59 100644 --- a/www/docs/customization/nfpm.md +++ b/www/docs/customization/nfpm.md @@ -1,7 +1,7 @@ # Linux packages (via nFPM) GoReleaser can be wired to [nfpm](https://github.com/goreleaser/nfpm) to -generate and publish `.deb`, `.rpm` and `.apk` packages. +generate and publish `.deb`, `.rpm`, `.apk`, and Archlinux packages. Available options: @@ -67,6 +67,7 @@ nfpms: - deb - rpm - termux.deb # Since GoReleaser v1.11. + - archlinux # Packages your package depends on. (overridable) dependencies: @@ -364,6 +365,22 @@ nfpms: # is matched to the public key store in /etc/apk/keys/.rsa.pub. # If unset, it defaults to the maintainer email address. key_name: origin + archlinux: + # Archlinux-specific scripts + scripts: + # The preupgrade script runs before pacman upgrades the package. + preupgrade: ./scripts/preupgrade.sh + # The postupgrade script runs after pacman upgrades the package. + postupgrade: ./scripts/postupgrade.sh + + # The pkgbase can be used to explicitly specify the name to be used to refer + # to a group of packages. See: https://wiki.archlinux.org/title/PKGBUILD#pkgbase. + pkgbase: foo + + # The packager refers to the organization packaging the software, not to be confused + # with the maintainer, which is the person who maintains the software. + packager: GoReleaser + ``` !!! tip