-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
73 lines (64 loc) · 2.08 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
71
72
# Variables
APP_NAME := atcg
SRC_DIR := ./cmd/atcg
BUILD_DIR := ./bin
ANSIBLE_DIR := ./tasks
GOFLAGS := -v
PLATFORMS := linux/amd64 linux/arm64 windows/amd64 windows/arm64 darwin/amd64 darwin/arm64
OUTPUT_DIR := build
VERSION := $(shell git describe --tags --always --dirty)
COMMIT := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
# Default target is to build the app
.PHONY: all
all: clean build
# Build target
.PHONY: build
build:
@echo "Building the application..."
@mkdir -p $(BUILD_DIR)
mkdir -p $(OUTPUT_DIR)
for platform in $(PLATFORMS); do \
EXT=""; \
if [ $${platform%/*} = "windows" ]; then EXT=".exe"; fi; \
GOOS=$${platform%/*} GOARCH=$${platform#*/} go build -ldflags="-X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.buildDate=$(BUILD_DATE)'" -o $(OUTPUT_DIR)/$(APP_NAME)-$${platform%/*}-$${platform#*/}$$EXT $(SRC_DIR); \
done
# Clean target to remove build artifacts and the tasks directory
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
@if [ -d $(BUILD_DIR) ]; then rm -vrf $(BUILD_DIR); fi
@if [ -d $(ANSIBLE_DIR) ]; then rm -vrf $(ANSIBLE_DIR); fi
@if [ -d $(OUTPUT_DIR) ]; then rm -vrf $(OUTPUT_DIR); fi
# Run target to run the built binary
.PHONY: run
run: build
@echo "Running the application..."
$(BUILD_DIR)/$(APP_NAME)
# Test target to run unit tests
.PHONY: test
test:
@echo "Running tests..."
gotestsum --format=short-verbose --junitfile=unit-test-report.xml ./...
# Lint target to check code with golangci-lint
.PHONY: lint
lint:
@echo "Linting code..."
@golangci-lint run ./...
# Format target to ensure code style
.PHONY: fmt
fmt:
@echo "Formatting code..."
@go fmt ./...
# Help target to list available commands
.PHONY: help
help:
@echo "Makefile targets:"
@echo " all - Build the application (default)."
@echo " build - Build the application."
@echo " clean - Clean the build artifacts and tasks directory."
@echo " run - Run the application."
@echo " test - Run tests."
@echo " lint - Run linter."
@echo " fmt - Format code."
@echo " help - Show this help message."