1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-03 00:57:43 +02:00

fix gomips support (#1331)

* wip: fix gomips

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* wip: fix gomips

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: added more

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* test: added more

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker
2020-02-05 22:08:18 -03:00
committed by GitHub
parent 16fe0ea3bf
commit d85fff06a2
14 changed files with 138 additions and 42 deletions

View File

@ -144,7 +144,7 @@ func (artifacts Artifacts) List() []*Artifact {
func (artifacts Artifacts) GroupByPlatform() map[string][]*Artifact { func (artifacts Artifacts) GroupByPlatform() map[string][]*Artifact {
var result = map[string][]*Artifact{} var result = map[string][]*Artifact{}
for _, a := range artifacts.items { 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) result[plat] = append(result[plat], a)
} }
return result return result

View File

@ -124,6 +124,18 @@ func TestGroupByPlatform(t *testing.T) {
Goarch: "arm", Goarch: "arm",
Goarm: "6", Goarm: "6",
}, },
{
Name: "foobar",
Goos: "linux",
Goarch: "mips",
Goarm: "softfloat",
},
{
Name: "foobar",
Goos: "linux",
Goarch: "mips",
Goarm: "hardfloat",
},
{ {
Name: "check", Name: "check",
Type: Checksum, Type: Checksum,
@ -137,6 +149,8 @@ func TestGroupByPlatform(t *testing.T) {
var groups = artifacts.GroupByPlatform() var groups = artifacts.GroupByPlatform()
assert.Len(t, groups["linuxamd64"], 2) assert.Len(t, groups["linuxamd64"], 2)
assert.Len(t, groups["linuxarm6"], 1) assert.Len(t, groups["linuxarm6"], 1)
assert.Len(t, groups["linuxmipssoftfloat"], 1)
assert.Len(t, groups["linuxmipshardfloat"], 1)
} }
func TestChecksum(t *testing.T) { func TestChecksum(t *testing.T) {

View File

@ -19,6 +19,7 @@ func Arch(key string) string {
return "armhf" return "armhf"
case "arm7": // GOARCH + GOARM case "arm7": // GOARCH + GOARM
return "armhf" return "armhf"
} default:
return arch return arch
} }
}

View File

@ -25,8 +25,8 @@ import (
) )
const ( const (
defaultNameTemplate = "{{ .ProjectName }}_{{ .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 }}" defaultBinaryNameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
) )
// nolint: gochecknoglobals // nolint: gochecknoglobals
@ -162,6 +162,7 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A
Goos: binaries[0].Goos, Goos: binaries[0].Goos,
Goarch: binaries[0].Goarch, Goarch: binaries[0].Goarch,
Goarm: binaries[0].Goarm, Goarm: binaries[0].Goarm,
Gomips: binaries[0].Gomips,
Extra: map[string]interface{}{ Extra: map[string]interface{}{
"Builds": binaries, "Builds": binaries,
"ID": archive.ID, "ID": archive.ID,
@ -198,6 +199,7 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
Goos: binary.Goos, Goos: binary.Goos,
Goarch: binary.Goarch, Goarch: binary.Goarch,
Goarm: binary.Goarm, Goarm: binary.Goarm,
Gomips: binary.Gomips,
Extra: map[string]interface{}{ Extra: map[string]interface{}{
"Builds": []*artifact.Artifact{binary}, "Builds": []*artifact.Artifact{binary},
"ID": archive.ID, "ID": archive.ID,

View File

@ -22,6 +22,12 @@ func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String()) 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) { func TestRunPipe(t *testing.T) {
folder, back := testlib.Mktmp(t) folder, back := testlib.Mktmp(t)
defer back() defer back()
@ -29,13 +35,11 @@ func TestRunPipe(t *testing.T) {
t.Run("Archive format "+format, func(tt *testing.T) { t.Run("Archive format "+format, func(tt *testing.T) {
var dist = filepath.Join(folder, format+"_dist") var dist = filepath.Join(folder, format+"_dist")
require.NoError(t, os.Mkdir(dist, 0755)) require.NoError(t, os.Mkdir(dist, 0755))
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755)) for _, arch := range []string{"darwinamd64", "linux386", "linuxarm7", "linuxmipssoftfloat"} {
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755)) createFakeBinary(t, dist, arch, "mybin")
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin")) }
require.NoError(t, err) createFakeBinary(t, dist, "windowsamd64", "mybin.exe")
_, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe")) _, err := os.Create(filepath.Join(folder, "README.md"))
require.NoError(t, err)
_, err = os.Create(filepath.Join(folder, "README.md"))
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, os.MkdirAll(filepath.Join(folder, "foo", "bar", "foobar"), 0755)) 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"))) _, err = os.Create(filepath.Join(filepath.Join(folder, "foo", "bar", "foobar", "blah.txt")))
@ -46,7 +50,7 @@ func TestRunPipe(t *testing.T) {
ProjectName: "foobar", ProjectName: "foobar",
Archives: []config.Archive{ Archives: []config.Archive{
{ {
ID: "defaultarch", ID: "myid",
Builds: []string{"default"}, Builds: []string{"default"},
NameTemplate: defaultNameTemplate, NameTemplate: defaultNameTemplate,
Files: []string{ Files: []string{
@ -74,6 +78,41 @@ func TestRunPipe(t *testing.T) {
"ID": "default", "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{ var windowsBuild = &artifact.Artifact{
Goos: "windows", Goos: "windows",
Goarch: "amd64", Goarch: "amd64",
@ -87,26 +126,29 @@ func TestRunPipe(t *testing.T) {
}, },
} }
ctx.Artifacts.Add(darwinBuild) ctx.Artifacts.Add(darwinBuild)
ctx.Artifacts.Add(linux386Build)
ctx.Artifacts.Add(linuxArmBuild)
ctx.Artifacts.Add(linuxMipsBuild)
ctx.Artifacts.Add(windowsBuild) ctx.Artifacts.Add(windowsBuild)
ctx.Version = "0.0.1" ctx.Version = "0.0.1"
ctx.Git.CurrentTag = "v0.0.1" ctx.Git.CurrentTag = "v0.0.1"
ctx.Config.Archives[0].Format = format ctx.Config.Archives[0].Format = format
require.NoError(tt, Pipe{}.Run(ctx)) require.NoError(tt, Pipe{}.Run(ctx))
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)) var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
for _, arch := range archives.List() { for _, arch := range archives {
require.Equal(t, "defaultarch", arch.Extra["ID"].(string), "all archives should have the archive ID set") require.Equal(t, "myid", arch.Extra["ID"].(string), "all archives should have the archive ID set")
} }
require.Len(tt, archives.List(), 2) require.Len(t, archives, 5)
darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0] // TODO: should verify the artifact fields here too
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))
if format == "tar.gz" { if format == "tar.gz" {
// Check archive contents // Check archive contents
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( require.Equal(
t, t,
[]string{ []string{
@ -116,9 +158,10 @@ func TestRunPipe(t *testing.T) {
"foo/bar/foobar/blah.txt", "foo/bar/foobar/blah.txt",
"mybin", "mybin",
}, },
tarFiles(t, filepath.Join(dist, "foobar_0.0.1_darwin_amd64.tar.gz")), tarFiles(t, filepath.Join(dist, name)),
) )
} }
}
if format == "zip" { if format == "zip" {
require.Equal( require.Equal(
t, t,

View File

@ -24,7 +24,7 @@ import (
"github.com/goreleaser/goreleaser/pkg/context" "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 // Pipe for fpm packaging
type Pipe struct{} type Pipe struct{}

View File

@ -55,7 +55,7 @@ type AppMetadata struct {
Completer string `yaml:",omitempty"` 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 // Pipe for snapcraft packaging
type Pipe struct{} type Pipe struct{}
@ -117,7 +117,7 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error {
), ),
).GroupByPlatform() { ).GroupByPlatform() {
arch := linux.Arch(platform) arch := linux.Arch(platform)
if arch == "armel" { if !isValidArch(arch) {
log.WithField("arch", arch).Warn("ignored unsupported arch") log.WithField("arch", arch).Warn("ignored unsupported arch")
continue continue
} }
@ -129,6 +129,16 @@ func doRun(ctx *context.Context, snap config.Snapcraft) error {
return g.Wait() 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 // Publish packages
func (Pipe) Publish(ctx *context.Context) error { func (Pipe) Publish(ctx *context.Context) error {
snaps := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List() snaps := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List()

View File

@ -13,7 +13,7 @@ import (
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
func TestDescription(t *testing.T) { 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") 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))
})
}
}

View File

@ -38,6 +38,7 @@ const (
os = "Os" os = "Os"
arch = "Arch" arch = "Arch"
arm = "Arm" arm = "Arm"
mips = "Mips"
binary = "Binary" binary = "Binary"
artifactName = "ArtifactName" artifactName = "ArtifactName"
// gitlab only // 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[os] = replace(replacements, a.Goos)
t.fields[arch] = replace(replacements, a.Goarch) t.fields[arch] = replace(replacements, a.Goarch)
t.fields[arm] = replace(replacements, a.Goarm) t.fields[arm] = replace(replacements, a.Goarm)
t.fields[mips] = replace(replacements, a.Gomips)
t.fields[binary] = bin.(string) t.fields[binary] = bin.(string)
t.fields[artifactName] = a.Name t.fields[artifactName] = a.Name
if val, ok := a.Extra["ArtifactUploadHash"]; ok { if val, ok := a.Extra["ArtifactUploadHash"]; ok {

View File

@ -31,6 +31,7 @@ func TestWithArtifact(t *testing.T) {
"Linux": "{{.Os}}", "Linux": "{{.Os}}",
"amd64": "{{.Arch}}", "amd64": "{{.Arch}}",
"6": "{{.Arm}}", "6": "{{.Arm}}",
"softfloat": "{{.Mips}}",
"1.2.3": "{{.Version}}", "1.2.3": "{{.Version}}",
"v1.2.3": "{{.Tag}}", "v1.2.3": "{{.Tag}}",
"1-2-3": "{{.Major}}-{{.Minor}}-{{.Patch}}", "1-2-3": "{{.Major}}-{{.Minor}}-{{.Patch}}",
@ -51,6 +52,7 @@ func TestWithArtifact(t *testing.T) {
Goarch: "amd64", Goarch: "amd64",
Goos: "linux", Goos: "linux",
Goarm: "6", Goarm: "6",
Gomips: "softfloat",
Extra: map[string]interface{}{ Extra: map[string]interface{}{
"Binary": "binary", "Binary": "binary",
}, },

View File

@ -26,9 +26,9 @@ archives:
# Archive name template. # Archive name template.
# Defaults: # Defaults:
# - if format is `tar.gz`, `gz` or `zip`: # - 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`: # - 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 }}" name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
# Replacements for GOOS and GOARCH in the archive name. # Replacements for GOOS and GOARCH in the archive name.

View File

@ -24,7 +24,7 @@ nfpms:
package_name: foo package_name: foo
# You can change the file name of the package. # 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 }}" file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
# Build IDs for the builds you want to create NFPM packages for. # Build IDs for the builds you want to create NFPM packages for.

View File

@ -31,7 +31,7 @@ snapcrafts:
- bar - bar
# You can change the name of the package. # 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 }}" name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
# Replacements for GOOS and GOARCH in the package name. # Replacements for GOOS and GOARCH in the package name.

View File

@ -37,6 +37,7 @@ may have some extra fields:
| `.Os` | `GOOS` (usually allow replacements) | | `.Os` | `GOOS` (usually allow replacements) |
| `.Arch` | `GOARCH` (usually allow replacements) | | `.Arch` | `GOARCH` (usually allow replacements) |
| `.Arm` | `GOARM` (usually allow replacements) | | `.Arm` | `GOARM` (usually allow replacements) |
| `.Mips` | `GOMIPS` (usually allow replacements) |
| `.Binary` | Binary name | | `.Binary` | Binary name |
| `.ArtifactName` | Archive name | | `.ArtifactName` | Archive name |