-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (53 loc) · 2.21 KB
/
Copy pathMakefile
File metadata and controls
67 lines (53 loc) · 2.21 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
.PHONY: test build clean run help docker-build docker-push
# Variables
BINARY_NAME=skillserver
DOCKER_IMAGE?=ghcr.io/$(shell git config --get remote.origin.url | sed 's/.*github.com[:/]\(.*\)\.git/\1/' | tr '[:upper:]' '[:lower:]')
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Build flags
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.GitCommit=$(GIT_COMMIT)"
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
test: ## Run all tests
@echo "Running tests..."
go test -v ./...
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
build: ## Build the binary
@echo "Building $(BINARY_NAME)..."
go build $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/skillserver
@echo "Binary built: bin/$(BINARY_NAME)"
clean: ## Clean build artifacts
@echo "Cleaning..."
rm -rf bin/
rm -f coverage.out coverage.html
go clean
run: build ## Build and run the application
./bin/$(BINARY_NAME)
docker-build: ## Build Docker image
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(VERSION) -t $(DOCKER_IMAGE):latest .
@echo "Docker image built: $(DOCKER_IMAGE):$(VERSION)"
docker-push: docker-build ## Build and push Docker image to GHCR
@echo "Pushing Docker image to GHCR..."
docker push $(DOCKER_IMAGE):$(VERSION)
docker push $(DOCKER_IMAGE):latest
@echo "Docker image pushed: $(DOCKER_IMAGE):$(VERSION)"
lint: ## Run linters
@echo "Running linters..."
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest" && exit 1)
golangci-lint run ./...
fmt: ## Format code
@echo "Formatting code..."
go fmt ./...
vet: ## Run go vet
@echo "Running go vet..."
go vet ./...
ci: test vet ## Run CI checks (tests and vet)