-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
67 lines (57 loc) · 1.59 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
# Default shell
SHELL := /bin/bash
# General
PROJECT = brickie
COMMANDS = brickie
WORKDIR = $(PWD)
# Go parameters
GOCMD = go
GOTEST = $(GOCMD) test -v
# Coverage
COVERAGE_REPORT = coverage.txt
COVERAGE_PROFILE = profile.out
COVERAGE_MODE = atomic
# Environment
BUILD_PATH := $(WORKDIR)/build
BUILD := $(shell date +"%m-%d-%Y_%H_%M_%S")
COMMIT := $(shell git log --format='%H' -n 1 | cut -c1-10)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
# Packages content
PKG_OS = darwin linux
PKG_ARCH = amd64
ifneq ($(origin CI), undefined)
WORKDIR := $(TRAVIS_BUILD_DIR)
endif
test:
$(GOTEST) ./...
packages:
for os in $(PKG_OS); do \
for arch in $(PKG_ARCH); do \
cd $(WORKDIR); \
mkdir -p $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}; \
for cmd in $(COMMANDS); do \
if [ -d "$${cmd}" ]; then \
cd $${cmd}; \
fi; \
GOOS=$${os} GOARCH=$${arch} $(GOCMD) build -ldflags \
"-X main.version=$(BRANCH) -X main.build=$(BUILD) -X main.commit=$(COMMIT)" \
-o "$(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}/`basename $${PWD}`" .; \
cd $(WORKDIR); \
done; \
cd $(BUILD_PATH); \
tar -cvzf $(PROJECT)_$(BRANCH)_$${os}_$${arch}.tar.gz $(PROJECT)_$${os}_$${arch}/; \
done; \
done; \
test-coverage:
cd $(WORKDIR); \
echo "" > $(COVERAGE_REPORT); \
for dir in `find . -name "*.go" | grep -o '.*/' | sort | uniq`; do \
$(GOTEST) $$dir -coverprofile=$(COVERAGE_PROFILE) -covermode=$(COVERAGE_MODE); \
if [ $$? != 0 ]; then \
exit 2; \
fi; \
if [ -f $(COVERAGE_PROFILE) ]; then \
cat $(COVERAGE_PROFILE) >> $(COVERAGE_REPORT); \
rm $(COVERAGE_PROFILE); \
fi; \
done; \