forked from stellar/wallet-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (136 loc) Β· 7.07 KB
/
Copy pathMakefile
File metadata and controls
159 lines (136 loc) Β· 7.07 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Prepend docker command with sudo if necessary.
SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo")
# Extract short commit hash from the current checked-out branch.
LABEL ?= $(shell git rev-parse --short HEAD)$(and $(shell git status -s),-dirty-$(shell id -u -n))
# When building the application for deployment, set the TAG parameter according to your organization's DockerHub repository.
TAG ?= stellar/wallet-backend:$(LABEL)
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
BUILD_DATE ?= $(shell date -u +%FT%TZ)
# Version of Stellar Core to be installed. Choose from jammy builds at https://apt.stellar.org/pool/stable/s/stellar-core/
STELLAR_CORE_VERSION ?= 21.0.0-1872.c6f474133.jammy
# ==================================================================================== #
# QUALITY & PREPARATION
# ==================================================================================== #
tidy: ## Tidy modfiles and format source files
@echo "==> Tidying module files..."
go mod tidy -v
@echo "==> Formatting code..."
go fmt ./...
@command -v $(shell go env GOPATH)/bin/gofumpt >/dev/null 2>&1 || { go install mvdan.cc/gofumpt@v0.9.2; }
$(shell go env GOPATH)/bin/gofumpt -l -w .
@echo "==> Fixing imports..."
@command -v $(shell go env GOPATH)/bin/goimports >/dev/null 2>&1 || { go install golang.org/x/tools/cmd/goimports@v0.43.0; }
@find . -type f -name "*.go" ! -path "*mock*" | xargs $(shell go env GOPATH)/bin/goimports -local "github.com/stellar/wallet-backend" -w
fmt: ## Check if code is formatted with gofmt
@echo "==> Checking formatting..."
@test -z $(shell gofmt -l .) || (echo "ERROR: Unformatted files found. Run 'make tidy' or 'gofmt -w .'"; exit 1)
@echo "Format check passed."
vet: ## Run go vet checks
@echo "==> Running go vet..."
go vet ./...
lint: ## Run golangci-lint linter (requires: brew install golangci-lint or equivalent)
@echo "==> Running golangci-lint..."
@command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "ERROR: golangci-lint not found. Install it: https://golangci-lint.run/usage/install/"; exit 1; }
golangci-lint run ./...
shadow: ## Run shadow analysis to find shadowed variables
@echo "==> Running shadow analyzer..."
@if ! command -v $(shell go env GOPATH)/bin/shadow >/dev/null 2>&1; then \
echo "Installing shadow..."; \
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@v0.43.0; \
fi
@$(shell go env GOPATH)/bin/shadow ./... | { grep -v "generated.go" || true; }
deadcode: ## Find unused code
@echo "==> Checking for deadcode..."
@if ! command -v $(shell go env GOPATH)/bin/deadcode >/dev/null 2>&1; then \
echo "Installing deadcode..."; \
go install golang.org/x/tools/cmd/deadcode@v0.43.0; \
fi
@output=$$($(shell go env GOPATH)/bin/deadcode -test ./... | grep -v "UnmarshalUInt32" | grep -v "isBalance"); \
if [ -n "$$output" ]; then \
echo "π¨ Deadcode found:"; \
echo "$$output"; \
exit 1; \
else \
echo "β
No deadcode found"; \
fi
fix-imports: ## Fix import formatting and organization
@echo "==> Fixing imports..."
@command -v $(shell go env GOPATH)/bin/goimports >/dev/null 2>&1 || { go install golang.org/x/tools/cmd/goimports@v0.43.0; }
@find . -type f -name "*.go" ! -path "*mock*" | xargs $(shell go env GOPATH)/bin/goimports -local "github.com/stellar/wallet-backend" -w
@echo "β
Imports fixed."
goimports: ## Check import formatting and organization
@echo "==> Checking imports..."
@command -v $(shell go env GOPATH)/bin/goimports >/dev/null 2>&1 || { go install golang.org/x/tools/cmd/goimports@v0.43.0; }
@non_compliant_files=$$(find . -type f -name "*.go" ! -path "*mock*" | xargs $(shell go env GOPATH)/bin/goimports -local "github.com/stellar/wallet-backend" -l); \
if [ -n "$$non_compliant_files" ]; then \
echo "π¨ The following files are not compliant with goimports:"; \
echo "$$non_compliant_files"; \
exit 1; \
else \
echo "β
All files are compliant with goimports."; \
fi
check: gql-validate tidy fmt vet lint shadow deadcode fix-imports ## Run all checks
@echo "β
All checks completed successfully"
# ==================================================================================== #
# GRAPHQL
# ==================================================================================== #
gql-generate: ## Generate GraphQL code using gqlgen
@echo "==> Generating GraphQL code..."
@command -v $(shell go env GOPATH)/bin/gqlgen >/dev/null 2>&1 || { go install github.com/99designs/gqlgen@v0.17.88; }
$(shell go env GOPATH)/bin/gqlgen generate
@echo "==> Normalizing imports on generated code..."
@command -v $(shell go env GOPATH)/bin/goimports >/dev/null 2>&1 || { go install golang.org/x/tools/cmd/goimports@v0.43.0; }
@find . -type f -name "*.go" ! -path "*mock*" | xargs $(shell go env GOPATH)/bin/goimports -local "github.com/stellar/wallet-backend" -w
@echo "β
GraphQL code generated successfully"
gql-validate: ## Validate GraphQL schema
@echo "==> Validating GraphQL schema..."
@command -v $(shell go env GOPATH)/bin/gqlgen >/dev/null 2>&1 || { go install github.com/99designs/gqlgen@v0.17.88; }
$(shell go env GOPATH)/bin/gqlgen validate
@echo "β
GraphQL schema is valid"
# ==================================================================================== #
# TESTING
# ==================================================================================== #
unit-test: ## Run unit tests
@echo "==> Running unit tests..."
ENABLE_INTEGRATION_TESTS=false go test -v -race ./...
build-integration-image: ## Build integration test Docker image with git commit tag
@echo "==> Building integration test image..."
@GIT_COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "latest"); \
IMAGE_TAG="wallet-backend:integration-test-$$GIT_COMMIT"; \
$(SUDO) docker build \
--file Dockerfile \
--tag "$$IMAGE_TAG" \
--build-arg GIT_COMMIT="$$GIT_COMMIT" \
.; \
echo "β
Built image: $$IMAGE_TAG"
rebuild-integration-image: ## Force rebuild integration test Docker image
@echo "==> Force rebuilding integration test image..."
@GIT_COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "latest"); \
IMAGE_TAG="wallet-backend:integration-test-$$GIT_COMMIT"; \
$(SUDO) docker build \
--file Dockerfile \
--no-cache \
--tag "$$IMAGE_TAG" \
--build-arg GIT_COMMIT="$$GIT_COMMIT" \
.; \
echo "β
Force rebuilt image: $$IMAGE_TAG"
integration-test: ## Run integration tests (auto-detects if rebuild needed)
@echo "==> Running integration tests..."
ENABLE_INTEGRATION_TESTS=true go test -v ./internal/integrationtests/... -timeout 30m
integration-test-clean: ## Force rebuild integration test image and run tests
@echo "==> Force rebuilding and running integration tests..."
FORCE_REBUILD=true ENABLE_INTEGRATION_TESTS=true go test -v ./internal/integrationtests/... -timeout 30m
docker-build:
$(SUDO) docker build \
--file Dockerfile \
--pull \
--label org.opencontainers.image.created="$(BUILD_DATE)" \
--tag $(TAG) \
--build-arg GIT_COMMIT=$(LABEL) \
--build-arg STELLAR_CORE_VERSION=$(STELLAR_CORE_VERSION) \
--platform linux/amd64 \
.
docker-push:
$(SUDO) docker push $(TAG)
go-install:
go install -ldflags "-X main.GitCommit=$(LABEL)" .