forked from open-edge-platform/geti
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.shared-go
More file actions
82 lines (64 loc) · 2.77 KB
/
Makefile.shared-go
File metadata and controls
82 lines (64 loc) · 2.77 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
# Copyright (C) 2022-2025 Intel Corporation
# LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
CWD = $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
include $(CWD)/Makefile.shared
.PHONY: build deps clean tests test-unit-default test-integration-default coverage static-code-analysis-default lint lint-install mocks mocks-install
GOPATH ?= $(HOME)/go
GOBIN ?= $(GOPATH)/bin
GOLANGCI_LINT_VERSION = v2.1.6
MOCKERY_VERSION = v3.2.5
TIMEOUT = 15m
# Go commands
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOOS ?= linux
CGO_ENABLED ?= 0
GO_BUILD_FLAGS ?= -trimpath -mod=readonly -gcflags="all=-spectre=all" -asmflags="all=-spectre=all" -ldflags="all=-s -w" -a
OUTPUT_BINARY ?= service
CLEAN_DIRS := \
$(OUTPUT_BINARY) coverage.out
deps: ## Clean up and verify modules
$(GOCMD) mod tidy
build-default: ## Build the Go binary
GOOS=$(GOOS) CGO_ENABLED=$(CGO_ENABLED) $(GOBUILD) $(GO_BUILD_FLAGS) -o $(OUTPUT_BINARY) .
tests: test-unit test-integration
test-unit-default: ## Run unit tests
$(GOTEST) -v -race -short ./...
test-integration-default: ## Run integration tests (requires -tags=integration in code)
$(GOTEST) -v -race -tags=integration ./...
coverage: ## Run tests and generate a coverage profile
$(GOTEST) -coverprofile=coverage.out ./...
@echo "Coverage report generated at coverage.out"
## Run static analysis/linters in read-only mode (e.g., for CI checks).
## This will fail on lint errors but won't modify any files.
static-code-analysis-default: lint-install
$(GOBIN)/golangci-lint run --timeout $(TIMEOUT)
## Run linter in "fix" mode to automatically correct code where possible.
## Generally used locally to clean up code before committing.
lint: lint-install
$(GOBIN)/golangci-lint run --fix --timeout $(TIMEOUT)
lint-install:
@if ! command -v $(GOBIN)/golangci-lint >/dev/null 2>&1 || [ "v$$($(GOBIN)/golangci-lint version --short)" != "$(GOLANGCI_LINT_VERSION)" ]; then \
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VERSION); \
echo "golangci-lint $(GOLANGCI_LINT_VERSION) installed at $(GOBIN)/golangci-lint"; \
else \
echo "golangci-lint $(GOLANGCI_LINT_VERSION) is already installed"; \
fi
## Generate mocks for interfaces
mocks: mocks-install
@echo "Generating mocks..."
$(GOBIN)/mockery
mocks-install:
@if ! command -v $(GOBIN)/mockery >/dev/null 2>&1; then \
echo "Installing mockery $(MOCKERY_VERSION)..."; \
go install github.com/vektra/mockery/v3@$(MOCKERY_VERSION); \
echo "mockery $(MOCKERY_VERSION) installed at $(GOBIN)/mockery"; \
else \
echo "mockery $(MOCKERY_VERSION) is already installed"; \
fi
##
# Builder container image
##
BUILDER_IMAGE ?= go-builder