From d355350f63315c1ef4bda13e9682c96783ebd5b2 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 29 May 2019 09:13:52 -0300 Subject: [PATCH] fix: nfpm id (#1030) * fix: nfpm id * fix: import order --- internal/pipe/snapcraft/snapcraft.go | 5 ++++- internal/pipe/snapcraft/snapcraft_test.go | 17 +++++++++++++++++ pkg/config/config.go | 1 + www/content/snapcraft.md | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/pipe/snapcraft/snapcraft.go b/internal/pipe/snapcraft/snapcraft.go index b3cebef54..6e63d0ee2 100644 --- a/internal/pipe/snapcraft/snapcraft.go +++ b/internal/pipe/snapcraft/snapcraft.go @@ -13,6 +13,7 @@ import ( "github.com/apex/log" "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/deprecate" + "github.com/goreleaser/goreleaser/internal/ids" "github.com/goreleaser/goreleaser/internal/linux" "github.com/goreleaser/goreleaser/internal/pipe" "github.com/goreleaser/goreleaser/internal/semerrgroup" @@ -71,6 +72,7 @@ func (Pipe) Default(ctx *context.Context) error { deprecate.Notice("snapcraft") } } + var ids = ids.New() for i := range ctx.Config.Snapcrafts { var snap = &ctx.Config.Snapcrafts[i] if snap.NameTemplate == "" { @@ -81,8 +83,9 @@ func (Pipe) Default(ctx *context.Context) error { snap.Builds = append(snap.Builds, b.ID) } } + ids.Inc(snap.ID) } - return nil + return ids.Validate() } // Run the pipe diff --git a/internal/pipe/snapcraft/snapcraft_test.go b/internal/pipe/snapcraft/snapcraft_test.go index d01376977..b582378dc 100644 --- a/internal/pipe/snapcraft/snapcraft_test.go +++ b/internal/pipe/snapcraft/snapcraft_test.go @@ -12,6 +12,7 @@ import ( "github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/context" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" yaml "gopkg.in/yaml.v2" ) @@ -313,3 +314,19 @@ func addBinaries(t *testing.T, ctx *context.Context, name, dist, dest string) { } } } + +func TestSeveralSnapssWithTheSameID(t *testing.T) { + var ctx = &context.Context{ + Config: config.Project{ + Snapcrafts: []config.Snapcraft{ + { + ID: "a", + }, + { + ID: "a", + }, + }, + }, + } + require.EqualError(t, Pipe{}.Default(ctx), "found 2 items with the ID 'a', please fix your config") +} diff --git a/pkg/config/config.go b/pkg/config/config.go index a97dcb866..fc5b05f56 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -226,6 +226,7 @@ type Snapcraft struct { Replacements map[string]string `yaml:",omitempty"` Publish bool `yaml:",omitempty"` + ID string `yaml:",omitempty"` Builds []string `yaml:",omitempty"` Name string `yaml:",omitempty"` Summary string `yaml:",omitempty"` diff --git a/www/content/snapcraft.md b/www/content/snapcraft.md index fd2fdf4a8..f2d6fab7c 100644 --- a/www/content/snapcraft.md +++ b/www/content/snapcraft.md @@ -20,6 +20,10 @@ Available options: # .goreleaser.yml snapcrafts: - + # ID of the nfpm config, must be unique. + # Defaults to "default". + id: foo + # Build IDs for the builds you want to create snapcraft packages for. # Defaults to all builds. builds: