-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
73 lines (58 loc) · 2.07 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
NAME = harmonia
VERSION = 0.0.1
# Included as relative path because of compile step, if not Go will look in GOROOT
SRC_DIR = ./src
BIN_DIR = bin
ENV := $(if $(ENV),$(ENV),dev)
####### GO TARGETS ########
.PHONY: swag compile run godoc test tidy
# Constructs bin/ directory for holding compiled binaries
$(BIN_DIR):
mkdir $(BIN_DIR)
# Builds out swagger documentation and outputs the specs to the docs/ directory
swag:
go install github.com/swaggo/swag/cmd/[email protected]
# --parseDependency, --parseInternal and --parseDepth are being used here to parse definitions outside of main package
swag init -d $(SRC_DIR)/main --parseDependency --parseDepth 1 -g server.go -o $(SRC_DIR)/main/docs
# Compiles build of the src/main Go application and outputs binary to the bin/ directory
# Compiles with different flags depending on environment
# This is dependent on the swagger documentation and bin/ directory being present
compile: swag $(BIN_DIR)
ifneq ($(ENV), prod)
@echo "compiling non-release build"
go build -gcflags=all="-N -l" -ldflags "-X main.harmoniaVersion=$(VERSION)" -o $(BIN_DIR)/$(NAME) $(SRC_DIR)/main
else
@echo "compiling release build"
go build -ldflags "-X main.harmoniaVersion=$(VERSION)" -o $(BIN_DIR)/$(NAME) $(SRC_DIR)/main
endif
# Runs the compiled version of the Go application located in the bin/ directory
run:
./$(BIN_DIR)/$(NAME)
# Serves Go documentation for the Go application based on docs
godoc:
godoc -http=:6060
# Runs Go application tests
test: swag
go test ./...
# Cleans up Go application dependencies
tidy:
go mod tidy
# Lints source code
lint: swag
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint run
####### MISCELLANEOUS TARGETS ########
.PHONY: local get-version get-tag get-name clean
# Entrypoint to setting up local environment configuration
local:
@sh local.sh
# Outputs application version - used by Jenkins primarily for building and tagging image
get-version:
@echo -n $(VERSION)
# Outputs app name
get-name:
@echo -n $(NAME)
# Cleans up artifacts
clean:
rm -rf $(BIN_DIR)
rm -rf $(SRC_DIR)/main/docs