Skip to content

Commit

Permalink
feat: add version
Browse files Browse the repository at this point in the history
  • Loading branch information
abtris committed Apr 20, 2021
1 parent 955b024 commit 3f92a58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ builds:
main: ./cli/main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w
- -X main.BuildDate={{.Date}}
- -X main.CommitHash={{ .ShortCommit }}
- -X main.Version={{ .Version }}
goos:
- linux
- windows
Expand Down
22 changes: 22 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ import (
"github.com/urfave/cli/v2"
)

// All of this added by goreleaser using ldflags
var (
// Short Git Commit Hash
CommitHash string
// Version vx.x.x
Version string
// Date of build
BuildDate string
)

func printVersion() {
log.Printf("Current build version: %s-%s", Version, CommitHash)
}

var errWrongURL = errors.New("wrong URL, can't generate badge")
// generateBadge
func generateBadge(githubActionURL string, branch string, label string) (string, error) {
Expand Down Expand Up @@ -125,6 +139,14 @@ func main() {
}
fmt.Printf("Done. File .github/workflows/%s was created.\n", fileName)

return nil
},
},{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version",
Action: func(c *cli.Context) error {
printVersion()
return nil
},
}}
Expand Down

0 comments on commit 3f92a58

Please sign in to comment.