gorush/Makefile

162 lines
4.0 KiB
Makefile
Raw Normal View History

.PHONY: all gorush test build fmt vet errcheck lint install update release-dirs release-build release-copy release-check release
DIST := dist
EXECUTABLE := gorush
DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
2017-04-01 14:30:46 +00:00
GOFMT ?= gofmt "-s"
TARGETS ?= linux darwin windows
ARCHS ?= amd64 386
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
2017-04-01 14:30:46 +00:00
GOFILES := find . -name "*.go" -type f -not -path "./vendor/*"
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
else
EXTLDFLAGS =
endif
ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG)
else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
all: build
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."
fmt:
2017-04-01 14:30:46 +00:00
$(GOFILES) | xargs $(GOFMT) -w
2017-03-30 06:29:53 +00:00
.PHONY: fmt-check
fmt-check:
2017-04-01 14:30:46 +00:00
# get all go files and run go fmt on them
@files=$$($(GOFILES) | xargs $(GOFMT) -l); if [ -n "$$files" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${files}"; \
exit 1; \
fi;
2017-03-30 06:29:53 +00:00
vet:
go vet $(PACKAGES)
deps:
go get github.com/campoy/embedmd
embedmd:
embedmd -d *.md
errcheck:
2017-03-09 07:23:56 +00:00
@hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/kisielk/errcheck; \
fi
errcheck $(PACKAGES)
lint:
2017-03-09 07:23:56 +00:00
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/golang/lint/golint; \
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-01-28 03:25:54 +00:00
go get -u github.com/mdempsky/unconvert; \
fi
for PKG in $(PACKAGES); do unconvert -v $$PKG || exit 1; done;
install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
2017-03-30 06:29:53 +00:00
test: fmt-check
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;
redis_test: init
go test -v -cover ./storage/redis/...
boltdb_test: init
go test -v -cover ./storage/boltdb/...
memory_test: init
go test -v -cover ./storage/memory/...
buntdb_test: init
go test -v -cover ./storage/buntdb/...
leveldb_test: init
go test -v -cover ./storage/leveldb/...
config_test: init
go test -v -cover ./config/...
html:
go tool cover -html=.cover/coverage.txt
release: release-dirs release-build release-copy release-check
release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
release-build:
@hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -arch="$(ARCHS)" -tags="$(TAGS)" -ldflags="$(EXTLDFLAGS)-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
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;)
docker_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags "$(EXTLDFLAGS)-s -w $(LDFLAGS)" -o bin/$(EXECUTABLE)
docker_image:
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) -f Dockerfile .
docker_release: docker_build docker_image
docker_deploy:
ifeq ($(tag),)
@echo "Usage: make $@ tag=<tag>"
@exit 1
endif
docker tag $(DEPLOY_ACCOUNT)/$(EXECUTABLE):latest $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
docker push $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
coverage:
curl -s https://codecov.io/bash > .codecov && \
chmod +x .codecov && \
./.codecov -f .cover/coverage.txt
clean:
go clean -x -i ./...
find . -name coverage.txt -delete
find . -name *.tar.gz -delete
find . -name *.db -delete
-rm -rf bin/* \
.cover
version:
@echo $(VERSION)