-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
79 lines (62 loc) · 2.2 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
# Makefile for building and testing
GO_LDFLAGS ?= -w -extldflags "-static"
GIT_REVISION_SHORT := $(shell git rev-parse --short HEAD)
GIT_REVISION := $(shell git rev-parse --short HEAD)
GIT_TAG_VERSION := $(shell git tag -l --points-at HEAD | grep -v latest)
ifeq ($(CI),true)
GO_TEST_EXTRAS ?= "-coverprofile=c.out"
GO_LDFLAGS += -X main.GitRevision=$(GIT_REVISION_SHORT) -X main.Version=$(GIT_TAG_VERSION)
GO_PGOFLAGS ?= "-pgo=profiles/merged.pprof"
endif
vendor: go.sum go.mod
go mod vendor -v
check_imports:
@echo "Checking goimports for imports and formatting..."
goimports -l -d .
@goimports -l -d . | xargs echo | xargs test -z 2> /dev/null
lint: vet check_imports
@echo "Running golangci-lint"
golangci-lint run
vet:
@echo "Running go vet ..."
go list ./... | xargs go vet
generate:
@if [ -z "$(CI)" ]; then \
echo "Running go generate ..." ;\
go generate ./... ;\
fi
test: generate check_imports
go clean -testcache || true
@echo "Executing tests ..."
go test -race -v ${GO_TEST_EXTRAS} ./...
itests:
@echo "Running integration tests"
cd ./itests && ./itests_runner.sh
clean:
@echo "Cleaning build cache"
go clean -cache
@echo "Cleaning test cache"
go clean -testcache
@echo "Cleaning binary"
rm -rf target || true
build: generate
@echo "Creating GO binary"
mkdir -p target
CGO_ENABLED=0 GOOS=linux go build -ldflags "$(GO_LDFLAGS)" ${GO_PGOFLAGS} -o target/pg-bifrost github.com/Nextdoor/pg-bifrost.git/main
build_mac: generate
@echo "Creating GO binary"
mkdir -p target
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o target/pg-bifrost github.com/Nextdoor/pg-bifrost.git/main
# Standard settings that will be used later
DOCKER := $(shell which docker)
docker_build:
@echo "Building pg-bifrost docker image"
@$(DOCKER) build -t "pg-bifrost:latest" --build-arg is_ci="${CI}" --build-arg GIT_REVISION="${GIT_REVISION}" .
docker_get_binary:
@echo "Copying binary from docker image"
mkdir -p target
@$(DOCKER) rm "pg-bifrost-build" || true
@$(DOCKER) create --name "pg-bifrost-build" "pg-bifrost:latest" /pg-bifrost
@$(DOCKER) cp "pg-bifrost-build":/pg-bifrost target/
@$(DOCKER) rm "pg-bifrost-build"
.PHONY: clean test itests docker_build docker_get_binary vendor lint check_imports