This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
forked from ivanfoo/mortadelo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (62 loc) · 1.78 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
# Default shell
SHELL := /bin/bash
# Project
PROJECT := mortadelo
COMMANDS := mortadelo
# Go commands
GOCMD = go
GOGET = $(GOCMD) get -v -t
GOTEST = $(GOCMD) test -v
# Coverage
COVERAGE_REPORT = coverage.txt
COVERAGE_PROFILE = profile.out
COVERAGE_MODE = atomic
# Env
BUILD_PATH := $(PWD)
# Artifacts
ARTIFACTS_PATH := $(PWD)/artifacts
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)
PKG_OS = darwin linux windows
PKG_ARCH = amd64
# Travis-CI
ifneq ($(origin CI), undefined)
COMMIT := $(shell echo $(TRAVIS_COMMIT) | cut -c1-10)
BRANCH := $(TRAVIS_BRANCH)
BUILD_PATH := $(TRAVIS_BUILD_DIR)
ARTIFACTS_PATH := $(TRAVIS_BUILD_DIR)/artifacts
endif
dependencies:
$(GOGET) ./...
test-coverage:
cd $(BUILD_PATH); \
echo "" > $(COVERAGE_REPORT); \
for dir in `find . -name "*.go" | grep -o '.*/' | sort -u`; 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; \
packages:
for os in $(PKG_OS); do \
for arch in $(PKG_ARCH); do \
cd $(BUILD_PATH); \
mkdir -p $(ARTIFACTS_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 "$(ARTIFACTS_PATH)/$(PROJECT)_$${os}_$${arch}/`basename $${PWD}`" .; \
cd $(BUILD_PATH); \
done; \
cd $(ARTIFACTS_PATH); \
tar -cvzf $(PROJECT)_$(BRANCH)_$${os}_$${arch}.tgz $(PROJECT)_$${os}_$${arch}/; \
done; \
done; \