-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (115 loc) · 4.16 KB
/
Makefile
File metadata and controls
139 lines (115 loc) · 4.16 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Copyright (c) 2026 Itential, Inc
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Make configuration
SHELL := /bin/bash
.DEFAULT_GOAL := help
.SHELLFLAGS := -eu -o pipefail -c
# Go build configuration
# Note: CGO_ENABLED is set to 0 by default for static builds, but is temporarily
# enabled for race detector tests which require it
export CGO_ENABLED := 0
# Go tools
GO := go
GOFMT := gofmt
GOLINT := golangci-lint
# Build metadata
GIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.1.0")
LDFLAGS := -X 'github.com/itential/igsdk.Version=$(VERSION)' \
-X 'github.com/itential/igsdk.Build=$(GIT_SHA)'
# Directories and files
COVER_DIR := cover
COVERAGE_OUT := coverage.out
COVERAGE_TXT := coverage.txt
# Test configuration
PKG := ./...
TEST_CACHE ?= enabled
CACHE_FLAG := $(if $(filter-out enabled,$(TEST_CACHE)),-count=1,)
# Phony targets
.PHONY: help config clean ci test test-race coverage \
fmt vet lint tidy verify tools
##@ General
help: ## Display this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} \
/^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
config: ## Display the build configuration
@echo "Build Configuration:"
@echo " VERSION = $(VERSION)"
@echo " GIT_SHA = $(GIT_SHA)"
@echo " CGO_ENABLED = $(CGO_ENABLED)"
@echo ""
@echo "Go Configuration:"
@echo " GO = $(GO)"
@echo " GOFMT = $(GOFMT)"
@echo ""
@echo "Linker Flags:"
@echo " LDFLAGS = $(LDFLAGS)"
##@ Development
fmt: ## Format all Go files
@echo "Formatting Go files..."
@$(GOFMT) -w .
@echo "Formatting complete"
vet: ## Run go vet
@echo "Running go vet..."
@$(GO) vet $(PKG)
@echo "Vet complete"
lint: ## Run golangci-lint (requires golangci-lint installed)
@echo "Running golangci-lint..."
@if command -v $(GOLINT) >/dev/null 2>&1; then \
$(GOLINT) run $(PKG); \
echo "Lint complete"; \
else \
echo "Error: golangci-lint not found. Install with:"; \
echo " curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin"; \
exit 1; \
fi
tidy: ## Run go mod tidy
@echo "Running go mod tidy..."
@$(GO) mod tidy
@echo "Tidy complete"
verify: ## Verify dependencies
@echo "Verifying dependencies..."
@$(GO) mod verify
@echo "Verification complete"
tools: ## Install development tools (golangci-lint)
@echo "Installing development tools..."
@if ! command -v $(GOLINT) >/dev/null 2>&1; then \
echo "Installing golangci-lint..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin; \
else \
echo "golangci-lint already installed"; \
fi
@echo "Tools installation complete"
clean: ## Clean build artifacts and coverage files
@echo "Cleaning build artifacts..."
@rm -rf $(COVER_DIR) $(COVERAGE_OUT) $(COVERAGE_TXT)
@$(GO) clean -cache -testcache
@echo "Clean complete"
##@ Testing
test: ## Run all tests
@echo "Running tests..."
@$(GO) test $(CACHE_FLAG) $(PKG)
@echo "Tests complete"
test-race: ## Run tests with race detector
@echo "Running tests with race detector..."
@CGO_ENABLED=1 $(GO) test -race $(CACHE_FLAG) $(PKG)
@echo "Race detector tests complete"
coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
@mkdir -p $(COVER_DIR)
@$(GO) test -cover $(CACHE_FLAG) $(PKG)
@echo ""
@echo "Generating coverage profile..."
@$(GO) test -coverprofile=$(COVERAGE_OUT) $(CACHE_FLAG) $(PKG)
@$(GO) tool cover -func=$(COVERAGE_OUT)
@# Generate coverage.txt artifact for CI
@if [ -f $(COVERAGE_OUT) ]; then \
total=$$($(GO) tool cover -func=$(COVERAGE_OUT) | grep total | awk '{print $$3}'); \
echo "Total coverage: $$total" | tee $(COVERAGE_TXT); \
fi
##@ CI/CD
ci: fmt vet test-race coverage ## Run all CI checks (fmt, vet, test-race, coverage)
@echo ""
@echo "✓ All CI checks passed!"