-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
179 lines (157 loc) · 5.33 KB
/
Makefile
File metadata and controls
179 lines (157 loc) · 5.33 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
.PHONY: help build build-local test test-local test-coverage test-integration run clean docker-build docker-run docker-clean fmt vet lint ci-test test-ci-local watch-ci
# Docker image settings
DOCKER_IMAGE := recal
DOCKER_TAG := latest
BUILDER_IMAGE := golang:1.24-alpine
# Binary name and location
BINARY := bin/recal
# Default target
help:
@echo "Available targets:"
@echo " build - Build the binary using Docker (reproducible)"
@echo " build-local - Build the binary using local Go (faster, less reproducible)"
@echo " test - Run all tests using Docker (reproducible)"
@echo " test-local - Run all tests using local Go (faster)"
@echo " test-coverage - Run tests with coverage report"
@echo " test-integration - Run integration tests against live server"
@echo " test-ci-local - Run CI integration tests locally (before pushing)"
@echo " run - Run the application using Docker"
@echo " clean - Remove build artifacts"
@echo " docker-build - Build Docker image"
@echo " docker-run - Run Docker container"
@echo " docker-clean - Remove Docker images"
@echo " fmt - Format code using Docker"
@echo " vet - Run go vet using Docker"
@echo " lint - Run golangci-lint using Docker"
@echo " ci-test - Run CI test suite (used by GitHub Actions)"
@echo " watch-ci - Watch CI build and auto-download logs on failure"
@echo " dev - Quick dev cycle: test-local + build-local"
# Build the binary using Docker for reproducibility
build:
@echo "Building binary using Docker (reproducible build)..."
@mkdir -p bin
@docker run --rm \
-v "$(PWD):/workspace" \
-w /workspace \
$(BUILDER_IMAGE) \
sh -c 'apk add --no-cache git && go build -buildvcs=false -ldflags="-w -s" -trimpath -o $(BINARY) ./cmd/recal'
@echo "Build complete: ./$(BINARY)"
# Build locally (faster but less reproducible)
build-local:
@echo "Building binary using local Go..."
@mkdir -p bin
go build -buildvcs=false -o $(BINARY) ./cmd/recal
# Run tests using Docker
test:
@echo "Running all tests using Docker..."
@docker run --rm \
-v "$(PWD):/workspace" \
-w /workspace \
$(BUILDER_IMAGE) \
sh -c 'apk add --no-cache git && go test -v ./...'
@echo ""
@echo "✓ All unit and integration tests passed!"
@echo ""
@echo "Test summary:"
@docker run --rm \
-v "$(PWD):/workspace" \
-w /workspace \
$(BUILDER_IMAGE) \
sh -c 'go test ./... 2>&1 | grep -E "^(ok|FAIL|\?)"'
# Run tests locally (faster)
test-local:
@echo "Running all tests locally..."
go test -v ./...
@echo ""
@echo "✓ All unit and integration tests passed!"
@echo ""
@echo "Test summary:"
@go test ./... 2>&1 | grep -E "^(ok|FAIL|\?)"
# Run the application using Docker
run: docker-build
@echo "Starting application in Docker..."
docker run --rm -p 8080:8080 $(DOCKER_IMAGE):$(DOCKER_TAG)
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf bin/
rm -f ical-filter ical-proxy-filter recal
docker rmi $(DOCKER_IMAGE):$(DOCKER_TAG) 2>/dev/null || true
docker rmi $(DOCKER_IMAGE):builder 2>/dev/null || true
# Build Docker image
docker-build:
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
# Run Docker container
docker-run:
@echo "Running Docker container..."
docker run --rm -p 8080:8080 --name $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG)
# Remove Docker images
docker-clean:
@echo "Removing Docker images..."
docker rmi $(DOCKER_IMAGE):$(DOCKER_TAG) || true
# Format code using Docker
fmt:
@echo "Formatting code using Docker..."
@docker run --rm \
-v "$(PWD):/workspace" \
-w /workspace \
$(BUILDER_IMAGE) \
sh -c 'go fmt ./...'
# Run go vet using Docker
vet:
@echo "Running go vet using Docker..."
@docker run --rm \
-v "$(PWD):/workspace" \
-w /workspace \
$(BUILDER_IMAGE) \
sh -c 'go vet ./...'
# Run golangci-lint using Docker
lint:
@echo "Running golangci-lint using Docker..."
@docker run --rm \
-v "$(PWD):/workspace" \
-w /workspace \
golangci/golangci-lint:latest \
golangci-lint run -v
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage using Docker..."
@docker run --rm \
-v "$(PWD):/workspace" \
-w /workspace \
$(BUILDER_IMAGE) \
sh -c 'apk add --no-cache git && go test -v -coverprofile=coverage.out ./... && go tool cover -func=coverage.out'
# Run integration tests against a live server
# Usage: make test-integration (assumes server running on localhost:8080)
# Or: make test-integration BASE_URL=http://myserver:8080
test-integration:
@echo "Running integration tests..."
@if [ ! -f ./test-server.sh ]; then \
echo "Error: test-server.sh not found"; \
exit 1; \
fi
@chmod +x ./test-server.sh
@./test-server.sh $(BASE_URL)
# CI test target (for GitHub Actions)
ci-test: test
@echo ""
@echo "✓ CI tests passed!"
# Development helpers
.PHONY: dev-setup
dev-setup:
@echo "Setting up development environment..."
@echo "Installing git hooks..."
@mkdir -p .git/hooks
@echo "Development environment ready!"
# Quick dev cycle: test + build
.PHONY: dev
dev: test-local build-local
@echo "Development build complete!"
# Run local CI integration tests (mimics GitHub Actions)
test-ci-local:
@echo "Running local CI integration tests..."
@./test-local.sh
# Watch GitHub Actions CI and auto-download logs on failure
watch-ci:
@./watch-ci.sh