-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
89 lines (71 loc) · 2.23 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
BINDIR := $(CURDIR)/bin
TESTFLAGS := -v
INSTALL_DIR := /usr/local/bin
FILENAME := cnab-azure
PKG := github.com/deislabs/$(FILENAME)-driver
COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION ?= $(shell git describe --tags 2> /dev/null || echo v0)
ifeq ($(OS),Windows_NT)
TARGET = $(FILENAME).exe
SHELL = pwsh.exe
CHECK = where
else
TARGET = $(FILENAME)
SHELL ?= bash
CHECK ?= which
endif
GO = GO111MODULE=on go
LDFLAGS = -w -s -X $(PKG)/pkg.Version=$(VERSION) -X $(PKG)/pkg.Commit=$(COMMIT)
default: build
.PHONY: build
build:
mkdir -p $(BINDIR)
$(GO) build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(TARGET) ./cmd/...
.PHONY: install
install:
install $(BINDIR)/$(TARGET) $(INSTALL_DIR)
CX_OSES = linux windows darwin
CX_ARCHS = amd64
xbuild-all: clean
ifeq ($(OS),Windows_NT)
powershell -executionPolicy bypass -NoLogo -NoProfile -File ./build/build-release.ps1 -oses '$(CX_OSES)' -arch $(CX_ARCHS) -ldflags $(LDFLAGS) -filename $(FILENAME) -bindir $(BINDIR)
else
@for os in $(CX_OSES); do \
echo "building $$os"; \
for arch in $(CX_ARCHS); do \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 $(GO) build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(TARGET)-$$os-$$arch ./cmd/...; \
done; \
if [ $$os = 'windows' ]; then \
mv $(BINDIR)/$(TARGET)-$$os-$$arch $(BINDIR)/$(TARGET)-$$os-$$arch.exe; \
fi; \
done
endif
test-all-local: test test-in-azure-local
test-all: test test-in-azure
.PHONY: test
test:
$(GO) test $(TESTFLAGS) ./...
test-in-azure:
$(GO) test $(TESTFLAGS) -timeout 30m ./pkg/... -args -runazuretest -verbosedriveroutput
test-in-azure-local:
ifeq ($(OS),Windows_NT)
powershell -executionPolicy bypass -NoLogo -NoProfile -file ./test/run_azure_test.local.ps1
else
./test/run_azure_test.local.sh
endif
lint: bootstrap
golangci-lint run --config ./golangci.yml
HAS_GOLANGCI := $(shell $(CHECK) golangci-lint)
HAS_GOIMPORTS := $(shell $(CHECK) goimports)
GOLANGCI_VERSION := v1.29.0
bootstrap:
ifndef HAS_GOLANGCI
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_VERSION)
endif
ifndef HAS_GOIMPORTS
go get -u golang.org/x/tools/cmd/goimports
endif
goimports: bootstrap
find . -name "*.go" | fgrep -v vendor/ | xargs goimports -w -local $(PKG)
clean:
-rm -fr bin/