forked from chikamif/go-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
142 lines (112 loc) · 4.85 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
GO=$(shell which go)
.PHONY: clean test coverage coverage-html fmt fmt-check vet lint staticcheck swagger-build swagger-view start re-start
help:
@echo "Test/check:"
@echo " make test - Run tests"
@echo " make coverage - Run tests and show coverage"
@echo " make coverage-html - Run tests and show coverage (as HTML)"
@echo " make coverage-upload - Upload coverage results to codecov.io"
@echo
@echo "Lint/format:"
@echo " make fmt - Run 'go fmt'"
@echo " make fmt-check - Run 'go fmt', but don't change anything"
@echo " make vet - Run 'go vet'"
@echo " make lint - Run 'golint'"
@echo " make staticcheck - Run 'staticcheck'"
@echo
@echo "Build:"
@echo " make build - Build"
@echo " make build-snapshot - Build snapshot"
@echo " make build-simple - Build (using go build, without goreleaser)"
@echo " make clean - Clean build folder"
@echo
@echo "Swagger:"
@echo " make swagger-build - Builds the swagger API docs in swagger.yml"
@echo " make swagger-view - Starts the swagger server to view the swagger docs"
@echo
@echo "Source Code Documentation"
@echo " make godoc - Builds the source code documentation and serves it on port 6060"
@echo
@echo "Docker:"
@echo " make start - Starts the App in docker with the env file .env.local"
@echo " make re-start - Rebuilds the App and starts it in docker with the env file .env.local."
@echo " make up - Starts the App in docker"
@echo " make re-up - Rebuilds the App and starts it in docker."
@echo " make watch - Watch source files and rebuild/restart app on changes."
# Additional golang or third-party tools are required for some commands.
# These will be installed on-demand.
golint:
which golint || ($(GO) get golang.org/x/lint/golint && $(GO) mod tidy)
golangci-lint:
which golangci-lint || ($(GO) get github.com/golangci/golangci-lint/cmd/golangci-lint@latest && $(GO) mod tidy)
# Test/check targets
check: test fmt-check vet lint staticcheck
test:
$(GO) test ./...
coverage:
mkdir -p build/coverage
$(GO) test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic ./...
$(GO) tool cover -func build/coverage/coverage.txt
coverage-html:
mkdir -p build/coverage
$(GO) test -race -coverprofile=build/coverage/coverage.txt -covermode=atomic ./...
$(GO) tool cover -html build/coverage/coverage.txt
# Lint/formatting targets
fmt:
$(GO) fmt ./...
fmt-check:
test -z "$(shell gofmt -l .)"
vet:
$(GO) vet ./...
# https://github.com/golangci/golangci-lint
lint: golangci-lint
golangci-lint run -c .golangci.yml
# https://github.com/golang/lint
# Note: The use of `EXIT` below ensures that BOTH commands run,
# but the job will fail as a whole if EITHER command exits with an error code.
lint-full: golint golangci-lint
$(GO) list ./... | grep -Ev '/(vendor|docs)/' | xargs -L1 golint -set_exit_status; EXIT=$$?; \
golangci-lint run -c .golangci-optional.yml && [[ $$EXIT == 0 ]]; echo $$EXIT;
staticcheck:
which staticcheck || ($(GO) get honnef.co/go/tools/cmd/staticcheck && $(GO) mod tidy)
rm -rf build/staticcheck
mkdir -p build/staticcheck
ln -s "$(GO)" build/staticcheck/go
PATH="$(PWD)/build/staticcheck:$(PATH)" staticcheck ./...
rm -rf build/staticcheck
# Building targets
build: clean
$(eval VERSION = "$(shell ./get_version.sh)")
@echo Building Version:$(VERSION) with $(shell $(GO) version)
mkdir -p bin/
$(GO) get -d -v ./...
$(GO) build -o bin/app -v ./main.go
git restore version/version.go
clean:
rm -rf bin build
# Swagger commands
swagger-build:
which swagger || ($(GO) get github.com/go-swagger/go-swagger/cmd/swagger && $(GO) mod tidy)
mkdir -p build/swagger
swagger generate spec -o ./build/swagger/provisioner.yaml --scan-models
swagger generate markdown --spec=./build/swagger/provisioner.yaml --output=./build/swagger/provisioner.md
swagger-view: swagger-build
swagger serve -F=swagger ./build/swagger/provisioner.yaml
# Go Source-Code Documentation
godoc:
which godoc || { $(GO) get -v golang.org/x/tools/cmd/godoc && $(GO) mod tidy; }
godoc -http=:6060 -index
# Docker commands
up:
docker-compose up --build
re-up:
docker-compose up --build --force-recreate
start:
docker-compose --env-file .env.local up --build
re-start restart:
docker-compose --env-file .env.local up --build --force-recreate
watch:
which watcher || { $(GO) get -u github.com/radovskyb/watcher/... && $(GO) mod tidy; }
watcher --cmd="$(MAKE) re-start" --ignore bin,assets,.git --startcmd
# Deploy Targets
# TODO: needs to be added with https://jira.datto.net/browse/BFYLEGO-8361