Repository: goreleaser/goreleaser
Pull request #1027 (2019-05-27 20:59:10)

fix: armhf on arm v6
closes https://github.com/goreleaser/goreleaser/issues/1026


Patch:
diff --git a/internal/builders/golang/build.go b/internal/builders/golang/build.go
index 46e23a30..d6961ee8 100644
--- a/internal/builders/golang/build.go
+++ b/internal/builders/golang/build.go
@@ -45,7 +45,7 @@ func (*Builder) WithDefaults(build config.Build) config.Build {
 		build.Goarm = []string{"6"}
 	}
 	if len(build.Ldflags) == 0 {
-		build.Ldflags = []string{"-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"}
+		build.Ldflags = []string{"-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser"}
 	}
 	if len(build.Targets) == 0 {
 		build.Targets = matrix(build)
diff --git a/internal/linux/arch.go b/internal/linux/arch.go
index 363f3d10..62ce399e 100644
--- a/internal/linux/arch.go
+++ b/internal/linux/arch.go
@@ -13,8 +13,10 @@ func Arch(key string) string {
 		return "i386"
 	case "amd64":
 		return "amd64"
-	case "arm6": // GOARCH + GOARM
+	case "arm5": // GOARCH + GOARM
 		return "armel"
+	case "arm6": // GOARCH + GOARM
+		return "armhf"
 	case "arm7": // GOARCH + GOARM
 		return "armhf"
 	}
diff --git a/main.go b/main.go
index fa2aff5b..934c61d8 100644
--- a/main.go
+++ b/main.go
@@ -21,8 +21,9 @@ import (
 // nolint: gochecknoglobals
 var (
 	version = "dev"
-	commit  = "none"
-	date    = "unknown"
+	commit  = ""
+	date    = ""
+	builtBy = ""
 )
 
 type releaseOptions struct {
@@ -61,7 +62,7 @@ func main() {
 	var parallelism = releaseCmd.Flag("parallelism", "Amount tasks to run concurrently").Short('p').Default("4").Int()
 	var timeout = releaseCmd.Flag("timeout", "Timeout to the entire release process").Default("30m").Duration()
 
-	app.Version(fmt.Sprintf("%v, commit %v, built at %v", version, commit, date))
+	app.Version(buildVersion(version, commit, date, builtBy))
 	app.VersionFlag.Short('v')
 	app.HelpFlag.Short('h')
 	app.UsageTemplate(static.UsageTemplate)
@@ -164,3 +165,17 @@ func loadConfig(path string) (config.Project, error) {
 	log.Warn("could not find a config file, using defaults...")
 	return config.Project{}, nil
 }
+
+func buildVersion(version, commit, date, builtBy string) string {
+	var result = fmt.Sprintf("version: %s", version)
+	if commit != "" {
+		result = fmt.Sprintf("%s\ncommit: %s", result, commit)
+	}
+	if date != "" {
+		result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
+	}
+	if builtBy != "" {
+		result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
+	}
+	return result
+}
diff --git a/www/content/build.md b/www/content/build.md
index 8167d3cc..dc1048c5 100644
--- a/www/content/build.md
+++ b/www/content/build.md
@@ -49,7 +49,7 @@ builds:
       - ./dontoptimizeme=-N
 
     # Custom ldflags templates.
-    # Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}`.
+    # Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
     ldflags:
      - -s -w -X main.build={{.Version}}
      - ./usemsan=-msan


Test patch:
diff --git a/internal/linux/arch_test.go b/internal/linux/arch_test.go
index a8d9901a..8b689c04 100644
--- a/internal/linux/arch_test.go
+++ b/internal/linux/arch_test.go
@@ -9,14 +9,15 @@ import (
 
 func TestArch(t *testing.T) {
 	for from, to := range map[string]string{
-		"linuxamd64": "amd64",
-		"linux386":   "i386",
-		"linuxarm64": "arm64",
-		"linuxarm6":  "armel",
-		"linuxarm7":  "armhf",
-		"linuxppc64":  "ppc64",
-		"linuxppc64le":  "ppc64le",
-		"linuxwhat":  "what",
+		"linuxamd64":   "amd64",
+		"linux386":     "i386",
+		"linuxarm64":   "arm64",
+		"linuxarm5":    "armel",
+		"linuxarm6":    "armhf",
+		"linuxarm7":    "armhf",
+		"linuxppc64":   "ppc64",
+		"linuxppc64le": "ppc64le",
+		"linuxwhat":    "what",
 	} {
 		t.Run(fmt.Sprintf("%s to %s", from, to), func(t *testing.T) {
 			assert.Equal(t, to, Arch(from))
diff --git a/internal/pipe/build/build_test.go b/internal/pipe/build/build_test.go
index cf713ce5..80bb2916 100644
--- a/internal/pipe/build/build_test.go
+++ b/internal/pipe/build/build_test.go
@@ -217,7 +217,7 @@ func TestDefaultEmptyBuild(t *testing.T) {
 	assert.Equal(t, []string{"amd64", "386"}, build.Goarch)
 	assert.Equal(t, []string{"6"}, build.Goarm)
 	assert.Len(t, build.Ldflags, 1)
-	assert.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}", build.Ldflags[0])
+	assert.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser", build.Ldflags[0])
 }
 
 func TestSeveralBuildsWithTheSameID(t *testing.T) {
@@ -266,7 +266,7 @@ func TestDefaultPartialBuilds(t *testing.T) {
 		assert.Equal(t, []string{"amd64", "386"}, build.Goarch)
 		assert.Equal(t, []string{"6"}, build.Goarm)
 		assert.Len(t, build.Ldflags, 1)
-		assert.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}", build.Ldflags[0])
+		assert.Equal(t, "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser", build.Ldflags[0])
 	})
 	t.Run("build1", func(t *testing.T) {
 		var build = ctx.Config.Builds[1]
diff --git a/internal/pipe/snapcraft/snapcraft_test.go b/internal/pipe/snapcraft/snapcraft_test.go
index 4a2fc5ea..d0137697 100644
--- a/internal/pipe/snapcraft/snapcraft_test.go
+++ b/internal/pipe/snapcraft/snapcraft_test.go
@@ -80,7 +80,7 @@ func TestRunPipe(t *testing.T) {
 	addBinaries(t, ctx, "foo", filepath.Join(dist, "foo"), "foo")
 	addBinaries(t, ctx, "bar", filepath.Join(dist, "bar"), "bar")
 	assert.NoError(t, Pipe{}.Run(ctx))
-	assert.Len(t, ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List(), 6)
+	assert.Len(t, ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List(), 9)
 }
 
 func TestRunPipeInvalidNameTemplate(t *testing.T) {
diff --git a/main_test.go b/main_test.go
index b81ccb7d..c5e713b5 100644
--- a/main_test.go
+++ b/main_test.go
@@ -10,6 +10,7 @@ import (
 	"github.com/goreleaser/goreleaser/internal/testlib"
 	"github.com/goreleaser/goreleaser/pkg/config"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 	yaml "gopkg.in/yaml.v2"
 )
 
@@ -181,3 +182,41 @@ release:
 `
 	createFile(t, "goreleaser.yml", yaml)
 }
+
+func TestVersion(t *testing.T) {
+	for name, tt := range map[string]struct {
+		version, commit, date, builtBy string
+		out                            string
+	}{
+		"all empty": {
+			out: "version: ",
+		},
+		"complete": {
+			version: "1.2.3",
+			date:    "12/12/12",
+			commit:  "aaaa",
+			builtBy: "me",
+			out:     "version: 1.2.3\ncommit: aaaa\nbuilt at: 12/12/12\nbuilt by: me",
+		},
+		"only version": {
+			version: "1.2.3",
+			out:     "version: 1.2.3",
+		},
+		"version and date": {
+			version: "1.2.3",
+			date:    "12/12/12",
+			out:     "version: 1.2.3\nbuilt at: 12/12/12",
+		},
+		"version, date, built by": {
+			version: "1.2.3",
+			date:    "12/12/12",
+			builtBy: "me",
+			out:     "version: 1.2.3\nbuilt at: 12/12/12\nbuilt by: me",
+		},
+	} {
+		tt := tt
+		t.Run(name, func(t *testing.T) {
+			require.Equal(t, tt.out, buildVersion(tt.version, tt.commit, tt.date, tt.builtBy))
+		})
+	}
+}