Commit f539b9bd authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

add git commit to version and expose version in debugapi (#684)

parent ff8e5fab
...@@ -4,10 +4,8 @@ GOLANGCI_LINT_VERSION ?= v1.30.0 ...@@ -4,10 +4,8 @@ GOLANGCI_LINT_VERSION ?= v1.30.0
GOGOPROTOBUF ?= protoc-gen-gogofaster GOGOPROTOBUF ?= protoc-gen-gogofaster
GOGOPROTOBUF_VERSION ?= v1.3.1 GOGOPROTOBUF_VERSION ?= v1.3.1
LDFLAGS ?= -s -w COMMIT ?= "$(shell git describe --long --dirty --always --match "" || true)"
ifdef COMMIT LDFLAGS ?= -s -w -X github.com/ethersphere/bee.commit="$(COMMIT)"
LDFLAGS += -X github.com/ethersphere/bee.commit="$(COMMIT)"
endif
.PHONY: all .PHONY: all
all: build lint vet test-race binary all: build lint vet test-race binary
......
...@@ -7,15 +7,18 @@ package debugapi ...@@ -7,15 +7,18 @@ package debugapi
import ( import (
"net/http" "net/http"
"github.com/ethersphere/bee"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
) )
type statusResponse struct { type statusResponse struct {
Status string `json:"status"` Status string `json:"status"`
Version string `json:"version"`
} }
func (s *server) statusHandler(w http.ResponseWriter, r *http.Request) { func (s *server) statusHandler(w http.ResponseWriter, r *http.Request) {
jsonhttp.OK(w, statusResponse{ jsonhttp.OK(w, statusResponse{
Status: "ok", Status: "ok",
Version: bee.Version,
}) })
} }
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/ethersphere/bee"
"github.com/ethersphere/bee/pkg/debugapi" "github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
) )
...@@ -18,6 +19,7 @@ func TestHealth(t *testing.T) { ...@@ -18,6 +19,7 @@ func TestHealth(t *testing.T) {
jsonhttptest.Request(t, testServer.Client, http.MethodGet, "/health", http.StatusOK, jsonhttptest.Request(t, testServer.Client, http.MethodGet, "/health", http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(debugapi.StatusResponse{
Status: "ok", Status: "ok",
Version: bee.Version,
}), }),
) )
} }
...@@ -28,6 +30,7 @@ func TestReadiness(t *testing.T) { ...@@ -28,6 +30,7 @@ func TestReadiness(t *testing.T) {
jsonhttptest.Request(t, testServer.Client, http.MethodGet, "/readiness", http.StatusOK, jsonhttptest.Request(t, testServer.Client, http.MethodGet, "/readiness", http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(debugapi.StatusResponse{
Status: "ok", Status: "ok",
Version: bee.Version,
}), }),
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment