Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ builds:
env:
- CGO_ENABLED=0
ldflags:
- -X main.Version={{.Tag}}
- -X main.CommitSHA={{.FullCommit}}
- -X main.BuildDate={{.CommitDate}}
- -X main.GoOS={{.Os}}
- -X main.GoArch={{.Arch}}
- -s
- -w
- -X 'main.version={{.Version}}'
- -X 'main.commit={{.Commit}}'
- -X 'main.date={{.Date}}'
- -X 'main.GoOS={{.Os}}'
- -X 'main.GoArch={{.Arch}}'
goos:
- linux
- darwin
Expand All @@ -40,17 +42,29 @@ builds:
- 386
- amd64
- arm
flags:
- -a
ldflags:
- -s
- -w
- -X 'main.version={{.Version}}'
- -X 'main.commit={{.Commit}}'
- -X 'main.date={{.Date}}'
- -X 'main.GoOS={{.Os}}'
- -X 'main.GoArch={{.Arch}}'
- id: pygmy-static
env:
- CGO_ENABLED=0
flags:
- -a
ldflags:
- -X main.Version={{.Tag}}
- -X main.CommitSHA={{.FullCommit}}
- -X main.BuildDate={{.CommitDate}}
- -X main.GoOS={{.Os}}
- -X main.GoArch={{.Arch}}
- -s
- -w
- -X 'main.version={{.Version}}'
- -X 'main.commit={{.Commit}}'
- -X 'main.date={{.Date}}'
- -X 'main.GoOS={{.Os}}'
- -X 'main.GoArch={{.Arch}}'
- -extldflags "-static"
goos:
- linux
Expand Down
43 changes: 37 additions & 6 deletions service/library/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,48 @@ package library

import (
"fmt"
"log"
"runtime/debug"
"strings"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)

// Version describes which version of Pygmy is running.
func Version(c Config) {
info, _ := debug.ReadBuildInfo()
func Version(c Config) error {

version = getVersion()
fmt.Printf("Application version: %s\n", version)

// Use the version information as needed
log.Printf("Running version %s (commit: %s, built on: %s)", version, commit, date)

return nil
}

func getVersion() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
commit = setting.Value[:8] // Short commit hash
case "vcs.time":
date = setting.Value
case "vcs.modified":
if setting.Value == "true" {
commit += "-dirty"
}
}
}
}

if info.Main.Version == "(devel)" {
fmt.Println("Development version")
return
if version == "dev" {
return fmt.Sprintf("%s-%s", version, commit)
}

fmt.Printf("Pygmy %s\n", info.Main.Version)
return strings.TrimPrefix(version, "v")
}