-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
98 lines (81 loc) · 2.71 KB
/
Makefile
File metadata and controls
98 lines (81 loc) · 2.71 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
.PHONY: build test lint clean install run fmt tidy coverage setup pre-commit
# Build variables
BINARY_NAME=azswitch
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT_SHA?=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS=-ldflags "-s -w -X github.com/l2D/azswitch/internal/version.Version=$(VERSION) -X github.com/l2D/azswitch/internal/version.CommitSHA=$(COMMIT_SHA) -X github.com/l2D/azswitch/internal/version.BuildTime=$(BUILD_TIME)"
# Go commands
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOFMT=$(GOCMD) fmt
GOMOD=$(GOCMD) mod
# Default target
all: lint test build
# Build the binary
build:
@mkdir -p bin
$(GOBUILD) $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/azswitch
# Build for all platforms
build-all:
@mkdir -p dist
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-amd64 ./cmd/azswitch
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-arm64 ./cmd/azswitch
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-amd64 ./cmd/azswitch
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-arm64 ./cmd/azswitch
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-windows-amd64.exe ./cmd/azswitch
# Run tests
test:
$(GOTEST) -v -race ./...
# Run tests with coverage
coverage:
@mkdir -p coverage
$(GOTEST) -v -race -coverprofile=coverage/coverage.out -covermode=atomic ./...
$(GOCMD) tool cover -html=coverage/coverage.out -o coverage/coverage.html
# Run linter
lint:
golangci-lint run ./...
# Format code
fmt:
$(GOFMT) ./...
# Tidy dependencies
tidy:
$(GOMOD) tidy
# Install the binary
install: build
cp bin/$(BINARY_NAME) $(GOPATH)/bin/
# Run the application
run: build
./bin/$(BINARY_NAME)
# Clean build artifacts
clean:
rm -rf bin/
rm -rf dist/
rm -rf coverage/
# Development: run with live reload (requires air)
dev:
air
# Setup pre-commit hooks
setup:
pre-commit install
# Run pre-commit on all files
pre-commit:
pre-commit run --all-files
# Help
help:
@echo "Available targets:"
@echo " build - Build the binary"
@echo " build-all - Build for all platforms"
@echo " test - Run tests"
@echo " coverage - Run tests with coverage report"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " tidy - Tidy dependencies"
@echo " install - Install binary to GOPATH/bin"
@echo " run - Build and run"
@echo " clean - Remove build artifacts"
@echo " dev - Run with live reload (requires air)"
@echo " setup - Install pre-commit hooks"
@echo " pre-commit - Run pre-commit on all files"