2017-07-04 07:45:25 +03:00
|
|
|
DIST := dist
|
|
|
|
EXECUTABLE := drone-telegram
|
2021-01-14 16:15:06 +03:00
|
|
|
GOFMT ?= gofumpt -l -s
|
2019-02-16 18:39:20 +03:00
|
|
|
GO ?= go
|
2016-10-04 16:45:49 +03:00
|
|
|
|
2017-07-04 07:45:25 +03:00
|
|
|
# for dockerhub
|
|
|
|
DEPLOY_ACCOUNT := appleboy
|
|
|
|
DEPLOY_IMAGE := $(EXECUTABLE)
|
|
|
|
|
2021-01-14 16:15:06 +03:00
|
|
|
TARGETS ?= linux darwin
|
2017-07-04 07:45:25 +03:00
|
|
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
|
|
TAGS ?=
|
2019-02-16 18:39:20 +03:00
|
|
|
LDFLAGS ?= -X 'main.Version=$(VERSION)'
|
2016-10-04 16:45:49 +03:00
|
|
|
|
|
|
|
ifneq ($(shell uname), Darwin)
|
|
|
|
EXTLDFLAGS = -extldflags "-static" $(null)
|
|
|
|
else
|
|
|
|
EXTLDFLAGS =
|
|
|
|
endif
|
|
|
|
|
2017-07-04 07:45:25 +03:00
|
|
|
ifneq ($(DRONE_TAG),)
|
|
|
|
VERSION ?= $(DRONE_TAG)
|
|
|
|
else
|
|
|
|
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
|
|
|
endif
|
|
|
|
|
|
|
|
all: build
|
|
|
|
|
|
|
|
fmt:
|
2021-01-14 16:15:06 +03:00
|
|
|
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
|
|
$(GO) get -u mvdan.cc/gofumpt; \
|
|
|
|
fi
|
2019-02-16 18:39:20 +03:00
|
|
|
$(GOFMT) -w $(SOURCES)
|
2017-07-04 07:45:25 +03:00
|
|
|
|
|
|
|
vet:
|
2020-02-01 12:59:25 +03:00
|
|
|
$(GO) vet ./...
|
2017-07-04 07:45:25 +03:00
|
|
|
|
|
|
|
lint:
|
2019-02-16 18:39:20 +03:00
|
|
|
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
|
|
$(GO) get -u github.com/mgechev/revive; \
|
2017-07-04 07:45:25 +03:00
|
|
|
fi
|
2019-02-16 18:39:20 +03:00
|
|
|
revive -config .revive.toml ./... || exit 1
|
2017-07-04 07:45:25 +03:00
|
|
|
|
|
|
|
.PHONY: misspell-check
|
|
|
|
misspell-check:
|
|
|
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2019-02-16 18:39:20 +03:00
|
|
|
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
|
2017-07-04 07:45:25 +03:00
|
|
|
fi
|
2019-02-16 18:39:20 +03:00
|
|
|
misspell -error $(SOURCES)
|
2017-07-04 07:45:25 +03:00
|
|
|
|
|
|
|
.PHONY: misspell
|
|
|
|
misspell:
|
|
|
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2019-02-16 18:39:20 +03:00
|
|
|
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
|
2017-07-04 07:45:25 +03:00
|
|
|
fi
|
2019-02-16 18:39:20 +03:00
|
|
|
misspell -w $(SOURCES)
|
2017-07-04 07:45:25 +03:00
|
|
|
|
|
|
|
.PHONY: fmt-check
|
|
|
|
fmt-check:
|
2021-01-14 16:15:06 +03:00
|
|
|
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
|
|
$(GO) get -u mvdan.cc/gofumpt; \
|
|
|
|
fi
|
2019-02-16 18:39:20 +03:00
|
|
|
@diff=$$($(GOFMT) -d $(SOURCES)); \
|
2017-07-04 07:45:25 +03:00
|
|
|
if [ -n "$$diff" ]; then \
|
|
|
|
echo "Please run 'make fmt' and commit the result:"; \
|
|
|
|
echo "$${diff}"; \
|
|
|
|
exit 1; \
|
|
|
|
fi;
|
2016-10-04 16:45:49 +03:00
|
|
|
|
2017-07-04 07:45:25 +03:00
|
|
|
test: fmt-check
|
2020-02-01 12:59:25 +03:00
|
|
|
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
2016-10-04 16:45:49 +03:00
|
|
|
|
2017-07-04 07:45:25 +03:00
|
|
|
install: $(SOURCES)
|
2019-02-16 18:39:20 +03:00
|
|
|
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
2017-07-04 07:45:25 +03:00
|
|
|
|
|
|
|
build: $(EXECUTABLE)
|
|
|
|
|
|
|
|
$(EXECUTABLE): $(SOURCES)
|
2019-02-16 18:39:20 +03:00
|
|
|
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
|
2017-07-04 07:45:25 +03:00
|
|
|
|
|
|
|
release: release-dirs release-build release-copy release-check
|
|
|
|
|
|
|
|
release-dirs:
|
|
|
|
mkdir -p $(DIST)/binaries $(DIST)/release
|
|
|
|
|
|
|
|
release-build:
|
|
|
|
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
|
2019-02-16 18:39:20 +03:00
|
|
|
$(GO) get -u github.com/mitchellh/gox; \
|
2017-07-04 07:45:25 +03:00
|
|
|
fi
|
2021-01-14 16:15:06 +03:00
|
|
|
gox -os="$(TARGETS)" -arch="amd64" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
|
2017-07-04 07:45:25 +03: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-09 13:10:06 +03:00
|
|
|
build_linux_amd64:
|
2019-02-16 18:39:20 +03:00
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
|
2017-12-09 13:10:06 +03:00
|
|
|
|
|
|
|
build_linux_i386:
|
2019-02-16 18:39:20 +03:00
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=386 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/i386/$(DEPLOY_IMAGE)
|
2017-12-09 13:10:06 +03:00
|
|
|
|
|
|
|
build_linux_arm64:
|
2019-02-16 18:39:20 +03:00
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
|
2017-12-09 13:10:06 +03:00
|
|
|
|
|
|
|
build_linux_arm:
|
2019-02-16 18:39:20 +03:00
|
|
|
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)
|
2016-10-04 16:45:49 +03:00
|
|
|
|
|
|
|
docker_image:
|
2016-11-27 11:39:31 +03:00
|
|
|
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
|
2016-10-04 16:45:49 +03:00
|
|
|
|
2019-02-16 18:39:20 +03:00
|
|
|
docker: docker_image
|
2016-10-04 16:45:49 +03:00
|
|
|
|
|
|
|
docker_deploy:
|
|
|
|
ifeq ($(tag),)
|
|
|
|
@echo "Usage: make $@ tag=<tag>"
|
|
|
|
@exit 1
|
|
|
|
endif
|
2017-07-04 07:45:25 +03:00
|
|
|
# deploy image
|
2016-10-04 16:45:49 +03:00
|
|
|
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
|
|
|
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
|
|
|
|
|
2017-07-04 07:45:25 +03:00
|
|
|
coverage:
|
|
|
|
sed -i '/main.go/d' coverage.txt
|
|
|
|
|
2016-10-04 16:45:49 +03:00
|
|
|
clean:
|
2019-02-16 18:39:20 +03:00
|
|
|
$(GO) clean -x -i ./...
|
|
|
|
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
|
2016-11-18 05:58:36 +03:00
|
|
|
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|