-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (115 loc) · 5.19 KB
/
Makefile
File metadata and controls
142 lines (115 loc) · 5.19 KB
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
include version.mk
ARCH := $(shell arch)
ifeq ($(ARCH),x86_64)
ARCH = amd64
else
ifeq ($(ARCH),aarch64)
ARCH = arm64
endif
endif
GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/target
GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=1 GOARCH=$(ARCH)
GOBINARY := aggkit
GOCMD := $(GOBASE)/cmd
LDFLAGS += -X 'github.com/agglayer/aggkit.Version=$(VERSION)'
LDFLAGS += -X 'github.com/agglayer/aggkit.GitRev=$(GITREV)'
LDFLAGS += -X 'github.com/agglayer/aggkit.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/agglayer/aggkit.BuildDate=$(DATE)'
# Check dependencies
.PHONY: check-go
check-go: ## Check if golang is installed
@which go > /dev/null || (echo "Error: Go is not installed" && exit 1)
# Check for Docker
.PHONY: check-docker
check-docker: ## Check if docker is installed
@which docker > /dev/null || (echo "Error: docker is not installed" && exit 1)
# Check for Protoc
.PHONY: check-protoc
check-protoc: ## Check if protoc is installed
@which protoc > /dev/null || (echo "Error: protoc is not installed" && exit 1) || (echo "Please install protoc from https://grpc.io/docs/protoc-installation/" && exit 1)
@which protoc-gen-go > /dev/null || (echo "Error: protoc-gen-go is not installed. Run: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest" && exit 1)
@which protoc-gen-go-grpc > /dev/null || (echo "Error: protoc-gen-go-grpc is not installed. Run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest" && exit 1)
@which buf > /dev/null || (echo "Error: buf is not installed. Please install it from https://docs.buf.build/installation" && exit 1)
# Check for Curl
.PHONY: check-curl
check-curl: ## Check if curl is installed
@which curl > /dev/null || (echo "Error: curl is not installed" && exit 1)
# Check for Golangci-lint
.PHONY: check-golangci-lint
check-golangci-lint:
@which golangci-lint > /dev/null || (echo "Error: golangci-lint is not installed. Please install it: https://github.com/golangci/golangci-lint" && exit 1)
# Check for Swag
.PHONY: check-swag
check-swag:
@command -v swag >/dev/null 2>&1 || { \
echo >&2 "Error: swag not installed. Please install it: https://github.com/swaggo/swag"; \
exit 1; \
}
# Targets that require the checks
build: check-go
lint: check-go check-golangci-lint
build-docker: check-docker
build-docker-nc: check-docker
generate-swagger-docs: check-swag
generate-code-from-proto: check-protoc
.PHONY: generate-code-from-proto
generate-code-from-proto: check-protoc ## Generate Go code from proto files in-place
buf dep update
buf generate
.PHONY: build ## Builds the binaries locally into ./target
build: build-aggkit build-tools
.PHONY: build-aggkit
build-aggkit: ## Builds aggkit binary
GIN_MODE=release $(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/$(GOBINARY) $(GOCMD)
.PHONY: build-tools
build-tools: $(GOBIN)/aggsender_find_imported_bridge $(GOBIN)/remove_ger ## Builds the tools
$(GOBIN)/aggsender_find_imported_bridge: ## Build aggsender_find_imported_bridge tool
$(GOENVVARS) go build -o $(GOBIN)/aggsender_find_imported_bridge ./tools/aggsender_find_imported_bridge
$(GOBIN)/remove_ger: ## Build remove_ger tool
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/remove_ger ./tools/remove_ger/cmd
.PHONY: build-docker
build-docker: ## Builds a docker image with the aggkit binary
docker build -t aggkit:local -f ./Dockerfile .
.PHONY: build-docker-ci
build-docker-ci: ## Builds a docker image with the aggkit binary for CI (includes shell)
docker build --build-arg INCLUDE_SHELL=true -t aggkit:local -f ./Dockerfile .
.PHONY: build-docker-nc
build-docker-nc: ## Builds a docker image with the aggkit binary - but without build cache
docker build --no-cache=true -t aggkit:local -f ./Dockerfile .
.PHONY: test-unit
test-unit: ## Runs the unit tests
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=coverage.out -timeout 15m ./...
.PHONY: test-e2e
test-e2e: ## Runs the e2e tests
go test -v -timeout 30m ./test/e2e/...
.PHONY: lint
lint: ## Runs the linter
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/golangci-lint run --timeout 5m
.PHONY: generate-swagger-docs
generate-swagger-docs: ## Generates the swagger docs
@echo "Generating swagger docs"
@swag init -g bridgeservice/bridge.go -o bridgeservice/docs
@mkdir -p docs/assets/swagger/bridge_service
@cp bridgeservice/docs/swagger.json docs/assets/swagger/bridge_service/swagger.json
@echo "Copied swagger.json to docs/assets/swagger/bridge_service/"
.PHONY: vulncheck
vulncheck: ## Runs the vulnerability checker tool
@command -v govulncheck >/dev/null 2>&1 || { \
echo "govulncheck is not installed. Please run: go install golang.org/x/vuln/cmd/govulncheck@latest"; \
exit 1; \
}
@echo "Running govulncheck on all packages..."
@go list ./... | xargs -n1 govulncheck
.PHONY: generate-mocks
generate-mocks: ## Generates the mocks using mockery
@cd test && $(MAKE) generate-mocks
## Help display.
## Pulls comments from beside commands and prints a nicely formatted
## display with the commands and their usage information.
.DEFAULT_GOAL := help
.PHONY: help
help: ## Prints this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'