forked from redhat-openshift-ecosystem/openshift-preflight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (116 loc) · 5.07 KB
/
Copy pathMakefile
File metadata and controls
144 lines (116 loc) · 5.07 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
140
141
142
143
144
.DEFAULT_GOAL:=help
BINARY?=preflight
IMAGE_BUILDER?=podman
IMAGE_REPO?=quay.io/opdev
VERSION=$(shell git rev-parse HEAD)
RELEASE_TAG ?= "0.0.0"
PLATFORMS=linux darwin
ARCHITECTURES_LINUX=amd64 arm64 ppc64le s390x
ARCHITECTURES_MAC=amd64 arm64
.PHONY: build
build:
CGO_ENABLED=0 go build -o $(BINARY) -trimpath -ldflags "-s -w -X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=$(VERSION) -X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=$(RELEASE_TAG)" cmd/preflight/main.go
@ls | grep -e '^preflight$$' &> /dev/null
.PHONY: build-multi-arch-linux
build-multi-arch-linux: $(addprefix build-linux-,$(ARCHITECTURES_LINUX))
define LINUX_ARCHITECTURE_template
.PHONY: build-linux-$(1)
build-linux-$(1):
GOOS=linux GOARCH=$(1) CGO_ENABLED=0 go build -o $(BINARY)-linux-$(1) -trimpath -ldflags "-s -w -X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=$(VERSION) \
-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=$(RELEASE_TAG)" cmd/preflight/main.go
endef
$(foreach arch,$(ARCHITECTURES_LINUX),$(eval $(call LINUX_ARCHITECTURE_template,$(arch))))
.PHONY: build-multi-arch-mac
build-multi-arch-mac: $(addprefix build-mac-,$(ARCHITECTURES_MAC))
define MAC_ARCHITECTURE_template
.PHONY: build-mac-$(1)
build-mac-$(1):
GOOS=darwin GOARCH=$(1) go build -o $(BINARY)-darwin-$(1) -trimpath -ldflags "-s -w -X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=$(VERSION) \
-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=$(RELEASE_TAG)" cmd/preflight/main.go
endef
$(foreach arch,$(ARCHITECTURES_MAC),$(eval $(call MAC_ARCHITECTURE_template,$(arch))))
.PHONY: fmt
fmt: gofumpt
${GOFUMPT} -l -w .
git diff --exit-code
.PHONY: tidy
tidy:
go mod tidy
git diff --exit-code
.PHONY: image-build
image-build:
$(IMAGE_BUILDER) build --build-arg release_tag=$(RELEASE_TAG) --build-arg preflight_commit=$(VERSION) -t $(IMAGE_REPO)/preflight:$(VERSION) .
.PHONY: image-push
image-push:
$(IMAGE_BUILDER) push $(IMAGE_REPO)/preflight:$(VERSION)
.PHONY: test
test:
go test -v -tags testing $$(go list ./... | grep -v e2e) \
-ldflags "-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=bar -X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=foo"
.PHONY: cover
cover: go-ignore-cov
go test -v -tags testing \
-ldflags "-X github.com/redhat-openshift-ecosystem/openshift-preflight/version.commit=bar -X github.com/redhat-openshift-ecosystem/openshift-preflight/version.version=foo" \
$$(go list ./... | grep -v e2e) \
-race \
-cover -coverprofile=coverage.out
$(GO_IGNORE_COV) --file coverage.out
.PHONY: vet
vet:
go vet -tags testing ./...
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter checks.
$(GOLANGCI_LINT) run --build-tags testing
.PHONY: test-e2e
test-e2e:
./test/e2e/operator-test.sh
.PHONY: test-e2e-customized-env
test-e2e-customized-env:
./test/e2e/operator-test-customized-env.sh
.PHONY: ensure-release-tag-set
ensure-release-tag-set:
echo "Make sure the RELEASE_TAG value is set."
test $(RELEASE_TAG) != "0.0.0"
.PHONY: verify-image
verify-image: cosign ensure-release-tag-set
${COSIGN} verify \
--certificate-identity https://github.com/redhat-openshift-ecosystem/openshift-preflight/.github/workflows/build-multiarch.yml@refs/tags/$(RELEASE_TAG) \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
quay.io/opdev/preflight:$(RELEASE_TAG)
.PHONY: clean
clean:
@go clean
@# cleans the binary created by make build
$(shell if [ -f "$(BINARY)" ]; then rm -f $(BINARY); fi)
@# cleans all the binaries created by make build-multi-arch
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES_LINUX),\
$(shell if [ -f "$(BINARY)-$(GOOS)-$(GOARCH)" ]; then rm -f $(BINARY)-$(GOOS)-$(GOARCH); fi)))
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES_MAC),\
$(shell if [ -f "$(BINARY)-$(GOOS)-$(GOARCH)" ]; then rm -f $(BINARY)-$(GOOS)-$(GOARCH); fi)))
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v2.1.6
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT):
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
GOFUMPT = $(shell pwd)/bin/gofumpt
GOFUMPT_VERSION ?= v0.9.0
gofumpt: ## Download envtest-setup locally if necessary.
$(call go-install-tool,$(GOFUMPT),mvdan.cc/gofumpt@$(GOFUMPT_VERSION))
COSIGN = $(shell pwd)/bin/cosign
COSIGN_VERSION ?= v2.0.0
cosign: ## Download envtest-setup locally if necessary.
$(call go-install-tool,$(COSIGN),github.com/sigstore/cosign/v2/cmd/cosign@$(COSIGN_VERSION))
GO_IGNORE_COV=$(shell pwd)/bin/go-ignore-cov
GO_IGNORE_COV_VERSION ?= v0.6.1
go-ignore-cov: $(GO_IGNORE_COV)
$(GO_IGNORE_COV):
$(call go-install-tool,$(GO_IGNORE_COV),github.com/quantumcycle/go-ignore-cov@$(GO_IGNORE_COV_VERSION))
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install-tool
@[ -f $(1) ] || { \
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
}
endef