-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
78 lines (62 loc) · 2.34 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
# System Setup
SHELL=bash
# Go Stuff
GOCMD=go
GOLINTCMD=golint
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOLIST=$(GOCMD) list
GOVET=$(GOCMD) vet
GOTEST=$(GOCMD) test -v ./...
GOFMT=$(GOCMD) fmt
CGO_ENABLED ?= 0
GOOS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
# General Vars
APP := $(shell basename $(PWD) | tr '[:upper:]' '[:lower:]')
GIT_COMMIT_HASH ?= $(shell git rev-parse --short HEAD)
BUILD_VERSION := dev-$(GIT_COMMIT_HASH)
DEPLOY_VERSION := $(shell echo $${GITHUB_REF/refs\/tags\//})
.PHONY: all
all: test build
.PHONY: build
build: ## Build the project
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) $(GOBUILD) -ldflags "-X github.com/gomicro/probe/cmd.Version=$(BUILD_VERSION) -s -w" -o $(APP) .
.PHONY: clean
clean: ## Clean out all generated files
-@$(GOCLEAN)
.PHONY: coverage
coverage: ## Generates the total code coverage of the project
@$(eval COVERAGE_DIR=$(shell mktemp -d))
@mkdir -p $(COVERAGE_DIR)/tmp
@for j in $$(go list ./... | grep -v '/vendor/' | grep -v '/ext/'); do go test -covermode=count -coverprofile=$(COVERAGE_DIR)/$$(basename $$j).out $$j > /dev/null 2>&1; done
@echo 'mode: count' > $(COVERAGE_DIR)/tmp/full.out
@tail -q -n +2 $(COVERAGE_DIR)/*.out >> $(COVERAGE_DIR)/tmp/full.out
@$(GOCMD) tool cover -func=$(COVERAGE_DIR)/tmp/full.out | tail -n 1 | sed -e 's/^.*statements)[[:space:]]*//' -e 's/%//'
.PHONY: deploy
deploy: ## Deploy the artifacts
@echo "Logging into Docker Hub"
-@echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
@VERSION=$(DEPLOY_VERSION) goreleaser release
.PHONY: help
help: ## Show This Help
@for line in $$(cat Makefile | grep "##" | grep -v "grep" | sed "s/:.*##/:/g" | sed "s/\ /!/g"); do verb=$$(echo $$line | cut -d ":" -f 1); desc=$$(echo $$line | cut -d ":" -f 2 | sed "s/!/\ /g"); printf "%-30s--%s\n" "$$verb" "$$desc"; done
.PHONY: install
install: ## Installs the binary
$(GOCMD) install
.PHONY: test
test: unit_test ## Runs all available tests
.PHONY: unit_test
unit_test: ## Run unit tests
$(GOTEST)
.PHONY: fmt
fmt: ## Run gofmt
@echo "checking formatting..."
@$(GOFMT) $(shell $(GOLIST) ./... | grep -v '/vendor/')
.PHONY: vet
vet: ## Run go vet
@echo "vetting..."
@$(GOVET) $(shell $(GOLIST) ./... | grep -v '/vendor/')
.PHONY: lint
lint: ## Run golint
@echo "linting..."
@$(GOLINTCMD) -set_exit_status $(shell $(GOLIST) ./... | grep -v '/vendor/')