-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
76 lines (64 loc) · 2.25 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
#!make
#----------------------------------------
# Settings
#----------------------------------------
.DEFAULT_GOAL := help
#--------------------------------------------------
# Variables
#--------------------------------------------------
BINARY="slack"
TEST?=$$(go list ./...)
GO_FILES?=$$(find . -name '*.go')
NEW_VERSION ?= "0.2.0-pre-release"
LATEST_VERSION=$$(git describe --abbrev=0 --tags)
#--------------------------------------------------
# Targets
#--------------------------------------------------
.PHONY: bootstrap
bootstrap: ## Downloads and cleans up all dependencies
@go mod tidy
@go mod download
.PHONY: fmt
fmt: ## Formats go files
@echo "==> Formatting files..."
@gofmt -w -s $(GO_FILES)
@echo ""
.PHONY: check
check: ## Checks code for linting/construct errors
@echo "==> Checking if files are well formatted..."
@gofmt -l $(GO_FILES)
@echo ""
@echo "==> Checking if files pass go vet..."
@go list -f '{{.Dir}}' ./... | xargs go vet;
@echo ""
.PHONY: test
test: check ## Runs all tests
@echo "==> Running tests..."
@go test -v --race $(TEST) -parallel=20
@echo ""
.PHONY: coverage
coverage: ## Runs code coverage
@mkdir -p .target/coverage
@go test --p=1 $(TEST) -coverprofile=.target/coverage/cover.out -covermode=atomic
.PHONY: show-coverage
show-coverage: coverage ## Shows code coverage report in your web browser
@go tool cover -html=.target/coverage/cover.out
.PHONY: dev
dev: fmt check ## Builds a local dev version
@go build -ldflags "-X 'github.com/nszilard/slack/cmd.appVersion=${LATEST_VERSION}-dev'" -o .target/local/${BINARY}
@go install -ldflags "-X 'github.com/nszilard/slack/cmd.appVersion=${LATEST_VERSION}-dev'"
.PHONY: package
package: clean bootstrap check ## Builds a production version
@env GOOS=linux GOARCH=amd64 go build -ldflags "-X 'github.com/nszilard/slack/cmd.appVersion=${NEW_VERSION}'" -o .target/linux_amd64/${BINARY}
.PHONY: docs
docs: dev ## Generates markdown documentation
@.target/local/${BINARY} docs
.PHONY: clean
clean: ## Cleans up temporary and compiled files
@echo "==> Cleaning up ..."
@rm -rf .target
@echo " [✓]"
@echo ""
.PHONY: help
help: ## Shows available targets
@fgrep -h "## " $(MAKEFILE_LIST) | fgrep -v fgrep | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-13s\033[0m %s\n", $$1, $$2}'