-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMakefile
More file actions
97 lines (77 loc) · 2.77 KB
/
Makefile
File metadata and controls
97 lines (77 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Directory of Makefile
export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GINKGO?="github.com/onsi/ginkgo/v2/ginkgo"
BUILD_DIR?=./build
PKG?=./pkg/... ./internal/...
COVER_PKG?=github.com/suse/elemental/...
INTEG_PKG?=./tests/integration/...
GO_MODULE?=$(shell go list -m)
# Exclude files in ./tests folder
GO_FILES=$(shell find ./ -path ./tests -prune -o -name '*.go' -not -name '*_test.go' -print)
GO_FILES+=./go.mod
GO_FILES+=./go.sum
GIT_COMMIT?=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD)
GIT_TAG?=$(shell git describe --candidates=50 --abbrev=0 --tags 2>/dev/null || echo "v0.0.1" )
VERSION?=$(GIT_TAG)-g$(GIT_COMMIT_SHORT)
LDFLAGS:=-w -s
LDFLAGS+=-X "$(GO_MODULE)/internal/cli/cmd.version=$(GIT_TAG)"
LDFLAGS+=-X "$(GO_MODULE)/internal/cli/cmd.gitCommit=$(GIT_COMMIT)"
GO_BUILD_ARGS?=-ldflags '$(LDFLAGS)'
# Used to build the OS image
DOCKER?=docker
ELEMENTAL_IMAGE_REPO?=local/elemental-image
ifdef PLATFORM
ARCH=$(subst linux/,,$(PLATFORM))
else
ARCH?=$(shell uname -m)
endif
PLATFORM?=linux/$(ARCH)
# Use vendor directory if it exists
ifneq (,$(wildcard ./vendor))
GO_BUILD_ARGS+=-mod=vendor
endif
ifneq (,$(GO_EXTRA_ARGS))
GO_BUILD_ARGS+=$(GO_EXTRA_ARGS)
endif
# No verbose unit tests by default
ifneq (,$(VERBOSE))
GO_RUN_ARGS+=-v
endif
# Include tests Makefile only if explicitly set
ifneq (,$(INTEGRATION_TESTS))
include tests/Makefile
endif
# Default target
.PHONY: all
all: $(BUILD_DIR)/elemental3 $(BUILD_DIR)/elemental3ctl
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/elemental3: $(GO_FILES)
go build $(GO_BUILD_ARGS) -o $@ ./cmd/elemental
$(BUILD_DIR)/elemental3ctl: $(GO_FILES)
go build $(GO_BUILD_ARGS) -o $@ ./cmd/elemental3ctl
.PHONY: image
image: VALID_RUNNERS := runner-elemental3 runner-elemental3ctl
image:
$(if $(filter $(RUNNER),$(VALID_RUNNERS)),,\
$(error Invalid RUNNER '$(RUNNER)'. Must be one of: $(VALID_RUNNERS)))
$(DOCKER) build --platform $(PLATFORM) --target $(RUNNER) --tag $(ELEMENTAL_IMAGE_REPO):$(VERSION) .
.PHONY: unit-tests
unit-tests:
go run $(GINKGO) --label-filter '!rootlesskit' --race --cover --coverpkg=$(COVER_PKG) --github-output -p -r $(GO_RUN_ARGS) ${PKG} || exit $$?
ifeq (, $(shell which rootlesskit 2>/dev/null))
@echo "No rootlesskit utility found, not executing tests requiring it"
else
@mv coverprofile.out coverprofile.out.bk
rootlesskit go run $(GINKGO) --label-filter 'rootlesskit' --race --cover --coverpkg=$(COVER_PKG) --github-output -p -r $(GO_RUN_ARGS) ${PKG} || exit $$?
@grep -v "mode: atomic" coverprofile.out >> coverprofile.out.bk
@mv coverprofile.out.bk coverprofile.out
endif
.PHONY: clean
clean:
@rm -rfv $(BUILD_DIR)
@find . -type f -executable -name '*.test' -exec rm -f {} \+
.PHONY: lint
lint:
@golangci-lint run -c $(ROOT_DIR)/.golangci.yml