forked from mcuadros/ofelia
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
75 lines (64 loc) · 1.99 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
# Package configuration
PROJECT = ofelia
COMMANDS = ofelia
DEPENDENCIES = golang.org/x/tools/cmd/cover
PACKAGES = github.com/mcuadros/ofelia/core \
github.com/mcuadros/ofelia/middlewares \
github.com/mcuadros/ofelia/cli
# Environment
BASE_PATH := $(shell pwd)
BUILD_PATH := $(BASE_PATH)/build
SHA1 := $(shell git log --format='%H' -n 1 | cut -c1-10)
BUILD := $(shell date +"%m-%d-%Y_%H_%M_%S")
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
# Packages content
PKG_OS = darwin linux
PKG_ARCH = amd64
PKG_CONTENT =
PKG_TAG = latest
# Go parameters
GOCMD = go
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOGET = $(GOCMD) get -v
GOTEST = $(GOCMD) test -v
GHRELEASE = github-release
# Coverage
COVERAGE_REPORT = coverage.txt
COVERAGE_MODE = atomic
ifneq ($(origin TRAVIS_TAG), undefined)
BRANCH := $(TRAVIS_TAG)
endif
# Rules
all: clean packages
dependencies:
@$(GOGET) -t ./...; \
for i in $(DEPENDENCIES); do $(GOGET) $$i; done
test: dependencies
@for p in $(PACKAGES); do \
$(GOTEST) $${p}; \
done;
test-coverage: dependencies
@echo "mode: $(COVERAGE_MODE)" > $(COVERAGE_REPORT); \
for p in $(PACKAGES); do \
$(GOTEST) $${p} -coverprofile=tmp_$(COVERAGE_REPORT) -covermode=$(COVERAGE_MODE); \
cat tmp_$(COVERAGE_REPORT) | grep -v "mode: $(COVERAGE_MODE)" >> $(COVERAGE_REPORT); \
rm tmp_$(COVERAGE_REPORT); \
done;
packages: dependencies
@for os in $(PKG_OS); do \
for arch in $(PKG_ARCH); do \
cd $(BASE_PATH); \
mkdir -p $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}; \
for cmd in $(COMMANDS); do \
GOOS=$${os} GOARCH=$${arch} $(GOCMD) build -ldflags "-X main.version=$(BRANCH) -X main.build=$(BUILD)" -o $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}/$${cmd} $${cmd}.go;\
done; \
for content in $(PKG_CONTENT); do \
cp -rf $${content} $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}/; \
done; \
cd $(BUILD_PATH) && tar -cvzf $(BUILD_PATH)/$(PROJECT)_$(BRANCH)_$${os}_$${arch}.tar.gz $(PROJECT)_$${os}_$${arch}/; \
done; \
done;
clean:
@rm -rf $(BUILD_PATH); \
$(GOCLEAN) .