Skip to content
Permalink
Browse files
feat: implement nfpm archlinux packages (#3470)
<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Also, add tests and the respective documentation changes as well.

-->


<!-- If applied, this commit will... -->

This PR implements the Archlinux packages that were added in nfpm
v2.20.0, as well as tests and documentation for them.

<!-- Why is this change being made? -->

<!-- # Provide links to any relevant tickets, URLs or other resources
-->

goreleaser/nfpm#133
goreleaser/nfpm#543
Fixes #3469

Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
Arsen6331 and caarlos0 committed Nov 2, 2022
1 parent 0638b0a commit ad359a4712afa46f8bd4259d6ca14b7783d68b2c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 11 deletions.
@@ -242,6 +242,7 @@ nfpms:
- apk
- deb
- rpm
- archlinux
dependencies:
- git
recommends:
@@ -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,
},
},
},
}

@@ -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{})))
@@ -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.
@@ -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/<key_name>.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 <staff@goreleaser.com>
```

!!! tip

0 comments on commit ad359a4

Please sign in to comment.