-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
116 lines (96 loc) · 3.15 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
.SILENT:
SHELL = /bin/bash
.DEFAULT_GOAL := help
COLOR_RESET = \033[0m
COLOR_COMMAND = \033[36m
COLOR_YELLOW = \033[33m
COLOR_GREEN = \033[32m
COLOR_RED = \033[31m
TAG := `git describe --tags`
DATE := `date -u +"%Y-%m-%dT%H:%M:%SZ"`
COMMIT := ""
LDFLAGS := -X main.version=$(TAG) -X main.commit=$(COMMIT) -X main.date=$(DATE)
GITHUB_TOKEN := $(shell git config --get github.releases-token || echo $$GITHUB_TOKEN)
PROJECT := statiks
SOURCE_FILES?=$$(go list ./... | grep -v /vendor/)
## Run project http
run:
@go run cmd/statiks.go
## Run project https
runs:
@go run main.go -s
## Runs the project unit tests
test:
@go test -timeout 10s -v -covermode atomic -cover -coverprofile coverage.out $(SOURCE_FILES)
@go vet . 2>&1 | grep -v '^vendor\/' | grep -v '^exit\ status\ 1' || true
## Run all the tests and opens the coverage report
test-cover: test
go tool cover -html=coverage.out
@rm coverage.out 2>/dev/null || true
## Run all the tests and code checks
test-ci: lint test
## Setup of the project
setup:
@go mod verify
@brew install goreleaser/tap/goreleaser
lint:
@echo "*** Start lint ***"
@script -q /dev/null golangci-lint run --enable-all -D gochecknoglobals,lll,wsl,maligned,nlreturn --print-issued-lines=false --out-format=colored-line-number | awk '{print $0; count++} END {print "\nCount: " count}'
@echo "*** Finish ***"
git-tag:
@printf "\n"; \
read -p "Tag ($(TAG)): "; \
if [ ! "$$REPLY" ]; then \
printf "\n${COLOR_RED}"; \
echo "Invalid tag."; \
exit 1; \
fi; \
TAG=$$REPLY; \
sed -i.bak "s/download\/[^/]*/download\/$$TAG/g" README.md && \
sed -i.bak "s/statiks_[^_]*/statiks_$$TAG/g" README.md && \
rm README.md.bak 2>/dev/null; \
git commit README.md -m "Update README.md with release $$TAG"; \
git tag -s $$TAG -m "$$TAG"; \
git push origin $$TAG; \
git push origin master; \
## Build project
build:
echo "Building $(PROJECT)"
go build -ldflags "$(LDFLAGS) -w -s" -o $(PROJECT) main.go
## Build Docker Image (uses docker multi-stage builds)
docker:
echo "Building Docker Image of $(PROJECT)"
docker build --target release -t $(PROJECT) .
## Run minimal demo from Docker Image (uses docker multi-stage builds)
docker_demo:
docker build --target demo -t $(PROJECT):demo .
docker run --rm -it -p 9080:9080 $(PROJECT):demo
## Release of the project
release: git-tag
@if [ ! "$(GITHUB_TOKEN)" ]; then \
echo "github token should be configurated."; \
exit 1; \
fi; \
export GITHUB_TOKEN=$(GITHUB_TOKEN); \
goreleaser release --rm-dist; \
echo "Release - OK"
push-release:
export GITHUB_TOKEN=$(GITHUB_TOKEN); \
goreleaser release --rm-dist --skip-validate
## Check release
check-release:
export GITHUB_TOKEN=$(GITHUB_TOKEN); \
goreleaser release --skip-publish --rm-dist --skip-validate
## Prints this help
help:
printf "${COLOR_YELLOW}${PROJECT}\n------\n${COLOR_RESET}"
awk '/^[a-zA-Z\-\_0-9\.%]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf "${COLOR_COMMAND}$$ make %s${COLOR_RESET} %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort
printf "\n"