-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (56 loc) · 1.76 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
69
70
# Name of the binary
BINARY_NAME=ayo
# Output directory for the build
BUILD_DIR=dist
# Coverage file name
COVERAGE_FILE=$(BUILD_DIR)/coverage.out
project_version := $(shell git describe --tags --always)
git_commit := $(shell git rev-parse --verify HEAD)
date := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
author := $(USER)
LDFLAGS := -s -w
LDFLAGS += -X 'github.com/banst/ayo/cmd/ayo/config.Version=$(project_version)'
LDFLAGS += -X 'github.com/banst/ayo/cmd/ayo/config.Commit=$(git_commit)'
LDFLAGS += -X 'github.com/banst/ayo/cmd/ayo/config.Date=$(date)'
LDFLAGS += -X 'github.com/banst/ayo/cmd/ayo/config.BuiltBy=$(author)'
# Default target
.PHONY: all
all: build
# Build the Go project
.PHONY: build
build-go: ## Build the Go project
@mkdir -p $(BUILD_DIR)
go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/ayo
# Build the Documentation
.PHONY: build-docs
build-docs: ## Build the Documentation
mdbook build -d ../$(BUILD_DIR)/docs docs/
# Build the project
.PHONY: build
build: build-go build-docs ## Build the project
# Run the Go project
.PHONY: run
run: build-go ## Build and run the Go project
./$(BUILD_DIR)/$(BINARY_NAME)
# Clean up the build artifacts
.PHONY: clean
clean: ## Clean up build artifacts
@if [ -d $(BUILD_DIR) ]; then rm -r $(BUILD_DIR); fi
# Run tests with coverage
.PHONY: test
test: ## Run tests with coverage
@mkdir -p $(BUILD_DIR)
go test ./... -coverprofile=$(COVERAGE_FILE)
go tool cover -func=$(COVERAGE_FILE)
# Format the code
.PHONY: fmt
fmt: ## Format the code
go fmt ./...
# Lint the code
.PHONY: lint
lint: ## Lint the code
golangci-lint run
# Display help
.PHONY: help
help: ## Show help
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'