Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (105 loc) · 3.42 KB
/
Copy pathMakefile
File metadata and controls
125 lines (105 loc) · 3.42 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
# Makefile for Session Service (Janus)
.PHONY: all build build-all test clean run install-deps proto
# Variables
GO?=go
GO_BIN?=app
BINARY_PATH?=bin/$(GO_BIN)
BINARY_ARCHS?=amd64 arm64 riscv64
CMD_PATH=./cmd/sts
PROTO_PATH=api/proto/v1
CGO_ENABLED?=0
GOOS?=$(shell $(GO) env GOOS)
GOARCH?=$(shell $(GO) env GOARCH)
GO_TEST_PARALLEL?=10
# Podman support - set DOCKER_HOST for testcontainers
# Usage: make test DOCKER_HOST=unix://$${XDG_RUNTIME_DIR}/podman/podman.sock
DOCKER_HOST?=
# Default target
all: build
# Install Go dependencies
install-deps:
go mod download
go mod tidy
$(GO) mod download
$(GO) mod tidy
# Mock generation - install mockgen and generate all mocks
mocks: vendor
$(GO) install go.uber.org/mock/mockgen@latest
# Generate all mocks via go:generate directives
$(GO) generate ./...
.PHONY: mocks
# Run tests with coverage and parallelization (max 10 concurrent tests)
test: mocks vet
@if [ -n "$(DOCKER_HOST)" ]; then \
echo "Using DOCKER_HOST=$(DOCKER_HOST)"; \
export DOCKER_HOST=$(DOCKER_HOST); \
fi; \
$(GO) test -v -p $(GO_TEST_PARALLEL) ./... -cover -coverprofile coverage_source.out
# Generate JSON output for CI/CD
@if [ -n "$(DOCKER_HOST)" ]; then export DOCKER_HOST=$(DOCKER_HOST); fi; \
$(GO) test -v -p $(GO_TEST_PARALLEL) ./... -cover -coverprofile coverage_source.out -json > test_source.json
# Filter out mock files from coverage
cat coverage_source.out | grep -v "mock_*" | tee coverage.out
cat test_source.json | grep -v "mock_*" | tee test.json
.PHONY: test
# Run tests with short flag (skips long-running tests, max 10 concurrent)
test-short: mocks vet
@if [ -n "$(DOCKER_HOST)" ]; then export DOCKER_HOST=$(DOCKER_HOST); fi; \
$(GO) test -v -p $(GO_TEST_PARALLEL) ./... -short -cover
.PHONY: test-short
# Run integration tests with parallelization (requires Docker/Podman)
test-integration: mocks
@if [ -n "$(DOCKER_HOST)" ]; then export DOCKER_HOST=$(DOCKER_HOST); fi; \
$(GO) test -v -p $(GO_TEST_PARALLEL) ./internal/auth ./internal/session ./internal/db -cover
.PHONY: test-integration
# Vet code
vet:
$(GO) vet ./...
.PHONY: vet
# Vendor dependencies
vendor:
$(GO) mod vendor
.PHONY: vendor
govulncheck: vendor
$(GO) install golang.org/x/vuln/cmd/govulncheck@latest
PATH="$$($(GO) env GOPATH)/bin:$$PATH" govulncheck ./...
.PHONY: govulncheck
# Build the binary
build:
@echo "Building $(GO_BIN) ($(GOOS)/$(GOARCH))..."
@mkdir -p bin
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build -o $(BINARY_PATH) $(CMD_PATH)
@echo "Build complete: $(BINARY_PATH)"
.PHONY: build
# Build binaries for all supported architectures (amd64, arm64, riscv64)
build-all:
@mkdir -p bin
@for arch in $(BINARY_ARCHS); do \
echo "Building $(GO_BIN) (linux/$$arch)..."; \
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$$arch $(GO) build -o bin/$(GO_BIN)-linux-$$arch $(CMD_PATH) || exit 1; \
echo "Build complete: bin/$(GO_BIN)-linux-$$arch"; \
done
.PHONY: build-all
# Run the service
run: build
./$(BINARY_PATH) serve
# Clean build artifacts
clean:
@echo "Cleaning..."
rm -rf bin/
rm -f coverage.out coverage.html
rm -rf keys/
@echo "Clean complete"
# Generate protobuf code (requires protoc)
proto:
@echo "Generating protobuf code..."
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
$(PROTO_PATH)/sts.proto
@echo "Protobuf generation complete"
# Format code
fmt:
go fmt ./...
# Lint code (requires golangci-lint)
lint:
golangci-lint run