-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
155 lines (132 loc) · 4.35 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
.PHONY: build run test clean fmt vet lint docker docker-run env-test check-env
APP_NAME=siprec-server
GO_FILES=$(shell find . -name "*.go" -type f -not -path "./vendor/*")
GO_PACKAGES=$(shell go list ./...)
MAIN_PACKAGE=./cmd/siprec
# Default target
all: build
# Build the application
build:
@echo "Building $(APP_NAME)..."
@go build -o $(APP_NAME) $(MAIN_PACKAGE)
# Run the application
run:
@echo "Running $(APP_NAME)..."
@go run $(MAIN_PACKAGE)
# Run the environment test
env-test:
@echo "Testing environment variables..."
@go test ./test -run TestEnvironmentLoading
# Run tests
test:
@echo "Running tests..."
@go test -v $(GO_PACKAGES)
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
@go test -coverprofile=coverage.out $(GO_PACKAGES)
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated at coverage.html"
# Run specific package tests
test-package:
@echo "Usage: make test-package PKG=./pkg/stt"
@if [ "$(PKG)" != "" ]; then \
echo "Running tests for $(PKG)..."; \
go test -v $(PKG); \
fi
# Run end-to-end tests
test-e2e:
@echo "Running end-to-end tests..."
@go test -v ./test/e2e
# Run specific end-to-end test
test-e2e-case:
@echo "Usage: make test-e2e-case TEST=TestSiprecCallFlow"
@if [ "$(TEST)" != "" ]; then \
echo "Running end-to-end test $(TEST)..."; \
go test -v ./test/e2e -run $(TEST); \
fi
# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -f $(APP_NAME)
@rm -rf ./recordings/*.wav
@rm -f coverage.out coverage.html
# Format code
fmt:
@echo "Formatting code..."
@go fmt $(GO_PACKAGES)
# Run go vet
vet:
@echo "Vetting code..."
@go vet $(GO_PACKAGES)
# Run golint if available
lint:
@if command -v golint >/dev/null 2>&1; then \
echo "Linting code..."; \
golint -set_exit_status $(GO_PACKAGES); \
else \
echo "golint not installed. Installing..."; \
go install golang.org/x/lint/golint@latest; \
echo "Linting code..."; \
golint -set_exit_status $(GO_PACKAGES); \
fi
# Check for required environment variables
check-env:
@echo "Checking for required environment variables..."
@if [ ! -f .env ]; then \
echo "Error: .env file not found"; \
echo "Please copy .env.example to .env and configure it"; \
exit 1; \
fi
@echo "Environment configuration OK"
# Ensure recordings directory exists
ensure-dirs:
@echo "Ensuring required directories exist..."
@mkdir -p recordings
@mkdir -p certs
@echo "Directories OK"
# Build Docker image
docker:
@echo "Building Docker image..."
@docker build -t $(APP_NAME) .
# Run Docker container
docker-run:
@echo "Running Docker container..."
@docker run -p 5060:5060/udp -p 5060:5060/tcp -p 8080:8080 --name $(APP_NAME) $(APP_NAME)
# Start all services with docker-compose
docker-up:
@echo "Starting all services with docker-compose..."
@docker-compose up -d
# Stop all services with docker-compose
docker-down:
@echo "Stopping all services with docker-compose..."
@docker-compose down
# View logs from docker-compose services
docker-logs:
@echo "Viewing logs from all services..."
@docker-compose logs -f
# Complete setup (build everything and check environment)
setup: check-env ensure-dirs build
# Help
help:
@echo "Available targets:"
@echo " build - Build the application"
@echo " run - Run the application locally"
@echo " env-test - Test the environment configuration"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " test-package - Run tests for a specific package (e.g., make test-package PKG=./pkg/stt)"
@echo " test-e2e - Run end-to-end tests"
@echo " test-e2e-case - Run a specific end-to-end test (e.g., make test-e2e-case TEST=TestSiprecCallFlow)"
@echo " clean - Remove build artifacts"
@echo " fmt - Format code with go fmt"
@echo " vet - Run go vet"
@echo " lint - Run golint"
@echo " check-env - Check for required environment variables"
@echo " ensure-dirs - Ensure required directories exist"
@echo " docker - Build Docker image"
@echo " docker-run - Run Docker container"
@echo " docker-up - Start all services with docker-compose"
@echo " docker-down - Stop all services with docker-compose"
@echo " docker-logs - View logs from docker-compose services"
@echo " setup - Complete setup (environment check and build)"