-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
75 lines (63 loc) · 1.84 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
# Project specific variables
PROJECT=manageiq-exchange
# --- the rest of the file should not need to be configured ---
# GO env
GOPATH=$(shell pwd)
GO=go
GOCMD=GOPATH=$(GOPATH) $(GO)
RELEASE_PATH := ${GOPATH}/release
DISTPATH := bin/$(PROJECT)
# Build versioning
COMMIT = $(shell git log -1 --format="%h" 2>/dev/null || echo "0")
VERSION=$(shell git describe --tags --always)
BUILD_DATE = $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
FLAGS = -ldflags "\
-X constants.COMMIT=$(COMMIT) \
-X constants.VERSION=$(VERSION) \
-X constants.BUILD_DATE=$(BUILD_DATE) \
"
GOBUILD = $(GOCMD) build $(FLAGS)
.PHONY: all
all: build
.PHONY: build
build: format test compile
.PHONY: compile
compile:
GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(DISTPATH).darwin ./src/$(PROJECT)
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(DISTPATH).linux ./src/$(PROJECT)
.PHONY: deploy
deploy: coverage build
echo "Creating tar file"
tar -zcf $(RELEASE_PATH)/$(PROJECT)-$(VERSION).tar.gz bin/$(PROJECT)*
.PHONY: format
format:
@for gofile in $$(find ./src/$(PROJECT) -name "*.go"); do \
echo "formatting" $$gofile; \
gofmt -w $$gofile; \
done
.PHONY: run
run:
- $(GOCMD) run ./src/$(PROJECT)/main.go
.PHONY: test
test:
$(GOCMD) test -v -race -tags safe ./...
.PHONY: coverage
coverage:
rm -fr coverage
mkdir -p coverage
$(GOCMD) list $(PROJECT)/... > coverage/packages
@i=a ; \
while read -r P; do \
i=a$$i ; \
$(GOCMD) test ./src/$$P -cover -coverpkg $$P -covermode=count -coverprofile=coverage/$$i.out; \
done <coverage/packages
echo "mode: count" > coverage/coverage
cat coverage/*.out | grep -v "mode: count" >> coverage/coverage
$(GOCMD) tool cover -html=coverage/coverage
.PHONY: CI-Coverage
CI-Coverage: coverage
go get -v github.com/mattn/goveralls
goveralls -coverprofile=coverage/coverage -service=travis-ci -covermode=count
.PHONY: clean
clean:
rm -fR bin pkg