-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
89 lines (73 loc) · 2.47 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
.DEFAULT_GOAL := build
CMD = crop
GOARCH = $(shell go env GOARCH)
GOOS = $(shell go env GOOS)
TARGET = ${GOOS}_${GOARCH}
DIST_PATH = dist
BUILD_PATH = ${DIST_PATH}/${CMD}_${TARGET}
DESTDIR = /usr/local/bin
GO_FILES = $(shell find . -path ./vendor -prune -or -type f -name '*.go' -print)
GO_PACKAGES = $(shell go list -mod vendor ./...)
GIT_COMMIT = $(shell git rev-parse --short HEAD)
TIMESTAMP = $(shell date +%s)
VERSION ?= 0.0.0-dev
# Deps
.PHONY: check_golangci
check_golangci:
@command -v golangci-lint >/dev/null || (echo "golangci-lint is required."; exit 1)
.PHONY: check_goreleaser
check_goreleaser:
@command -v goreleaser >/dev/null || (echo "goreleaser is required."; exit 1)
.PHONY: all ## Run tests, linting and build
all: test lint build
.PHONY: test-all ## Run tests and linting
test-all: test lint
.PHONY: test
test: ## Run tests
@echo "*** go test ***"
go test -cover -v -race ${GO_PACKAGES}
.PHONY: lint
lint: check_golangci ## Run linting
@echo "*** golangci-lint ***"
golangci-lint run --timeout 10m
.PHONY: vendor
vendor: ## Vendor files and tidy go.mod
go mod vendor
go mod tidy
.PHONY: vendor_update
vendor_update: ## Update vendor dependencies
go get -u ./...
${MAKE} vendor
.PHONY: build
build: vendor ${BUILD_PATH}/${CMD} ## Build application
# Binary
${BUILD_PATH}/${CMD}: ${GO_FILES} go.sum
@echo "Building for ${TARGET}..." && \
mkdir -p ${BUILD_PATH} && \
CGO_ENABLED=0 go build \
-mod vendor \
-trimpath \
-ldflags "-s -w -X github.com/l3uddz/crop/runtime.Version=${VERSION} -X github.com/l3uddz/crop/runtime.GitCommit=${GIT_COMMIT} -X github.com/l3uddz/crop/runtime.Timestamp=${TIMESTAMP}" \
-o ${BUILD_PATH}/${CMD} \
.
.PHONY: install
install: build ## Install binary
install -m 0755 ${BUILD_PATH}/${CMD} ${DESTDIR}/${CMD}
.PHONY: clean
clean: ## Cleanup
rm -rf ${DIST_PATH}
.PHONY: fetch
fetch: ## Fetch vendor files
go mod vendor
.PHONY: release
release: check_goreleaser #fetch ## Generate a release, but don't publish
goreleaser --skip-validate --skip-publish --rm-dist
.PHONY: publish
publish: check_goreleaser #fetch ## Generate a release, and publish
goreleaser --rm-dist
.PHONY: snapshot
snapshot: check_goreleaser #fetch ## Generate a snapshot release
goreleaser --snapshot --skip-validate --skip-publish --rm-dist
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'