diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go index 58b631c6af6..e38c40d811f 100644 --- a/internal/artifact/artifact.go +++ b/internal/artifact/artifact.go @@ -144,7 +144,7 @@ func (artifacts Artifacts) List() []*Artifact { func (artifacts Artifacts) GroupByPlatform() map[string][]*Artifact { var result = map[string][]*Artifact{} for _, a := range artifacts.items { - plat := a.Goos + a.Goarch + a.Goarm + plat := a.Goos + a.Goarch + a.Goarm + a.Gomips result[plat] = append(result[plat], a) } return result diff --git a/internal/artifact/artifact_test.go b/internal/artifact/artifact_test.go index cd364c39c8b..0380eac383c 100644 --- a/internal/artifact/artifact_test.go +++ b/internal/artifact/artifact_test.go @@ -124,6 +124,18 @@ func TestGroupByPlatform(t *testing.T) { Goarch: "arm", Goarm: "6", }, + { + Name: "foobar", + Goos: "linux", + Goarch: "mips", + Goarm: "softfloat", + }, + { + Name: "foobar", + Goos: "linux", + Goarch: "mips", + Goarm: "hardfloat", + }, { Name: "check", Type: Checksum, @@ -137,6 +149,8 @@ func TestGroupByPlatform(t *testing.T) { var groups = artifacts.GroupByPlatform() assert.Len(t, groups["linuxamd64"], 2) assert.Len(t, groups["linuxarm6"], 1) + assert.Len(t, groups["linuxmipssoftfloat"], 1) + assert.Len(t, groups["linuxmipshardfloat"], 1) } func TestChecksum(t *testing.T) { diff --git a/internal/linux/arch.go b/internal/linux/arch.go index 62ce399eabc..748c112ab04 100644 --- a/internal/linux/arch.go +++ b/internal/linux/arch.go @@ -19,6 +19,7 @@ func Arch(key string) string { return "armhf" case "arm7": // GOARCH + GOARM return "armhf" + default: + return arch } - return arch } diff --git a/internal/pipe/archive/archive.go b/internal/pipe/archive/archive.go index 987c7024de8..4848c33da58 100644 --- a/internal/pipe/archive/archive.go +++ b/internal/pipe/archive/archive.go @@ -25,8 +25,8 @@ import ( ) const ( - defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" - defaultBinaryNameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" + defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" + defaultBinaryNameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" ) // nolint: gochecknoglobals @@ -162,6 +162,7 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A Goos: binaries[0].Goos, Goarch: binaries[0].Goarch, Goarm: binaries[0].Goarm, + Gomips: binaries[0].Gomips, Extra: map[string]interface{}{ "Builds": binaries, "ID": archive.ID, @@ -198,6 +199,7 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art Goos: binary.Goos, Goarch: binary.Goarch, Goarm: binary.Goarm, + Gomips: binary.Gomips, Extra: map[string]interface{}{ "Builds": []*artifact.Artifact{binary}, "ID": archive.ID, diff --git a/internal/pipe/archive/archive_test.go b/internal/pipe/archive/archive_test.go index 47a4533a257..162a0cc1cde 100644 --- a/internal/pipe/archive/archive_test.go +++ b/internal/pipe/archive/archive_test.go @@ -22,6 +22,12 @@ func TestDescription(t *testing.T) { require.NotEmpty(t, Pipe{}.String()) } +func createFakeBinary(t *testing.T, dist, arch, bin string) { + require.NoError(t, os.Mkdir(filepath.Join(dist, arch), 0755)) + _, err := os.Create(filepath.Join(dist, arch, bin)) + require.NoError(t, err) +} + func TestRunPipe(t *testing.T) { folder, back := testlib.Mktmp(t) defer back() @@ -29,13 +35,11 @@ func TestRunPipe(t *testing.T) { t.Run("Archive format "+format, func(tt *testing.T) { var dist = filepath.Join(folder, format+"_dist") require.NoError(t, os.Mkdir(dist, 0755)) - require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755)) - require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755)) - _, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin")) - require.NoError(t, err) - _, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe")) - require.NoError(t, err) - _, err = os.Create(filepath.Join(folder, "README.md")) + for _, arch := range []string{"darwinamd64", "linux386", "linuxarm7", "linuxmipssoftfloat"} { + createFakeBinary(t, dist, arch, "mybin") + } + createFakeBinary(t, dist, "windowsamd64", "mybin.exe") + _, err := os.Create(filepath.Join(folder, "README.md")) require.NoError(t, err) require.NoError(t, os.MkdirAll(filepath.Join(folder, "foo", "bar", "foobar"), 0755)) _, err = os.Create(filepath.Join(filepath.Join(folder, "foo", "bar", "foobar", "blah.txt"))) @@ -46,7 +50,7 @@ func TestRunPipe(t *testing.T) { ProjectName: "foobar", Archives: []config.Archive{ { - ID: "defaultarch", + ID: "myid", Builds: []string{"default"}, NameTemplate: defaultNameTemplate, Files: []string{ @@ -74,6 +78,41 @@ func TestRunPipe(t *testing.T) { "ID": "default", }, } + var linux386Build = &artifact.Artifact{ + Goos: "linux", + Goarch: "386", + Name: "mybin", + Path: filepath.Join(dist, "linux386", "mybin"), + Type: artifact.Binary, + Extra: map[string]interface{}{ + "Binary": "mybin", + "ID": "default", + }, + } + var linuxArmBuild = &artifact.Artifact{ + Goos: "linux", + Goarch: "arm", + Goarm: "7", + Name: "mybin", + Path: filepath.Join(dist, "linuxarm7", "mybin"), + Type: artifact.Binary, + Extra: map[string]interface{}{ + "Binary": "mybin", + "ID": "default", + }, + } + var linuxMipsBuild = &artifact.Artifact{ + Goos: "linux", + Goarch: "mips", + Gomips: "softfloat", + Name: "mybin", + Path: filepath.Join(dist, "linuxmipssoftfloat", "mybin"), + Type: artifact.Binary, + Extra: map[string]interface{}{ + "Binary": "mybin", + "ID": "default", + }, + } var windowsBuild = &artifact.Artifact{ Goos: "windows", Goarch: "amd64", @@ -87,37 +126,41 @@ func TestRunPipe(t *testing.T) { }, } ctx.Artifacts.Add(darwinBuild) + ctx.Artifacts.Add(linux386Build) + ctx.Artifacts.Add(linuxArmBuild) + ctx.Artifacts.Add(linuxMipsBuild) ctx.Artifacts.Add(windowsBuild) ctx.Version = "0.0.1" ctx.Git.CurrentTag = "v0.0.1" ctx.Config.Archives[0].Format = format require.NoError(tt, Pipe{}.Run(ctx)) - var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)) - for _, arch := range archives.List() { - require.Equal(t, "defaultarch", arch.Extra["ID"].(string), "all archives should have the archive ID set") + var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List() + for _, arch := range archives { + require.Equal(t, "myid", arch.Extra["ID"].(string), "all archives should have the archive ID set") } - require.Len(tt, archives.List(), 2) - darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0] - windows := archives.Filter(artifact.ByGoos("windows")).List()[0] - require.Equal(tt, "foobar_0.0.1_darwin_amd64."+format, darwin.Name) - require.Equal(tt, "foobar_0.0.1_windows_amd64.zip", windows.Name) - - require.Equal(t, []*artifact.Artifact{darwinBuild}, darwin.Extra["Builds"].([]*artifact.Artifact)) - require.Equal(t, []*artifact.Artifact{windowsBuild}, windows.Extra["Builds"].([]*artifact.Artifact)) + require.Len(t, archives, 5) + // TODO: should verify the artifact fields here too if format == "tar.gz" { // Check archive contents - require.Equal( - t, - []string{ - "README.md", - "foo/bar", - "foo/bar/foobar", - "foo/bar/foobar/blah.txt", - "mybin", - }, - tarFiles(t, filepath.Join(dist, "foobar_0.0.1_darwin_amd64.tar.gz")), - ) + for _, name := range []string{ + "foobar_0.0.1_darwin_amd64.tar.gz", + "foobar_0.0.1_linux_386.tar.gz", + "foobar_0.0.1_linux_armv7.tar.gz", + "foobar_0.0.1_linux_mips_softfloat.tar.gz", + } { + require.Equal( + t, + []string{ + "README.md", + "foo/bar", + "foo/bar/foobar", + "foo/bar/foobar/blah.txt", + "mybin", + }, + tarFiles(t, filepath.Join(dist, name)), + ) + } } if format == "zip" { require.Equal( diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go index 94e36da6bc1..133aa7475a2 100644 --- a/internal/pipe/nfpm/nfpm.go +++ b/internal/pipe/nfpm/nfpm.go @@ -24,7 +24,7 @@ import ( "github.com/goreleaser/goreleaser/pkg/context" ) -const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" +const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" // Pipe for fpm packaging type Pipe struct{} diff --git a/internal/pipe/snapcraft/snapcraft.go b/internal/pipe/snapcraft/snapcraft.go index e033a5b6d85..93ac5a4d6c3 100644 --- a/internal/pipe/snapcraft/snapcraft.go +++ b/internal/pipe/snapcraft/snapcraft.go @@ -55,7 +55,7 @@ type AppMetadata struct { Completer string `yaml:",omitempty"` } -const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" +const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" // Pipe for snapcraft packaging type Pipe struct{} @@ -117,7 +117,7 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error { ), ).GroupByPlatform() { arch := linux.Arch(platform) - if arch == "armel" { + if !isValidArch(arch) { log.WithField("arch", arch).Warn("ignored unsupported arch") continue } @@ -129,6 +129,16 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error { return g.Wait() } +func isValidArch(arch string) bool { + // https://snapcraft.io/docs/architectures + for _, a := range []string{"s390x", "ppc64el", "arm64", "armhf", "amd64", "i386"} { + if arch == a { + return true + } + } + return false +} + // Publish packages func (Pipe) Publish(ctx *context.Context) error { snaps := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List() diff --git a/internal/pipe/snapcraft/snapcraft_test.go b/internal/pipe/snapcraft/snapcraft_test.go index ec84b4e9c35..9263dd73667 100644 --- a/internal/pipe/snapcraft/snapcraft_test.go +++ b/internal/pipe/snapcraft/snapcraft_test.go @@ -13,7 +13,7 @@ import ( "github.com/goreleaser/goreleaser/pkg/context" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" ) func TestDescription(t *testing.T) { @@ -397,3 +397,24 @@ func TestSeveralSnapssWithTheSameID(t *testing.T) { } require.EqualError(t, Pipe{}.Default(ctx), "found 2 snapcrafts with the ID 'a', please fix your config") } + +func Test_isValidArch(t *testing.T) { + tests := []struct { + arch string + want bool + }{ + {"s390x", true}, + {"ppc64el", true}, + {"arm64", true}, + {"armhf", true}, + {"amd64", true}, + {"i386", true}, + {"mips", false}, + {"armel", false}, + } + for _, tt := range tests { + t.Run(tt.arch, func(t *testing.T) { + require.Equal(t, tt.want, isValidArch(tt.arch)) + }) + } +} diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index c5f1a36c28f..fe995d59f34 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -38,6 +38,7 @@ const ( os = "Os" arch = "Arch" arm = "Arm" + mips = "Mips" binary = "Binary" artifactName = "ArtifactName" // gitlab only @@ -92,6 +93,7 @@ func (t *Template) WithArtifact(a *artifact.Artifact, replacements map[string]st t.fields[os] = replace(replacements, a.Goos) t.fields[arch] = replace(replacements, a.Goarch) t.fields[arm] = replace(replacements, a.Goarm) + t.fields[mips] = replace(replacements, a.Gomips) t.fields[binary] = bin.(string) t.fields[artifactName] = a.Name if val, ok := a.Extra["ArtifactUploadHash"]; ok { diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index 7e72672b3e7..01472887b16 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -31,6 +31,7 @@ func TestWithArtifact(t *testing.T) { "Linux": "{{.Os}}", "amd64": "{{.Arch}}", "6": "{{.Arm}}", + "softfloat": "{{.Mips}}", "1.2.3": "{{.Version}}", "v1.2.3": "{{.Tag}}", "1-2-3": "{{.Major}}-{{.Minor}}-{{.Patch}}", @@ -51,6 +52,7 @@ func TestWithArtifact(t *testing.T) { Goarch: "amd64", Goos: "linux", Goarm: "6", + Gomips: "softfloat", Extra: map[string]interface{}{ "Binary": "binary", }, diff --git a/www/content/archive.md b/www/content/archive.md index c1ebf28bab5..416357a9dc5 100644 --- a/www/content/archive.md +++ b/www/content/archive.md @@ -26,9 +26,9 @@ archives: # Archive name template. # Defaults: # - if format is `tar.gz`, `gz` or `zip`: - # - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}` + # - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}` # - if format is `binary`: - # - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}` + # - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}` name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" # Replacements for GOOS and GOARCH in the archive name. diff --git a/www/content/nfpm.md b/www/content/nfpm.md index 3544d8d41fa..f51feda5b0d 100644 --- a/www/content/nfpm.md +++ b/www/content/nfpm.md @@ -24,7 +24,7 @@ nfpms: package_name: foo # You can change the file name of the package. - # Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}` + # Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}` file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" # Build IDs for the builds you want to create NFPM packages for. diff --git a/www/content/snapcraft.md b/www/content/snapcraft.md index 0d1ac956e1d..b3f46c40646 100644 --- a/www/content/snapcraft.md +++ b/www/content/snapcraft.md @@ -31,7 +31,7 @@ snapcrafts: - bar # You can change the name of the package. - # Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}` + # Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}` name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" # Replacements for GOOS and GOARCH in the package name. diff --git a/www/content/templates.md b/www/content/templates.md index b1910b317f3..ee519d82544 100644 --- a/www/content/templates.md +++ b/www/content/templates.md @@ -37,6 +37,7 @@ may have some extra fields: | `.Os` | `GOOS` (usually allow replacements) | | `.Arch` | `GOARCH` (usually allow replacements) | | `.Arm` | `GOARM` (usually allow replacements) | +| `.Mips` | `GOMIPS` (usually allow replacements) | | `.Binary` | Binary name | | `.ArtifactName` | Archive name |