Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
add: version subcommand (#13)
Browse files Browse the repository at this point in the history
use knowledge version to print the version of the knowledge tool as hardcoded at build time when using the make build target
  • Loading branch information
iwilltry42 authored May 13, 2024
1 parent d863d31 commit e8f5dcd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
GO_TAGS ?= netgo
# get git tag
ifneq ($(GIT_TAG_OVERRIDE),)
$(info GIT_TAG set from env override!)
GIT_TAG := $(GIT_TAG_OVERRIDE)
endif

GIT_TAG ?= $(shell git describe --tags)
ifeq ($(GIT_TAG),)
GIT_TAG := $(shell git describe --always)
endif

GO_TAGS := netgo
LD_FLAGS := -s -w -X github.com/gptscript-ai/knowledge/version.Version=${GIT_TAG}
build:
CGO_ENABLED=0 go build -o bin/knowledge -tags "${GO_TAGS}" -ldflags "-s -w" .
CGO_ENABLED=0 go build -o bin/knowledge -tags "${GO_TAGS}" -ldflags '$(LD_FLAGS)' .

run: build
bin/knowledge server
Expand All @@ -26,9 +38,9 @@ test:

# cross-compilation for all targets
TARGETS ?= darwin/amd64 darwin/arm64 linux/amd64 linux/386 linux/arm linux/arm64 windows/amd64
build-cross: LDFLAGS += -extldflags "-static"
build-cross: LD_FLAGS += -extldflags "-static"
build-cross:
CGO_ENABLED=0 gox -parallel=3 -output="dist/knowledge-{{.OS}}-{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(GO_TAGS),-tags '$(TAGS)',) -ldflags '$(LDFLAGS)'
CGO_ENABLED=0 gox -parallel=3 -output="dist/knowledge-{{.OS}}-{{.Arch}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(GO_TAGS),-tags '$(TAGS)',) -ldflags '$(LD_FLAGS)'
gen-checksum: build-cross
$(eval ARTIFACTS_TO_PUBLISH := $(shell ls dist/*))
$$(sha256sum $(ARTIFACTS_TO_PUBLISH) > dist/checksums.txt)
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"fmt"
"github.com/acorn-io/cmd"
"github.com/gptscript-ai/knowledge/version"
"github.com/spf13/cobra"
"log/slog"
"os"
Expand All @@ -25,6 +27,7 @@ func New() *cobra.Command {
new(ClientRetrieve),
new(ClientResetDatastore),
new(ClientAskDir),
new(Version),
)
}

Expand All @@ -33,3 +36,10 @@ type Knowledge struct{}
func (c *Knowledge) Run(cmd *cobra.Command, _ []string) error {
return cmd.Help()
}

type Version struct{}

func (c *Version) Run(cmd *cobra.Command, _ []string) error {
fmt.Println(version.Version)
return nil
}
3 changes: 3 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var Version = "dev"

0 comments on commit e8f5dcd

Please sign in to comment.