aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2021-09-13 22:41:42 +0200
committerGitHub <noreply@github.com>2021-09-13 22:41:42 +0200
commitd8a2b0a0b90b49c89421518fecdb7c84643eb114 (patch)
tree4f6568309bf678653502f84f0ee81c201be75cb1
parent51b1e5418c40c69e4f5c822aa75d3647a5993737 (diff)
parentc2f997b4792529535e544ec3957bdf6369e6ef63 (diff)
Merge pull request #19091 from vespa-engine/mpolden/release-targets
Basic Vespa CLI release mechanism
-rw-r--r--client/go/.gitignore1
-rw-r--r--client/go/Makefile93
-rw-r--r--client/go/README.md6
-rw-r--r--client/go/cmd/version.go3
-rw-r--r--client/go/cmd/version_test.go2
5 files changed, 97 insertions, 8 deletions
diff --git a/client/go/.gitignore b/client/go/.gitignore
index b35a2cef362..eb679add05e 100644
--- a/client/go/.gitignore
+++ b/client/go/.gitignore
@@ -1,4 +1,5 @@
bin/
+dist/
share/
!Makefile
!build/
diff --git a/client/go/Makefile b/client/go/Makefile
index 3297b628cb2..17748d765c8 100644
--- a/client/go/Makefile
+++ b/client/go/Makefile
@@ -1,23 +1,104 @@
# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# The version to release. Defaults to the current tag or revision.
+# Use env VERSION=X.Y.Z make ... to override
+VERSION ?= $(shell git describe --tags 2> /dev/null | sed -E "s/^vespa-|-1$$//g")
+DEVEL_VERSION := $(shell echo "0.0.0-`git rev-parse --short HEAD`")
+ifeq ($(VERSION),)
+ VERSION = $(DEVEL_VERSION)
+endif
+
BIN ?= $(CURDIR)/bin
SHARE ?= $(CURDIR)/share
-# When building a new release the build system should set the VERSION
-# environment variable to version being built
-VERSION ?= $(shell echo "0.0.0-`git rev-parse --short HEAD`")
+DIST ?= $(CURDIR)/dist
+
+GO_FLAGS := -ldflags "-X github.com/vespa-engine/vespa/client/go/build.Version=$(VERSION)"
+GIT_ROOT := $(shell git rev-parse --show-toplevel)
+DIST_TARGETS := dist-mac dist-linux dist-win32 dist-win64
all: test checkfmt install
+#
+# Dist targets
+#
+
+# Bump the version of the vespa-cli formula and create a pull request to Homebrew repository.
+#
+# Example:
+#
+# $ git checkout vespa-X.Y.Z-1
+# $ make dist-github
+dist-homebrew: dist-version
+ brew bump-formula-pr --tag vespa-$(VERSION)-1 --version $(VERSION) vespa-cli
+
+# Create a GitHub release draft for all platforms. Note that this only creates a
+# draft, which is not publicly visible until it's explicitly published.
+#
+# Once the release has been created this prints an URL to the release draft.
+#
+# This requires the GitHub CLI to be installed: brew install gh
+#
+# Example:
+#
+# $ git checkout vespa-X.Y.Z-1
+# $ make dist-github
+dist-github: dist
+ gh release create v$(VERSION) --repo vespa-engine/vespa --notes-file $(CURDIR)/README.md --draft --title "Vespa CLI $(VERSION)" \
+ $(DIST)/vespa-cli_$(VERSION)_sha256sums.txt \
+ $(DIST)/vespa-cli_$(VERSION)_*.{zip,tar.gz}
+
+#
+# Cross-platform build targets
+#
+
+dist: $(DIST_TARGETS) dist-sha256sums
+
+dist-mac: GOOS=darwin
+dist-mac: GOARCH=amd64
+
+dist-linux: GOOS=linux
+dist-linux: GOARCH=amd64
+
+dist-win32: GOOS=windows
+dist-win32: GOARCH=386
+
+dist-win64: GOOS=windows
+dist-win64: GOARCH=amd64
+
+$(DIST_TARGETS): DIST_NAME=vespa-cli_$(VERSION)_$(GOOS)_$(GOARCH)
+$(DIST_TARGETS): dist-version manpages
+$(DIST_TARGETS):
+ mkdir -p $(DIST)/$(DIST_NAME)/bin
+ env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(DIST)/$(DIST_NAME)/bin $(GO_FLAGS) ./...
+ cp -a $(GIT_ROOT)/LICENSE $(DIST)/$(DIST_NAME)
+ if [ "$(GOOS)" = "windows" ]; then \
+ cd $(DIST) && zip -r $(DIST)/$(DIST_NAME).zip $(DIST_NAME); \
+ else \
+ cp -a share $(DIST)/$(DIST_NAME); \
+ tar -czvf $(DIST)/$(DIST_NAME).tar.gz -C $(DIST) $(DIST_NAME); \
+ fi
+
+dist-sha256sums:
+ cd $(DIST) && sha256sum vespa-cli_$(VERSION)_*.{zip,tar.gz} > vespa-cli_$(VERSION)_sha256sums.txt
+
+dist-version:
+ifeq ($(VERSION),$(DEVEL_VERSION))
+ $(error Invalid release version: $(VERSION). Try 'git checkout vespa-X.Y.Z-1' or 'env VERSION=X.Y.Z make ...')
+endif
+
+#
+# Development targets
+#
+
install:
- env GOBIN=$(BIN) \
- go install -ldflags "-X github.com/vespa-engine/vespa/client/go/build.Version=$(VERSION)" ./...
+ env GOBIN=$(BIN) go install $(GO_FLAGS) ./...
manpages: install
mkdir -p $(SHARE)/man/man1
$(BIN)/vespa man $(SHARE)/man/man1
clean:
- rm -rf $(BIN) $(SHARE)
+ rm -rf $(BIN) $(SHARE) $(DIST)
test:
go test ./...
diff --git a/client/go/README.md b/client/go/README.md
new file mode 100644
index 00000000000..7b5b222503c
--- /dev/null
+++ b/client/go/README.md
@@ -0,0 +1,6 @@
+The command-line tool for Vespa.ai.
+
+Use it on Vespa instances running locally, remotely or in the cloud.
+Prefer web service API's to this in production.
+
+Vespa documentation: https://docs.vespa.ai
diff --git a/client/go/cmd/version.go b/client/go/cmd/version.go
index 4a5b6ec71b3..05820f4e34b 100644
--- a/client/go/cmd/version.go
+++ b/client/go/cmd/version.go
@@ -2,6 +2,7 @@ package cmd
import (
"log"
+ "runtime"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
@@ -17,6 +18,6 @@ var versionCmd = &cobra.Command{
DisableAutoGenTag: true,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
- log.Print("vespa version ", build.Version)
+ log.Printf("vespa version %s compiled with %v on %v/%v", build.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
},
}
diff --git a/client/go/cmd/version_test.go b/client/go/cmd/version_test.go
index 02303a08e21..fc977c47938 100644
--- a/client/go/cmd/version_test.go
+++ b/client/go/cmd/version_test.go
@@ -7,5 +7,5 @@ import (
)
func TestVersion(t *testing.T) {
- assert.Equal(t, "vespa version 0.0.0-devel\n", execute(command{args: []string{"version"}}, t, nil))
+ assert.Contains(t, execute(command{args: []string{"version"}}, t, nil), "vespa version 0.0.0-devel compiled with")
}