-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (53 loc) · 1.51 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
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOINSTALL=$(GOCMD) install
BINARY_NAME=restmigrate
BINARY_UNIX=$(BINARY_NAME)_unix
MAIN_PATH=./cmd/restmigrate
VERSION := 0.1.0-dev
COMMIT := $(shell git rev-parse HEAD)
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Build the project
all: test build
build:
$(GOBUILD) -ldflags="-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.Date=$(DATE)" -o $(BINARY_NAME) -v $(MAIN_PATH)
# Test the project
test:
$(GOTEST) -v ./...
# Clean build files
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)
# Run the application
run:
$(GOBUILD) -o $(BINARY_NAME) -v $(MAIN_PATH)
./$(BINARY_NAME)
# Cross compilation for Linux
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v $(MAIN_PATH)
# Install dependencies
deps:
$(GOGET) -v -t ./...
# Format all Go files
fmt:
$(GOCMD) fmt ./...
# Run golangci-lint
lint:
golangci-lint run
# Generate test coverage report
coverage:
$(GOTEST) -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out
# Build for multiple platforms
release:
GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
# Install the binary locally
install:
$(GOINSTALL) $(MAIN_PATH)
.PHONY: all build test clean run build-linux deps fmt lint coverage release install