Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
56 lines (43 loc) · 1.46 KB
/
Copy pathMakefile
File metadata and controls
56 lines (43 loc) · 1.46 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
PWD := $(shell pwd)
PLATFORM := linux
BINARY := opa-pdp
GO_TEST_CLEAN ?= go clean -cache -testcache -modcache -i -r
RETRY_COUNT ?= 3
SLEEP_BETWEEN_RETRIES ?= 5
GO_INSTALL_DIR := /usr/local/go
# The install target unpacks the pinned Go (build_image.sh GO_VERSION) into
# GO_INSTALL_DIR, but it runs in a subshell so its PATH never reaches this make
# process and go falls back to whatever the build node ships -- Go 1.23 on the
# ONAP CI nodes. go.mod toolchain switching covers build and test but not
# coverage: 'go test -coverprofile' shells out to 'go tool covdata' resolved from
# PATH, and a pre-1.26 go cannot find covdata inside a 1.26 GOROOT because 1.26
# builds it on demand instead of shipping it prebuilt. GOROOT is dropped because
# the Jenkins Go plugin points it at that same older tree.
ifneq ($(wildcard $(GO_INSTALL_DIR)/bin/go),)
export PATH := $(GO_INSTALL_DIR)/bin:$(PATH)
unexport GOROOT
endif
all: test build
build: install clean go_build test cover
deploy: build_image
.PHONY: test
test:
@go test -v -p 1 ./...
format:
@go fmt ./...
clean:
@echo "Cleaning up..."
rm -f go.tar.gz
@rm -f $(BINARY)
@echo "Done."
.PHONY: cover
cover:
@go test -p 2 ./... -coverprofile=coverage.out
@go tool cover -func=coverage.out -o coverage.html
.PHONY: install clean
install:
./build_image.sh install
build_image:
./build_image.sh build
go_build:
CGO_ENABLED=1 GOOS=$(PLATFORM) GOARCH=amd64 go build -ldflags "-w -s" -o $(PWD)/$(BINARY) cmd/opa-pdp/opa-pdp.go