Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Add Version Command
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Oct 22, 2023
1 parent 621acc2 commit 24b73c2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
11 changes: 5 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ builds:
- "6"
- "7"
ldflags:
- "-s -w"
- "-X main.GitCommit={{ .Commit }}"
- "-X main.GitVersion={{ .Version }}"
- -s -w
- -X github.com/systemli/ticker/cmd.version={{.Version}}
- -X github.com/systemli/ticker/cmd.commit={{.Commit}}
dockers:
-
goos: linux
- goos: linux
goarch: amd64
image_templates:
- "systemli/ticker:{{ .Tag }}"
- "systemli/ticker:{{ .Major }}"
- "systemli/ticker:{{ .Major }}.{{ .Minor }}"
- "systemli/ticker:latest"
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
Expand Down
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
)

var (
GitCommit string
GitVersion string

configPath string
cfg config.Config

Expand Down Expand Up @@ -50,6 +47,7 @@ func initConfig() {
func Execute() {
rootCmd.AddCommand(runCmd)
rootCmd.AddCommand(dbCmd)
rootCmd.AddCommand(versionCmd)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
5 changes: 1 addition & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ var (
Use: "run",
Short: "Run the ticker",
Run: func(cmd *cobra.Command, args []string) {
log.Infof("starting ticker api on %s", cfg.Listen)
if GitCommit != "" && GitVersion != "" {
log.Infof("build info: %s (commit: %s)", GitVersion, GitCommit)
}
log.Infof("starting ticker (version: %s, commit: %s) on %s", version, commit, cfg.Listen)

go func() {
http.Handle("/metrics", promhttp.Handler())
Expand Down
20 changes: 20 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var (
version = "dev"
commit = "HEAD"

versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Ticker version: %s (commit: %s)\n", version, commit)
},
}
)

0 comments on commit 24b73c2

Please sign in to comment.