-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (92 loc) · 3.28 KB
/
Makefile
File metadata and controls
111 lines (92 loc) · 3.28 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
99
100
101
102
103
104
105
106
107
108
109
110
# Variables
NAME := stopnik
VERSION ?= dev
GOOS ?= linux
GOARCH ?= amd64
GIT_HASH := $(shell git rev-parse --short=11 HEAD)
BIN_DIR := bin
BINARY_NAME := stopnik
MAIN_PATH := ./cmd/stopnik
# Default target
all: test lint
build-all: clean build-linux-intel build-linux-arm build-macos-intel build-macos-arm build-windows-intel build-windows-arm
build-ci: clean
@echo "Building CI"
ifeq ($(CI_OS),ubuntu-latest)
@$(MAKE) build-linux-intel
@$(MAKE) build-linux-arm
@$(MAKE) build-windows-intel
@$(MAKE) build-windows-arm
else ifeq ($(CI_OS),macos-latest)
@$(MAKE) build-macos-intel
@$(MAKE) build-macos-arm
else ifeq ($(CI_OS),windows-latest)
@$(MAKE) build-windows-intel
@$(MAKE) build-windows-arm
else
@echo "Could not detect build platform"
endif
build-windows-intel:
@$(MAKE) build GOOS=windows GOARCH=amd64 BINARY_NAME=stopnik.exe
build-windows-arm:
@$(MAKE) build GOOS=windows GOARCH=arm64 BINARY_NAME=stopnik.exe
build-linux-intel:
@$(MAKE) build GOOS=linux GOARCH=amd64
build-linux-arm:
@$(MAKE) build GOOS=linux GOARCH=arm64
build-macos-intel:
@$(MAKE) build GOOS=darwin GOARCH=amd64
build-macos-arm:
@$(MAKE) build GOOS=darwin GOARCH=arm64
# Build the application
build:
@echo "Building $(BINARY_NAME) version $(VERSION) ($(GIT_HASH)) for $(GOOS) $(GOARCH) into $(BIN_DIR)"
@mkdir -p $(BIN_DIR)/$(GOOS)/$(GOARCH)
@GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags="-s -w -X 'main.Version=$(VERSION)' -X 'main.GitHash=$(GIT_HASH)'" \
-o $(BIN_DIR)/$(GOOS)/$(GOARCH)/$(BINARY_NAME) $(MAIN_PATH)
@cd $(BIN_DIR)/$(GOOS)/$(GOARCH) && sha256sum $(BINARY_NAME) >> SHA256SUMS
@command -v zip >/dev/null 2>&1 && cd $(BIN_DIR)/$(GOOS)/$(GOARCH) && zip -q -r ../$(NAME).$(VERSION)-$(GOOS)-$(GOARCH).zip ./
lint: clean-lint
@echo "Linting"
@command -v golangci-lint >/dev/null 2>&1 && golangci-lint run || \
echo "golangci-lint not installed; skipping"
# Run tests
test:
@echo "Running tests"
go test ./...
test-ci:
@echo "Running tests for CI/CD"
go test ./... -json > testresults.json
# Clean build artifacts
clean:
@echo "Cleaning build artifacts"
@rm -rf $(BIN_DIR)
clean-test:
@echo "Cleaning test results"
@rm -f testresults.json
@rm -rf ./test_coverage
clean-lint:
@echo "Cleaning lint result"
@rm -rf .lint_result/
clean-all: clean clean-lint clean-test
# Show help
help:
@echo "Available targets:"
@echo " all Run tests and linting"
@echo " build Build for the current GOOS/GOARCH"
@echo " build-all Build binaries for all supported platforms"
@echo " build-ci Build the platform(s) for the current CI OS"
@echo " build-linux-intel Build linux/amd64"
@echo " build-linux-arm Build linux/arm64"
@echo " build-macos-intel Build darwin/amd64"
@echo " build-macos-arm Build darwin/arm64"
@echo " build-windows-intel Build windows/amd64"
@echo " build-windows-arm Build windows/arm64"
@echo " lint Run golangci-lint if installed"
@echo " test Run all Go tests"
@echo " test-ci Run tests and write testresults.json"
@echo " clean Remove build artifacts"
@echo " clean-test Remove test results and coverage output"
@echo " clean-lint Remove lint output"
@echo " clean-all Run clean, clean-lint, and clean-test"