137 lines
3.6 KiB
Makefile
137 lines
3.6 KiB
Makefile
EXECUTABLE := statusmon
|
|
DIST := dist
|
|
export GO111MODULE=on
|
|
|
|
GO ?= go
|
|
SHASUM ?= shasum -a 256
|
|
|
|
export PATH := $($(GO) env GOPATH)/bin:$(PATH)
|
|
|
|
GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*")
|
|
GOFMT ?= gofmt -s
|
|
|
|
ifneq ($(DRONE_TAG),)
|
|
VERSION ?= $(subst v,,$(DRONE_TAG))
|
|
TEA_VERSION ?= $(VERSION)
|
|
else
|
|
ifneq ($(DRONE_BRANCH),)
|
|
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
|
|
else
|
|
ifeq ($(VERSION),)
|
|
VERSION ?= master
|
|
endif
|
|
endif
|
|
TEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
|
|
endif
|
|
|
|
TAGS ?=
|
|
TAGS_STATIC := osusergo,netgo,static_build,$(TAGS)
|
|
|
|
LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)"
|
|
LDFLAGS_STATIC := $(LDFLAGS) -extldflags "-fno-PIC -static" -s -w
|
|
|
|
GOFLAGS := -mod=vendor -tags '$(TAGS)' -ldflags '$(LDFLAGS)'
|
|
# TODO: clean this mess up when there are news on https://github.com/golang/go/issues/26492
|
|
GOFLAGS_STATIC_GOX := $(GOFLAGS) -tags '$(TAGS_STATIC)' -ldflags '$(LDFLAGS_STATIC) -s -w'
|
|
ifeq ($(STATIC),true)
|
|
GOFLAGS := $(GOFLAGS_STATIC_GOX) -buildmode=pie
|
|
endif
|
|
|
|
PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/)
|
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
|
|
ifeq ($(OS), Windows_NT)
|
|
EXECUTABLE := $(EXECUTABLE).exe
|
|
endif
|
|
|
|
.PHONY: all
|
|
all: build
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(GO) clean -mod=vendor -i ./...
|
|
rm -rf $(EXECUTABLE) $(DIST)
|
|
|
|
.PHONY: fmt
|
|
fmt:
|
|
$(GOFMT) -w $(GOFILES)
|
|
|
|
.PHONY: fmt-check
|
|
fmt-check:
|
|
# get all go files and run go fmt on them
|
|
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
|
if [ -n "$$diff" ]; then \
|
|
echo "Please run 'make fmt' and commit the result:"; \
|
|
echo "$${diff}"; \
|
|
exit 1; \
|
|
fi;
|
|
|
|
.PHONY: test
|
|
test:
|
|
$(GO) test -mod=vendor -tags='$(TAGS)' $(PACKAGES)
|
|
|
|
.PHONY: unit-test-coverage
|
|
unit-test-coverage:
|
|
$(GO) test -mod=vendor -tags='$(TAGS)' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
|
|
|
.PHONY: vendor
|
|
vendor:
|
|
$(GO) mod tidy && $(GO) mod vendor
|
|
|
|
.PHONY: test-vendor
|
|
test-vendor: vendor
|
|
@diff=$$(git diff vendor/); \
|
|
if [ -n "$$diff" ]; then \
|
|
echo "Please run 'make vendor' and commit the result:"; \
|
|
echo "$${diff}"; \
|
|
exit 1; \
|
|
fi;
|
|
|
|
.PHONY: check
|
|
check: test
|
|
|
|
.PHONY: install
|
|
install: $(SOURCES)
|
|
@echo "installing to $(GOPATH)/bin/$(EXECUTABLE)"
|
|
$(GO) install -v $(GOFLAGS)
|
|
|
|
.PHONY: build
|
|
build: $(EXECUTABLE)
|
|
|
|
$(EXECUTABLE): $(SOURCES)
|
|
$(GO) build -v $(GOFLAGS) -o $@
|
|
|
|
.PHONY: release
|
|
release: release-dirs release-os release-compress release-check
|
|
|
|
.PHONY: release-dirs
|
|
release-dirs:
|
|
mkdir -p $(DIST)/binaries $(DIST)/release
|
|
|
|
.PHONY: release-os
|
|
release-os:
|
|
@hash gox > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
cd /tmp && $(GO) get -u github.com/mitchellh/gox; \
|
|
fi
|
|
CGO_ENABLED=0 gox -verbose -cgo=false $(GOFLAGS_STATIC_GOX) -osarch='!darwin/386 !darwin/arm64 !darwin/arm' -os="windows linux darwin" -arch="386 amd64 arm arm64" -output="$(DIST)/release/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
|
|
|
|
.PHONY: release-compress
|
|
release-compress:
|
|
@hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
GO111MODULE=off $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
|
|
fi
|
|
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
|
|
|
|
.PHONY: release-check
|
|
release-check:
|
|
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
|
|
|
|
.PHONY: publish
|
|
publish:
|
|
git tag $(VERSION)
|
|
git push
|
|
git push --tags
|
|
make clean release
|
|
tea releases create \
|
|
--title $(VERSION) --tag $(VERSION) --target master \
|
|
$(shell find $(DIST)/release/ -type f | xargs -L1 echo --asset )
|