generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
142 lines (115 loc) · 5.29 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
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
140
141
142
# Copyright (c) 2024, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
include make/quality.mk
GOPATH ?= $(shell go env GOPATH)
CATALOG_REPO=https://github.com/oracle-cne/catalog.git
MAKEFILE_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
INFO_DIR:=github.com/oracle-cne/ocne/cmd/info
CLONE_DIR:=${MAKEFILE_DIR}/temp-clone-dir
BUILD_DIR:=build
OUT_DIR:=out
PLATFORM_OUT_DIR:=$(OUT_DIR)/$(shell go env GOOS)_$(shell go env GOARCH)
PLATFORM_INSTRUMENTED_OUT_DIR:=$(OUT_DIR)/$(shell go env GOOS)_$(shell go env GOARCH)_instrumented
CHART_BUILD_DIR:=$(BUILD_DIR)/catalog
CHART_BUILD_OUT_DIR:=$(CHART_BUILD_DIR)/repo
CHART_GIT_DIR:=build/charts
CHART_EMBED:=pkg/catalog/embedded/charts
CATALOG_BRANCH?=release/2.0
TEST_PATTERN:=.*
TEST_FILTERS:=
TEST_DIR:=$(OUT_DIR)/tests
BATS_RESULT_DIR:=$(MAKEFILE_DIR)/$(TEST_DIR)/results
GOCOVERDIR:=$(MAKEFILE_DIR)/$(TEST_DIR)/coverage_raw
MERGED_COVER_DIR:=$(MAKEFILE_DIR)/$(TEST_DIR)/coverage_merged
CODE_COVERAGE:=$(TEST_DIR)/coverage
NAME:=ocne
GIT_COMMIT:=$(shell git rev-parse HEAD)
BUILD_DATE:=$(shell date +"%Y-%m-%dT%H:%M:%SZ")
CLI_VERSION:=$(shell grep Version: ${MAKEFILE_DIR}/buildrpm/ocne.spec | cut -d ' ' -f 2)-$(shell grep Release: ${MAKEFILE_DIR}/buildrpm/ocne.spec | cut -d ' ' -f 2 | cut -d '%' -f 1)
OS:=$(shell uname)
ifeq ($(OS), Linux)
CLI_VERSION=$(shell rpmspec -q --queryformat='%{VERSION}-%{RELEASE}' ${MAKEFILE_DIR}/buildrpm/ocne.spec)
endif
ifndef RELEASE_BRANCH
RELEASE_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
endif
DIST_DIR:=dist
ENV_NAME=ocne
GO=GO111MODULE=on GOPRIVATE=github.com/oracle-cne/ocne go
CLI_GO_LDFLAGS=-X '${INFO_DIR}.gitCommit=${GIT_COMMIT}' -X '${INFO_DIR}.buildDate=${BUILD_DATE}' -X '${INFO_DIR}.cliVersion=${CLI_VERSION}'
export GOCOVERDIR
export BATS_RESULT_DIR
#
# CLI
#
.DEFAULT_GOAL := help
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: run
run:
$(GO) run -trimpath -ldflags "${CLI_GO_LDFLAGS}" ./...
#
# Go build related tasks
#
$(BUILD_DIR) \
$(PLATFORM_OUT_DIR) \
$(PLATFORM_INSTRUMENTED_OUT_DIR) :
mkdir -p $@
$(CHART_EMBED): $(CHART_BUILD_OUT_DIR)
mkdir -p $@
cp $(CHART_BUILD_OUT_DIR)/* $@
$(CHART_BUILD_DIR): $(BUILD_DIR)
git clone -b ${CATALOG_BRANCH} $(CATALOG_REPO) $@
$(CHART_BUILD_OUT_DIR): $(CHART_BUILD_DIR)
cd $< && make
.PHONY: build-cli
build-cli: $(CHART_EMBED) $(PLATFORM_OUT_DIR) ## Build CLI for the current system and architecture
$(GO) build -trimpath -ldflags "${CLI_GO_LDFLAGS}" -o $(OUT_DIR)/$(shell go env GOOS)_$(shell go env GOARCH) ./...
# Build an instrumented CLI for the current system and architecture
build-cli-instrumented: $(CHART_EMBED) $(PLATFORM_INSTRUMENTED_OUT_DIR)
$(GO) build -cover -trimpath -ldflags "${CLI_GO_LDFLAGS}" -o $(OUT_DIR)/$(shell go env GOOS)_$(shell go env GOARCH)_instrumented ./...
.PHONY: cli
cli: build-cli ## Build and install the CLI
cp out/$(shell go env GOOS)_$(shell go env GOARCH)/ocne $(GOPATH)/bin
.PHONY: unit-test
unit-test: cli
$(GO) test -v ./...
# Integration tests
#
# Example commands
# Run tests only on the setup named "default"
# make integration-test TEST_PATTERN=default
#
# Run application tests on the setup named "default"
# make integration-test TEST_PATTERN=default TEST_FILTERS="--filter-tags APPLICATION"
#
# Run the cluster upgrade tests on all setups, start with Kubernetes 1.29 on each cluster
# make integration-test TEST_FILTERS="--filter-tags CLUSTER_UPGRADE" TEST_K8S_VERSION="1.29"
#
$(GOCOVERDIR) $(MERGED_COVER_DIR) $(BATS_RESULT_DIR):
mkdir -p $@
.PHONY: integration-test
integration-test: $(GOCOVERDIR) $(MERGED_COVER_DIR) $(BATS_RESULT_DIR) build-cli-instrumented
cd test && PATH="$(MAKEFILE_DIR)/$(OUT_DIR)/$(shell go env GOOS)_$(shell go env GOARCH)_instrumented:$$PATH" ./run-tests.sh '$(TEST_PATTERN)'
$(GO) tool covdata merge -i=$(GOCOVERDIR) -o=$(MERGED_COVER_DIR)
$(GO) tool covdata textfmt -i=$(MERGED_COVER_DIR) -o=$(CODE_COVERAGE)
echo To view coverage data, execute \"go tool cover -html=$(CODE_COVERAGE)\"
.PHONY: capi-test
capi-test: $(GOCOVERDIR) $(MERGED_COVER_DIR) $(BATS_RESULT_DIR) build-cli-instrumented
cd test && PATH="$(MAKEFILE_DIR)/$(OUT_DIR)/$(shell go env GOOS)_$(shell go env GOARCH)_instrumented:$$PATH" ./run-tests.sh '$(TEST_PATTERN)' 1
$(GO) tool covdata merge -i=$(GOCOVERDIR) -o=$(MERGED_COVER_DIR)
$(GO) tool covdata textfmt -i=$(MERGED_COVER_DIR) -o=$(CODE_COVERAGE)
echo To view coverage data, execute \"go tool cover -html=$(CODE_COVERAGE)\"
.PHONY: release-test
release-test: $(GOCOVERDIR) $(MERGED_COVER_DIR) $(BATS_RESULT_DIR) build-cli-instrumented
cd test && PATH="$(MAKEFILE_DIR)/$(OUT_DIR)/$(shell go env GOOS)_$(shell go env GOARCH)_instrumented:$$PATH" ./run-tests.sh '$(TEST_PATTERN)' 1 1
$(GO) tool covdata merge -i=$(GOCOVERDIR) -o=$(MERGED_COVER_DIR)
$(GO) tool covdata textfmt -i=$(MERGED_COVER_DIR) -o=$(CODE_COVERAGE)
echo To view coverage data, execute \"go tool cover -html=$(CODE_COVERAGE)\"
clean-charts:
rm -rf $(CHART_EMBED)
rm -rf $(CHART_GIT_DIR)
clean: clean-charts ## Delete output from prior builds
rm -rf $(BUILD_DIR)
rm -rf $(OUT_DIR)