-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakefile
127 lines (109 loc) · 3.76 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
.DEFAULT_GOAL=help
# Required for globs to work correctly
SHELL:=/bin/bash
BUILD_TIME = $(shell date +%FT%T%z)
BUILD_DIR = $(CURDIR)/build
GIT_HASH = $(shell git rev-parse --short HEAD)
PKG_PREFIX = github.com/hangxie/parquet-tools
REL_TARGET = \
darwin-amd64 darwin-arm64 \
linux-amd64 linux-arm linux-arm64 \
windows-amd64 windows-arm64 \
freebsd-amd64
VERSION = $(shell git describe --tags --always)
# go option
CGO_ENABLED := 0
GO ?= go
GOBIN = $(shell go env GOPATH)/bin
GOFLAGS := -trimpath
GOSOURCES := $(shell find . -type f -name '*.go')
LDFLAGS := -w -s
LDFLAGS += -extldflags "-static" \
-X $(PKG_PREFIX)/cmd.version=$(VERSION) \
-X $(PKG_PREFIX)/cmd.build=$(BUILD_TIME) \
-X $(PKG_PREFIX)/cmd.gitHash=$(GIT_HASH) \
-X ${PKG_PREFIX}/cmd.source=Makefile
.EXPORT_ALL_VARIABLES:
.PHONY: all
all: deps tools format lint test build ## Build all common targets
.PHONY: format
format: tools ## Format all go code
@echo "==> Formatting all go code"
@$(GOBIN)/gofumpt -w -extra $(GOSOURCES)
@$(GOBIN)/goimports -w -local $(PKG_PREFIX) $(GOSOURCES)
.PHONY: lint
lint: tools ## Run static code analysis
@echo "==> Running static code analysis"
@$(GOBIN)/golangci-lint cache clean
@$(GOBIN)/golangci-lint run --timeout 5m ./...
@$(GOBIN)/gocyclo -over 15 . > /tmp/gocyclo.output; \
if [[ -s /tmp/gocyclo.output ]]; then \
echo functions with gocyclo score higher than 15; \
cat /tmp/gocyclo.output | sed 's/^/ /'; \
false; \
fi
.PHONY: deps
deps: ## Install prerequisite for build
@echo "==> Installing prerequisite for build"
@go mod tidy
.PHONY: tools
tools: ## Install build tools
@echo "==> Installing build tools"
@(cd /tmp; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
go install github.com/jstemmer/go-junit-report/v2@latest; \
go install mvdan.cc/gofumpt@latest; \
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest; \
go install golang.org/x/tools/cmd/goimports@latest; \
)
.PHONY: build
build: deps ## Build locally for local os/arch creating $(BUILD_DIR) in ./
@echo "==> Building executable"
@mkdir -p $(BUILD_DIR)
@CGO_ENABLED=$(CGO_ENABLED) \
$(GO) build $(GOFLAGS) \
-ldflags '$(LDFLAGS)' \
-o $(BUILD_DIR) ./
.PHONY: clean
clean: ## Clean up the build dirs
@echo "==> Cleaning up build dirs"
@rm -rf $(BUILD_DIR) vendor .venv
.PHONY: docker-build
docker-build: ## Build docker image for local test
@echo "==> Building docker image"
@mkdir -p $(BUILD_DIR)/release/
@package/scripts/build-bin.sh
@sleep 2 # to address podman volume issue on MacOS
@docker build . -f package/container/Dockerfile -t parquet-tools:local
.PHONY: test
test: deps tools ## Run unit tests
@echo "==> Running unit tests"
@mkdir -p $(BUILD_DIR)/test
@set -euo pipefail ; \
cd $(BUILD_DIR)/test; \
CGO_ENABLED=1 go test -v -race -count 1 -trimpath \
-coverprofile=coverage.out $(CURDIR)/... \
| tee go-test.output ; \
go tool cover -html=coverage.out -o coverage.html ; \
go tool cover -func=coverage.out -o coverage.txt ; \
cat go-test.output | $(GOBIN)/go-junit-report > junit.xml ; \
cat coverage.txt
.PHONY: release-build
release-build: deps ## Build release binaries
@echo "==> Building release binaries"
@mkdir -p $(BUILD_DIR)/release/
@package/scripts/build-bin.sh
@echo "==> generate RPM and deb packages"
@package/scripts/build-rpm.sh
@package/scripts/build-deb.sh
@echo "==> generate build meta data"
@package/scripts/gen-meta.sh
@echo "==> release info"
@cat $(BUILD_DIR)/release/checksum-sha512.txt
@echo
@cat $(BUILD_DIR)/CHANGELOG
.PHONY: help
help: ## Print list of Makefile targets
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
cut -d ":" -f1- | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'