/
Makefile
74 lines (55 loc) · 3.51 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
BUILD_DATE := `date -u +%Y%m%d`
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo v0.0.1)
GIT_SHA := $(shell git rev-parse HEAD)
APP_NAME := have-want-bot
REPL_NAME := have-want-repl
DUMP_NAME := have-want-dump
PROJECT := github.com/gsmcwhirter/discord-have-want-bot
SERVER := discordbot@evogames.org:~/eso-discord/
CONF_FILE := ./have-want-config.toml
SERVICE_FILE := ./eso-have-want-bot.service
INSTALLER := ./have-want-install.sh
# can specify V=1 on the line with `make` to get verbose output
V ?= 0
Q = $(if $(filter 1,$V),,@)
.DEFAULT_GOAL := help
build-debug: version generate
$Q go build -v -ldflags "-X main.AppName=$(APP_NAME) -X main.BuildVersion=$(VERSION) -X main.BuildSHA=$(GIT_SHA) -X main.BuildDate=$(BUILD_DATE)" -o bin/$(APP_NAME) -race $(PROJECT)/cmd/$(APP_NAME)
$Q go build -v -ldflags "-X main.AppName=$(REPL_NAME) -X main.BuildVersion=$(VERSION) -X main.BuildSHA=$(GIT_SHA) -X main.BuildDate=$(BUILD_DATE)" -o bin/$(REPL_NAME) -race $(PROJECT)/cmd/$(REPL_NAME)
$Q go build -v -ldflags "-X main.AppName=$(DUMP_NAME) -X main.BuildVersion=$(VERSION) -X main.BuildSHA=$(GIT_SHA) -X main.BuildDate=$(BUILD_DATE)" -o bin/$(DUMP_NAME) -race $(PROJECT)/cmd/$(DUMP_NAME)
build-release: version generate
$Q GOOS=linux go build -v -ldflags "-s -w -X main.AppName=$(APP_NAME) -X main.BuildVersion=$(VERSION) -X main.BuildSHA=$(GIT_SHA) -X main.BuildDate=$(BUILD_DATE)" -o bin/$(APP_NAME) $(PROJECT)/cmd/$(APP_NAME)
$Q GOOS=linux go build -v -ldflags "-s -w -X main.AppName=$(REPL_NAME) -X main.BuildVersion=$(VERSION) -X main.BuildSHA=$(GIT_SHA) -X main.BuildDate=$(BUILD_DATE)" -o bin/$(REPL_NAME) $(PROJECT)/cmd/$(REPL_NAME)
$Q GOOS=linux go build -v -ldflags "-s -w -X main.AppName=$(DUMP_NAME) -X main.BuildVersion=$(VERSION) -X main.BuildSHA=$(GIT_SHA) -X main.BuildDate=$(BUILD_DATE)" -o bin/$(DUMP_NAME) $(PROJECT)/cmd/$(DUMP_NAME)
generate: ## run a go generate
$Q go generate ./...
build-release-bundles: build-release
$Q gzip -k -f bin/$(APP_NAME)
$Q cp bin/$(APP_NAME).gz bin/$(APP_NAME)-$(VERSION).gz
$Q gzip -k -f bin/$(REPL_NAME)
$Q cp bin/$(REPL_NAME).gz bin/$(REPL_NAME)-$(VERSION).gz
$Q gzip -k -f bin/$(DUMP_NAME)
$Q cp bin/$(DUMP_NAME).gz bin/$(DUMP_NAME)-$(VERSION).gz
clean: ## Remove compiled artifacts
$Q rm bin/*
debug: generate test build-debug ## Debug build: create a dev build (enable race detection, don't strip symbols)
release: generate test build-release-bundles ## Release build: create a release build (disable race detection, strip symbols)
deps: ## Download dependencies
$Q go get ./...
test: ## Run the tests
$Q go test -cover ./...
version: ## Print the version string and git sha that would be recorded if a release was built now
$Q echo $(VERSION) $(GIT_SHA)
vet: ## Run the linter
$Q golint ./...
$Q go vet ./...
$Q gometalinter -D gas -D gocyclo -D goconst -e .pb.go -e _easyjson.go --warn-unmatched-nolint --enable-gc --deadline 180s ./...
release-upload: release upload
setup: deps generate ## attempt to get everything set up to do a build (deps and generate)
upload:
$Q scp $(CONF_FILE) $(SERVICE_FILE) $(INSTALLER) $(SERVER)
$Q scp ./bin/$(APP_NAME).gz ./bin/$(APP_NAME)-$(VERSION).gz $(SERVER)
$Q scp ./bin/$(REPL_NAME).gz ./bin/$(REPL_NAME)-$(VERSION).gz $(SERVER)
$Q scp ./bin/$(DUMP_NAME).gz ./bin/$(DUMP_NAME)-$(VERSION).gz $(SERVER)
help: ## Show the help message
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' ./Makefile