You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +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:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							16fe0ea3bf
						
					
				
				
					commit
					d85fff06a2
				
			| @@ -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 | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -19,6 +19,7 @@ func Arch(key string) string { | ||||
| 		return "armhf" | ||||
| 	case "arm7": // GOARCH + GOARM | ||||
| 		return "armhf" | ||||
| 	default: | ||||
| 		return arch | ||||
| 	} | ||||
| 	return arch | ||||
| } | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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( | ||||
|   | ||||
| @@ -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{} | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
| @@ -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)) | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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", | ||||
| 					}, | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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              | | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user