2016-12-07 08:40:00 +00:00
|
|
|
DIST := dist
|
|
|
|
EXECUTABLE := gorush
|
|
|
|
|
2017-08-15 04:16:04 +00:00
|
|
|
GO ?= go
|
2016-12-07 08:40:00 +00:00
|
|
|
DEPLOY_ACCOUNT := appleboy
|
|
|
|
DEPLOY_IMAGE := $(EXECUTABLE)
|
2017-04-01 14:30:46 +00:00
|
|
|
GOFMT ?= gofmt "-s"
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2016-12-13 14:17:21 +00:00
|
|
|
TARGETS ?= linux darwin windows
|
2017-01-02 05:58:07 +00:00
|
|
|
ARCHS ?= amd64 386
|
2017-08-15 04:16:04 +00:00
|
|
|
PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/)
|
2017-06-05 02:26:45 +00:00
|
|
|
GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
|
2016-12-07 08:40:00 +00:00
|
|
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
|
|
TAGS ?=
|
2017-01-17 02:44:33 +00:00
|
|
|
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
2017-06-01 07:52:01 +00:00
|
|
|
TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'tempdir')
|
2017-07-25 14:50:00 +00:00
|
|
|
NODE_PROTOC_PLUGIN := $(shell which grpc_tools_node_protoc_plugin)
|
2018-01-04 08:32:50 +00:00
|
|
|
GOVENDOR := $(GOPATH)/bin/govendor
|
|
|
|
GOX := $(GOPATH)/bin/gox
|
|
|
|
MISSPELL := $(GOPATH)/bin/misspell
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2016-08-15 12:43:34 +00:00
|
|
|
ifneq ($(shell uname), Darwin)
|
|
|
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
|
|
|
else
|
|
|
|
EXTLDFLAGS =
|
|
|
|
endif
|
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
ifneq ($(DRONE_TAG),)
|
|
|
|
VERSION ?= $(DRONE_TAG)
|
|
|
|
else
|
2016-12-09 17:15:45 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
2016-12-07 08:40:00 +00:00
|
|
|
endif
|
|
|
|
|
2017-07-26 15:24:43 +00:00
|
|
|
.PHONY: all
|
2016-03-27 12:20:57 +00:00
|
|
|
all: build
|
|
|
|
|
2016-05-22 03:17:40 +00:00
|
|
|
init:
|
|
|
|
ifeq ($(ANDROID_API_KEY),)
|
|
|
|
@echo "Missing ANDROID_API_KEY Parameter"
|
|
|
|
@exit 1
|
|
|
|
endif
|
|
|
|
ifeq ($(ANDROID_TEST_TOKEN),)
|
|
|
|
@echo "Missing ANDROID_TEST_TOKEN Parameter"
|
|
|
|
@exit 1
|
|
|
|
endif
|
|
|
|
@echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable."
|
|
|
|
|
2018-01-04 08:32:50 +00:00
|
|
|
$(GOVENDOR):
|
|
|
|
$(GO) get -u github.com/kardianos/govendor
|
|
|
|
|
|
|
|
$(GOX):
|
|
|
|
$(GO) get -u github.com/mitchellh/gox
|
|
|
|
|
|
|
|
$(MISSPELL):
|
|
|
|
$(GO) get -u github.com/client9/misspell/cmd/misspell
|
2017-09-12 03:44:42 +00:00
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
fmt:
|
2017-06-05 02:26:45 +00:00
|
|
|
$(GOFMT) -w $(GOFILES)
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2017-03-30 06:29:53 +00:00
|
|
|
.PHONY: fmt-check
|
|
|
|
fmt-check:
|
2017-06-05 02:26:45 +00:00
|
|
|
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
|
|
|
if [ -n "$$diff" ]; then \
|
2017-04-01 14:30:46 +00:00
|
|
|
echo "Please run 'make fmt' and commit the result:"; \
|
2017-06-05 02:26:45 +00:00
|
|
|
echo "$${diff}"; \
|
2017-04-01 14:30:46 +00:00
|
|
|
exit 1; \
|
2017-06-05 02:26:45 +00:00
|
|
|
fi;
|
2017-03-30 06:29:53 +00:00
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
vet:
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) vet $(PACKAGES)
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2017-02-25 12:31:49 +00:00
|
|
|
deps:
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) get github.com/campoy/embedmd
|
2017-02-25 12:31:49 +00:00
|
|
|
|
|
|
|
embedmd:
|
|
|
|
embedmd -d *.md
|
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
errcheck:
|
2017-03-09 07:23:56 +00:00
|
|
|
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) get -u github.com/kisielk/errcheck; \
|
2016-12-07 08:40:00 +00:00
|
|
|
fi
|
|
|
|
errcheck $(PACKAGES)
|
|
|
|
|
|
|
|
lint:
|
2017-03-09 07:23:56 +00:00
|
|
|
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) get -u github.com/golang/lint/golint; \
|
2016-12-07 08:40:00 +00:00
|
|
|
fi
|
|
|
|
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
|
|
|
|
|
2017-01-28 03:25:54 +00:00
|
|
|
unconvert:
|
2017-03-09 07:23:56 +00:00
|
|
|
@hash unconvert > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) get -u github.com/mdempsky/unconvert; \
|
2017-01-28 03:25:54 +00:00
|
|
|
fi
|
|
|
|
for PKG in $(PACKAGES); do unconvert -v $$PKG || exit 1; done;
|
|
|
|
|
2018-01-04 08:32:50 +00:00
|
|
|
.PHONY: install
|
2016-12-09 17:15:45 +00:00
|
|
|
install: $(SOURCES)
|
2017-10-22 23:42:38 +00:00
|
|
|
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
2017-08-19 13:23:29 +00:00
|
|
|
@echo "==> Installed gorush ${GOPATH}/bin/gorush"
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2017-08-19 13:23:29 +00:00
|
|
|
.PHONY: build
|
2017-12-11 01:17:36 +00:00
|
|
|
build: $(EXECUTABLE)
|
2016-07-30 14:05:38 +00:00
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
$(EXECUTABLE): $(SOURCES)
|
2017-12-10 11:07:58 +00:00
|
|
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/$@
|
2016-08-15 12:43:34 +00:00
|
|
|
|
2017-06-05 02:45:38 +00:00
|
|
|
.PHONY: misspell-check
|
2018-01-04 08:32:50 +00:00
|
|
|
misspell-check: $(MISSPELL)
|
|
|
|
$(MISSPELL) -error $(GOFILES)
|
2017-06-05 02:42:07 +00:00
|
|
|
|
2017-06-05 03:50:00 +00:00
|
|
|
.PHONY: misspell
|
2018-01-04 08:32:50 +00:00
|
|
|
misspell: $(MISSPELL)
|
|
|
|
$(MISSPELL) -w $(GOFILES)
|
2017-06-05 03:50:00 +00:00
|
|
|
|
2018-04-22 01:17:16 +00:00
|
|
|
.PHONY: coverage
|
|
|
|
coverage:
|
|
|
|
@hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
|
|
$(GO) get -u github.com/wadey/gocovmerge; \
|
|
|
|
fi
|
|
|
|
gocovmerge $(shell find . -type f -name "coverage.out") > coverage.all;\
|
|
|
|
|
|
|
|
.PHONY: unit-test-coverage
|
|
|
|
unit-test-coverage: init
|
|
|
|
for PKG in $(PACKAGES); do $(GO) test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
|
|
|
|
|
|
|
|
test: init
|
|
|
|
for PKG in $(PACKAGES); do $(GO) test -v $$PKG || exit 1; done;
|
2016-05-03 01:42:53 +00:00
|
|
|
|
2017-06-01 07:52:01 +00:00
|
|
|
.PHONY: test-vendor
|
2018-01-04 08:32:50 +00:00
|
|
|
test-vendor: $(GOVENDOR)
|
|
|
|
$(GOVENDOR) list +unused | tee "$(TMPDIR)/wc-gitea-unused"
|
2017-06-01 07:52:01 +00:00
|
|
|
[ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
|
|
|
|
|
2018-01-04 08:32:50 +00:00
|
|
|
$(GOVENDOR) list +outside | tee "$(TMPDIR)/wc-gitea-outside"
|
2017-06-01 07:52:01 +00:00
|
|
|
[ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1
|
|
|
|
|
2018-01-04 08:32:50 +00:00
|
|
|
$(GOVENDOR) status || exit 1
|
2017-06-01 07:52:01 +00:00
|
|
|
|
2016-05-22 03:17:40 +00:00
|
|
|
redis_test: init
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) test -v -cover ./storage/redis/...
|
2016-05-03 01:42:53 +00:00
|
|
|
|
2016-05-22 03:17:40 +00:00
|
|
|
boltdb_test: init
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) test -v -cover ./storage/boltdb/...
|
2016-05-04 01:29:36 +00:00
|
|
|
|
2016-05-22 03:17:40 +00:00
|
|
|
memory_test: init
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) test -v -cover ./storage/memory/...
|
2016-05-04 01:29:36 +00:00
|
|
|
|
2016-08-02 07:35:28 +00:00
|
|
|
buntdb_test: init
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) test -v -cover ./storage/buntdb/...
|
2016-08-02 07:35:28 +00:00
|
|
|
|
2016-09-19 08:19:20 +00:00
|
|
|
leveldb_test: init
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) test -v -cover ./storage/leveldb/...
|
2016-09-19 08:19:20 +00:00
|
|
|
|
2016-05-22 03:17:40 +00:00
|
|
|
config_test: init
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) test -v -cover ./config/...
|
2016-05-03 01:42:53 +00:00
|
|
|
|
2016-05-04 01:29:36 +00:00
|
|
|
html:
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) tool cover -html=.cover/coverage.txt
|
2016-04-11 06:10:46 +00:00
|
|
|
|
2016-12-08 03:43:23 +00:00
|
|
|
release: release-dirs release-build release-copy release-check
|
|
|
|
|
|
|
|
release-dirs:
|
|
|
|
mkdir -p $(DIST)/binaries $(DIST)/release
|
|
|
|
|
2018-01-04 08:32:50 +00:00
|
|
|
release-build: $(GOX)
|
|
|
|
$(GOX) -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="$(EXTLDFLAGS)-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
|
2016-12-08 03:43:23 +00:00
|
|
|
|
|
|
|
release-copy:
|
|
|
|
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
|
|
|
|
|
|
|
|
release-check:
|
|
|
|
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
|
|
|
|
2017-12-10 11:00:15 +00:00
|
|
|
build_linux_amd64:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
2016-12-07 08:40:00 +00:00
|
|
|
|
2017-12-10 11:00:15 +00:00
|
|
|
build_linux_i386:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE)
|
2017-08-31 06:25:56 +00:00
|
|
|
|
2017-12-10 11:00:15 +00:00
|
|
|
build_linux_arm64:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
|
|
|
|
|
|
|
|
build_linux_arm:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
|
2017-08-25 05:51:04 +00:00
|
|
|
|
2018-01-23 08:34:34 +00:00
|
|
|
build_linux_lambda:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags 'lambda' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/lambda/$(DEPLOY_IMAGE)
|
|
|
|
|
2016-12-07 08:40:00 +00:00
|
|
|
docker_image:
|
|
|
|
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) -f Dockerfile .
|
|
|
|
|
2017-05-15 15:29:49 +00:00
|
|
|
docker_release: docker_image
|
2016-05-22 14:28:57 +00:00
|
|
|
|
2016-10-01 08:11:23 +00:00
|
|
|
docker_deploy:
|
2016-04-11 09:18:53 +00:00
|
|
|
ifeq ($(tag),)
|
|
|
|
@echo "Usage: make $@ tag=<tag>"
|
|
|
|
@exit 1
|
|
|
|
endif
|
2016-12-08 04:01:10 +00:00
|
|
|
docker tag $(DEPLOY_ACCOUNT)/$(EXECUTABLE):latest $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
|
2016-12-07 08:40:00 +00:00
|
|
|
docker push $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
|
2016-04-11 09:18:53 +00:00
|
|
|
|
2016-03-27 12:20:57 +00:00
|
|
|
clean:
|
2017-08-15 04:16:04 +00:00
|
|
|
$(GO) clean -x -i ./...
|
2016-12-07 08:40:00 +00:00
|
|
|
find . -name coverage.txt -delete
|
2016-12-08 04:01:10 +00:00
|
|
|
find . -name *.tar.gz -delete
|
|
|
|
find . -name *.db -delete
|
2017-12-11 01:17:36 +00:00
|
|
|
-rm -rf release dist .cover
|
2016-11-20 01:54:16 +00:00
|
|
|
|
2017-07-25 14:53:21 +00:00
|
|
|
rpc/example/node/gorush_*_pb.js: rpc/proto/gorush.proto
|
2018-01-02 14:33:16 +00:00
|
|
|
@hash grpc_tools_node_protoc_plugin > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
|
|
npm install -g grpc-tools; \
|
|
|
|
fi
|
2017-07-25 14:50:00 +00:00
|
|
|
protoc -I rpc/proto rpc/proto/gorush.proto --js_out=import_style=commonjs,binary:rpc/example/node/ --grpc_out=rpc/example/node/ --plugin=protoc-gen-grpc=$(NODE_PROTOC_PLUGIN)
|
|
|
|
|
|
|
|
rpc/proto/gorush.pb.go: rpc/proto/gorush.proto
|
|
|
|
protoc -I rpc/proto rpc/proto/gorush.proto --go_out=plugins=grpc:rpc/proto
|
|
|
|
|
2017-07-25 14:53:21 +00:00
|
|
|
generate_proto: rpc/proto/gorush.pb.go rpc/example/node/gorush_*_pb.js
|
2017-07-25 14:50:00 +00:00
|
|
|
|
2016-11-20 01:54:16 +00:00
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|