Add main.Version

This commit is contained in:
Balakrishnan Balasubramanian 2023-04-05 11:17:07 -04:00
parent 347823b0bd
commit 2aa043b5fc
3 changed files with 17 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tglistbot*

9
Makefile Normal file
View File

@ -0,0 +1,9 @@
VERSION = $(shell git describe --tags --abbrev=0)
build_release:
CGO_ENABLED=0 go build -buildmode=pie -ldflags "-X main.version=$(VERSION)" -o tglistbot-$(VERSION)
release_check:
go list -m go.balki.me/tglistbot@$(VERSION)

View File

@ -22,6 +22,8 @@ import (
"go.balki.me/tglistbot/glist"
)
// Version will be set from build commandline
var Version string
var apiToken string
func main() {
@ -61,7 +63,10 @@ func main() {
glist.DataPath = dataPath
commit := func() string {
version := func() string {
if Version != "" {
return Version
}
if bi, ok := debug.ReadBuildInfo(); ok {
for _, s := range bi.Settings {
if s.Key == "vcs.revision" {
@ -79,7 +84,7 @@ func main() {
return fmt.Sprintf("port: %v", port)
}()
log.Printf("List bot (%s) starting with datapath: %q, %s\n", commit, dataPath, listeningOn)
log.Printf("List bot (%s) starting with datapath: %q, %s\n", version, dataPath, listeningOn)
var chats sync.Map
if err := loadData(dataPath, &chats); err != nil {