Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
73 lines (62 loc) · 1.9 KB
/
Copy pathMakefile
File metadata and controls
73 lines (62 loc) · 1.9 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
# Variables
BINARY_NAME=lsweb
VERSION=$(shell git describe --tags --always --dirty)
BUILD_DIR=dist
COVERAGE_DIR=coverage
# Default target
all: deps test build
# Fetch all dependencies
deps:
@echo "Fetching dependencies..."
go mod tidy
go mod download
# Build the project using goreleaser
build: deps
@echo "Building $(BINARY_NAME) version $(VERSION) using goreleaser..."
goreleaser build --snapshot --clean
# Format all Go files
fmt:
@echo "Formatting all Go files..."
go fmt ./...
# Run tests
test: fmt
@echo "Running tests..."
go test -v ./...
# Run tests with coverage
cover: fmt
@echo "Running tests with coverage..."
mkdir -p $(COVERAGE_DIR)
go test -v -coverprofile=$(COVERAGE_DIR)/coverage.out ./...
go tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@echo "Coverage report generated in $(COVERAGE_DIR)/coverage.html"
# Lint code
lint: fmt
@echo "Linting code..."
go vet ./...
# Clean up
clean:
@echo "Cleaning up..."
rm -rf $(BUILD_DIR) $(COVERAGE_DIR)
go clean
# Install goreleaser if not installed
install-goreleaser:
ifeq (, $(shell which goreleaser))
@echo "Installing goreleaser..."
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
else
@echo "goreleaser is already installed"
endif
# Help
help:
@echo "Available targets:"
@echo " all (default) - Fetch dependencies, run tests, and build the project"
@echo " deps - Fetch all dependencies"
@echo " build - Build the project using goreleaser"
@echo " fmt - Format all Go files"
@echo " test - Run tests"
@echo " cover - Run tests with coverage"
@echo " lint - Lint code with go vet"
@echo " clean - Clean up"
@echo " install-goreleaser - Install goreleaser if not installed"
@echo " help - Display this help"
.PHONY: all deps build fmt test cover lint clean install-goreleaser help