Skip to content

Commit bb6b3c8

Browse files
committed
feat: add version command and build metadata to Makefile
1 parent bf36a17 commit bb6b3c8

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
.PHONY: build test vet check ui-install ui-build dev-ui dev-go
22

3+
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
4+
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
5+
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
6+
LDFLAGS := -X github.com/RandomCodeSpace/docscontext/cmd.Version=$(VERSION) \
7+
-X github.com/RandomCodeSpace/docscontext/cmd.Commit=$(COMMIT) \
8+
-X github.com/RandomCodeSpace/docscontext/cmd.Date=$(DATE)
9+
310
ui-install:
411
cd ui && npm install
512

613
ui-build:
714
cd ui && npm run build
815

916
build: ui-build
10-
CGO_ENABLED=0 go build ./...
17+
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" ./...
1118

1219
test:
1320
CGO_ENABLED=0 go test -timeout 120s ./...

cmd/version.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
// Set via -ldflags at build time.
10+
var (
11+
Version = "dev"
12+
Commit = "unknown"
13+
Date = "unknown"
14+
)
15+
16+
var versionCmd = &cobra.Command{
17+
Use: "version",
18+
Short: "Print the version of DocsContext",
19+
Run: func(cmd *cobra.Command, args []string) {
20+
fmt.Printf("DocsContext %s (commit: %s, built: %s)\n", Version, Commit, Date)
21+
},
22+
}
23+
24+
func init() {
25+
rootCmd.AddCommand(versionCmd)
26+
}

ui/dist/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<\!DOCTYPE html>

0 commit comments

Comments
 (0)