-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
179 lines (131 loc) · 4.62 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
.PHONY: clean distclean fmt tidy vendor proto proto-doc mock dev test testlib btcd build-itest lib-utest lib-itest testbackend lint all
TARGET := c13n
MODULE_NAME = github.com/c13n-io/c13n-go
SHELL = /bin/bash
include make/release_flags.mk
SERVICE_DIR = rpc/services
PROTO_IMPORT_PATHS := --proto_path=. --proto_path=vendor
GO = go
GOBUILD := go build -v
GOINSTALL := go install
############
# Packages #
############
BTCD_PKG := github.com/btcsuite/btcd
LND_PKG := github.com/lightningnetwork/lnd
# Backend Packages
BACKEND_PACKAGES := $(shell go list ./... | grep -vE "lnchat")
# Library packages
LNCHAT_PKG := github.com/c13n-io/c13n-go/lnchat
LNCONNECT_PKG := github.com/c13n-io/c13n-go/lnchat/lnconnect
C13N_PACKAGES := $(BACKEND_PACKAGES) $(LNCHAT_PKG) $(LNCONNECT_PKG)
#############
# Artifacts #
#############
# Backend certificates
CERT_DIR = cert
# Documentation
RPC_DOCS_FILE = index.md
############
# Testing #
###########
# Integration testing
## Integration test flags
ITEST_TAGS := dev rpctest chainrpc walletrpc signrpc invoicesrpc autopilotrpc routerrpc watchtowerrpc wtclientrpc btcd
## Packages to include in coverage reports, comma separated
ITEST_COVERAGE_PKGS := $(LNCHAT_PKG),$(LNCONNECT_PKG)
# Test artifacts
## Test output logs regex
TEST_OUTPUT_LOGS := lnchat/tests/*.log
## Test output logs regex
TEST_HARNESS_LOGS := lnchat/tests/.backendlogs lnchat/tests/.minerlogs
## Coverage output file
COVERAGE_OUTPUT := lnchat/tests/coverage.out
## LND test executable
LND_TEST_EXEC := lnchat/tests/lnd-itest
## LNCLI test executable
LNCLI_TEST_EXEC := lnchat/tests/lncli-itest
############
# Targets #
###########
all: $(TARGET)
dev: proto mock tidy
COMMIT := $(shell git describe --abbrev=40 --dirty)
COMMIT_HASH := $(shell git rev-parse HEAD)
LDFLAGSBASE := -X $(MODULE_NAME)/app.commit=$(COMMIT) \
-X $(MODULE_NAME)/app.commitHash=$(COMMIT_HASH)
LDFLAGS := -ldflags="$(LDFLAGSBASE)"
RELEASE_LDFLAGS := -s -w -buildid= $(LDFLAGSBASE)
$(TARGET):
$(GOBUILD) -o $(TARGET) $(LDFLAGS) $(MODULE_NAME)/cli
release:
./scripts/release.sh build-release "$(BUILD_SYSTEM)" "$(RELEASE_LDFLAGS)" $(MODULE_NAME)/cli
certgen:
openssl req -nodes -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -config $(CERT_DIR)/cert.conf -extensions v3_exts -days 365 -keyout $(CERT_DIR)/c13n.key -out $(CERT_DIR)/c13n.pem
# Formatting
fmt:
goimports -e -w -local $(MODULE_NAME) .
tidy: fmt
$(GO) mod tidy
# Building
# https://stepan.wtf/importing-protobuf-with-go-modules/
vendor:
go mod vendor
dev-deps:
$(GOINSTALL) google.golang.org/protobuf/cmd/[email protected]
$(GOINSTALL) google.golang.org/grpc/cmd/[email protected]
$(GOINSTALL) github.com/mwitkow/go-proto-validators/[email protected]
$(GOINSTALL) github.com/pseudomuto/protoc-gen-doc/cmd/[email protected]
$(GOINSTALL) github.com/vektra/mockery/[email protected]
$(GOINSTALL) golang.org/x/tools/cmd/goimports@latest
$(GOINSTALL) github.com/golangci/golangci-lint/cmd/[email protected]
# Generate protobuf source code
# http://github.com/golang/protobuf
proto: vendor
protoc $(PROTO_IMPORT_PATHS) \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
--govalidators_out=. --govalidators_opt=paths=source_relative \
$(SERVICE_DIR)/*.proto
# Generating
mock:
$(GO) generate ./...
proto-doc: vendor
protoc $(PROTO_IMPORT_PATHS) --doc_out=./docs/c13n-api-docs/docs --doc_opt=./docs/md.template,$(RPC_DOCS_FILE) $(SERVICE_DIR)/*.proto
# Testing
test: testlib testbackend
testbackend:
@echo "Executing backend tests"
$(GO) test -count=1 $(BACKEND_PACKAGES)
testlib: build-itest lib-utest lib-itest
build-itest:
@echo "Building itest lnd and lncli."
$(GOBUILD) -mod=mod -tags="$(ITEST_TAGS)" -o ./lnchat/tests/lnd-itest $(LND_PKG)/cmd/lnd
$(GOBUILD) -mod=mod -tags="$(ITEST_TAGS)" -o ./lnchat/tests/lncli-itest $(LND_PKG)/cmd/lncli
lib-itest:
@echo "Running integration tests with btcd backend."
$(RM) ./lnchat/tests/*.log
$(GO) test -v -coverprofile=lnchat/tests/coverage.out -coverpkg=$(ITEST_COVERAGE_PKGS) ./lnchat/tests -tags="$(ITEST_TAGS)" -logoutput
lib-utest:
@echo "Running lnchat unit tests."
$(GO) test -count=1 $(LNCHAT_PKG)
# Linting
lint:
@echo "Running linters"
golangci-lint run ./...
# Cleaning
clean:
$(RM) $(TARGET)
# Remove lnd and lncli executables
$(RM) $(LND_TEST_EXEC) $(LNCLI_TEST_EXEC)
# Remove logs from btcd, lnd-itest, lncli-itest
$(RM) $(TEST_OUTPUT_LOGS)
# Remove harness logs
$(RM) -r $(TEST_HARNESS_LOGS)
# Remove go test coverage output
$(RM) $(COVERAGE_OUTPUT)
distclean: clean
$(RM) -r vendor/
$(RM) $(CERT_DIR)/c13n.pem $(CERT_DIR)/c13n.key
$(RM) docs/$(RPC_DOCS_FILE)
$(RM) -r c13n-build/