-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (109 loc) · 3.76 KB
/
Makefile
File metadata and controls
130 lines (109 loc) · 3.76 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
# Copyright (c) 2021 Red Hat, Inc.
# Copyright Contributors to the Open Cluster Management project
PWD := $(shell pwd)
LOCAL_BIN ?= $(PWD)/bin
# Keep an existing GOPATH, make a private one if it is undefined
GOPATH_DEFAULT := $(PWD)/.go
export GOPATH ?= $(GOPATH_DEFAULT)
GOBIN_DEFAULT := $(GOPATH)/bin
export GOBIN ?= $(GOBIN_DEFAULT)
export PATH := $(LOCAL_BIN):$(GOBIN):$(PATH)
TESTARGS_DEFAULT := "-v"
export TESTARGS ?= $(TESTARGS_DEFAULT)
export DEPENDENCY_OVERRIDE ?= false
# Kustomize plugin configuration
XDG_CONFIG_HOME ?= ${HOME}/.config
KUSTOMIZE_PLUGIN_HOME ?= $(XDG_CONFIG_HOME)/kustomize/plugin
API_PLUGIN_PATH ?= $(KUSTOMIZE_PLUGIN_HOME)/policy.open-cluster-management.io/v1/policygenerator
# Kustomize arguments
SOURCE_DIR ?= examples/
include build/common/Makefile.common.mk
############################################################
# clean section
############################################################
.PHONY: clean
clean:
-rm $(LOCAL_BIN)/*
-rm $(API_PLUGIN_PATH)/PolicyGenerator
-rm build_output/*
-rm PolicyGenerator
############################################################
# build section
############################################################
# Parse the version using git, with fallbacks as follows:
# - git describe (i.e. vX.Y.Z-<extra_commits>-<sha>)
# - <branch>-<sha>
# - <sha>-dev
# - Go BuildInfo version
# - Unversioned binary
GIT_VERSION := $(shell git describe --dirty 2>/dev/null)
ifndef GIT_VERSION
GIT_BRANCH := $(shell git branch --show-current)
GIT_SHA := $(shell git rev-parse --short HEAD)
ifdef GIT_BRANCH
GIT_VERSION := $(GIT_BRANCH)-$(GIT_SHA)
else ifdef GIT_SHA
GIT_VERSION := $(GIT_SHA)-dev
endif
endif
GO_LDFLAGS ?= -X 'main.Version=$(GIT_VERSION)'
.PHONY: build
build: layout
go build -ldflags="$(GO_LDFLAGS)" -o $(API_PLUGIN_PATH)/ ./cmd/PolicyGenerator
.PHONY: build-binary
build-binary:
CGO_ENABLED=1 go build -mod=readonly -ldflags="$(GO_LDFLAGS)" ./cmd/PolicyGenerator
.PHONY: build-release
build-release:
@if [ $(shell git status --porcelain | wc -l) -gt 0 ]; then \
echo "There are local modifications in the repo" > /dev/stderr; \
exit 1; \
fi
@for ARCH in amd64 arm64 ppc64le s390x; do \
NAME="linux-$${ARCH}-PolicyGenerator"; \
echo "# Building $${NAME}"; \
GOOS=linux GOARCH=$${ARCH} CGO_ENABLED=0 \
go build -mod=readonly -ldflags="$(GO_LDFLAGS)" -o build_output/$${NAME} ./cmd/PolicyGenerator \
|| exit 1; \
done
@for ARCH in amd64 arm64; do \
NAME="darwin-$${ARCH}-PolicyGenerator"; \
echo "# Building $${NAME}"; \
GOOS=darwin GOARCH=$${ARCH} CGO_ENABLED=0 \
go build -mod=readonly -ldflags="$(GO_LDFLAGS)" -o build_output/$${NAME} ./cmd/PolicyGenerator \
|| exit 1; \
done
@for ARCH in amd64 arm64; do \
NAME="windows-$${ARCH}-PolicyGenerator.exe"; \
echo "# Building $${NAME}"; \
GOOS=windows GOARCH=$${ARCH} CGO_ENABLED=0 \
go build -mod=readonly -ldflags="$(GO_LDFLAGS)" -o build_output/$${NAME} ./cmd/PolicyGenerator \
|| exit 1; \
done
.PHONY: generate
generate:
@KUSTOMIZE_PLUGIN_HOME=$(KUSTOMIZE_PLUGIN_HOME) kustomize build --enable-alpha-plugins $(SOURCE_DIR)
.PHONY: layout
layout:
mkdir -p $(API_PLUGIN_PATH)
############################################################
# format section
############################################################
.PHONY: fmt
fmt:
############################################################
# lint section
############################################################
.PHONY: lint
lint:
############################################################
# test section
############################################################
.PHONY: test
test:
@go test $(TESTARGS) ./...
.PHONY: test-coverage
test-coverage: TESTARGS = -json -cover -covermode=atomic -coverprofile=coverage.out
test-coverage: test
.PHONY: gosec-scan
gosec-scan: