Skip to content

Commit

Permalink
goreleaser: define version tag (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek authored Jul 19, 2021
1 parent 7fabac9 commit 57299f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
builds:
- ldflags:
- -X github.com/elastic/elastic-package/internal/version.Tag={{.Tag}}
- -X github.com/elastic/elastic-package/internal/version.CommitHash={{.ShortCommit}}
- -X github.com/elastic/elastic-package/internal/version.BuildTime={{.Timestamp}}
12 changes: 11 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"

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

func versionCommandAction(cmd *cobra.Command, args []string) error {
cmd.Printf("elastic-package version-hash %s (build time: %s)\n", version.CommitHash, version.BuildTimeFormatted())
var sb strings.Builder
sb.WriteString("elastic-package ")
if version.Tag != "" {
sb.WriteString(version.Tag)
sb.WriteString(" ")
}
sb.WriteString(fmt.Sprintf("version-hash %s (build time: %s)", version.CommitHash, version.BuildTimeFormatted()))
fmt.Println(sb.String())
return nil
}
3 changes: 3 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var (

// CommitHash is the Git hash of the branch, used for version purposes (set externally with ldflags).
CommitHash = "undefined"

// Tag describes the semver version of the application (set externally with ldflags).
Tag string
)

// BuildTimeFormatted method returns the build time preserving the RFC3339 format.
Expand Down

0 comments on commit 57299f2

Please sign in to comment.