Skip to content

Commit 57299f2

Browse files
authored
goreleaser: define version tag (#434)
1 parent 7fabac9 commit 57299f2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.goreleaser.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
builds:
22
- ldflags:
3+
- -X github.com/elastic/elastic-package/internal/version.Tag={{.Tag}}
34
- -X github.com/elastic/elastic-package/internal/version.CommitHash={{.ShortCommit}}
45
- -X github.com/elastic/elastic-package/internal/version.BuildTime={{.Timestamp}}

cmd/version.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package cmd
66

77
import (
8+
"fmt"
9+
"strings"
10+
811
"github.com/spf13/cobra"
912

1013
"github.com/elastic/elastic-package/internal/cobraext"
@@ -25,6 +28,13 @@ func setupVersionCommand() *cobraext.Command {
2528
}
2629

2730
func versionCommandAction(cmd *cobra.Command, args []string) error {
28-
cmd.Printf("elastic-package version-hash %s (build time: %s)\n", version.CommitHash, version.BuildTimeFormatted())
31+
var sb strings.Builder
32+
sb.WriteString("elastic-package ")
33+
if version.Tag != "" {
34+
sb.WriteString(version.Tag)
35+
sb.WriteString(" ")
36+
}
37+
sb.WriteString(fmt.Sprintf("version-hash %s (build time: %s)", version.CommitHash, version.BuildTimeFormatted()))
38+
fmt.Println(sb.String())
2939
return nil
3040
}

internal/version/version.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ var (
1515

1616
// CommitHash is the Git hash of the branch, used for version purposes (set externally with ldflags).
1717
CommitHash = "undefined"
18+
19+
// Tag describes the semver version of the application (set externally with ldflags).
20+
Tag string
1821
)
1922

2023
// BuildTimeFormatted method returns the build time preserving the RFC3339 format.

0 commit comments

Comments
 (0)