File tree Expand file tree Collapse file tree 3 files changed +48
-5
lines changed
Expand file tree Collapse file tree 3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,22 @@ ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
66# Gather all .go files for use in dependencies below
77GO_FILES =$(shell find $(ROOT_DIR ) -name '* .go')
88
9+ # Extract Go module name from go.mod
10+ GOMODULE =$(shell grep ^module $(ROOT_DIR ) /go.mod | awk '{ print $$2 }')
11+
12+ # Set version strings based on git tag and current ref
13+ GO_LDFLAGS =-ldflags "-s -w -X '$(GOMODULE ) /internal/version.Version=$(shell git describe --tags --exact-match 2>/dev/null) ' -X '$(GOMODULE ) /internal/version.CommitHash=$(shell git rev-parse --short HEAD) '"
14+
915mod-tidy :
1016 go mod tidy
1117
1218# Build our program binary
1319# Depends on GO_FILES to determine when rebuild is needed
1420$(BINARY ) : mod-tidy $(GO_FILES )
15- # Needed to fetch new dependencies and add them to go.mod
16- go build -o $(BINARY ) ./cmd/$(BINARY )
21+ go build \
22+ $(GO_LDFLAGS ) \
23+ -o $(BINARY ) \
24+ ./cmd/$(BINARY )
1725
1826.PHONY : build clean image mod-tidy
1927
Original file line number Diff line number Diff line change @@ -17,12 +17,14 @@ package main
1717import (
1818 "flag"
1919 "fmt"
20- "github.com/blinklabs-io/tx-submit-api/internal/api"
21- "github.com/blinklabs-io/tx-submit-api/internal/config"
22- "github.com/blinklabs-io/tx-submit-api/internal/logging"
2320 "net/http"
2421 _ "net/http/pprof"
2522 "os"
23+
24+ "github.com/blinklabs-io/tx-submit-api/internal/api"
25+ "github.com/blinklabs-io/tx-submit-api/internal/config"
26+ "github.com/blinklabs-io/tx-submit-api/internal/logging"
27+ "github.com/blinklabs-io/tx-submit-api/internal/version"
2628)
2729
2830var cmdlineFlags struct {
@@ -57,6 +59,8 @@ func main() {
5759 }
5860 }()
5961
62+ logger .Infof ("starting tx-submit-api %s" , version .GetVersionString ())
63+
6064 // Start debug listener
6165 if cfg .Debug .ListenPort > 0 {
6266 logger .Infof (
Original file line number Diff line number Diff line change 1+ // Copyright 2023 Blink Labs Software
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ package version
16+
17+ import (
18+ "fmt"
19+ )
20+
21+ // These are populated at build time
22+ var Version string
23+ var CommitHash string
24+
25+ func GetVersionString () string {
26+ if Version != "" {
27+ return fmt .Sprintf ("%s (commit %s)" , Version , CommitHash )
28+ } else {
29+ return fmt .Sprintf ("devel (commit %s)" , CommitHash )
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments