forked from digitalocean/do-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
101 lines (80 loc) · 3.37 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
90
91
92
93
94
95
96
97
98
99
100
101
.PHONY: all test clean build dependencies
CONFIG_PATH=github.com/digitalocean/do-agent/config
CURRENT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
CURRENT_HASH=$(shell git rev-parse --short HEAD)
ifeq ("$(shell git name-rev --tags --name-only $(shell git rev-parse HEAD))", "undefined")
RELEASE=dev
else
RELEASE=$(shell git name-rev --tags --name-only $(shell git rev-parse HEAD) | sed 's/\^.*$///')
endif
LAST_RELEASE=$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
GOFLAGS = -ldflags="-X $(CONFIG_PATH).build=$(CURRENT_BRANCH).$(CURRENT_HASH) -X $(CONFIG_PATH).version=$(RELEASE) -extldflags -static"
GOVENDOR=$(GOPATH)/bin/govendor
all: build test
build: dependencies
@echo ">> build version=$(RELEASE)"
@echo ">> Building system native"
@env CGO=0 go build $(GOFLAGS) -o do-agent cmd/do-agent/main.go
@echo ">> Creating build directory"
@mkdir -p build
@echo ">> Building linux 386"
@env CGO=0 GOOS=linux GOARCH=386 go build $(GOFLAGS) -o build/do-agent_linux_386 cmd/do-agent/main.go
@echo ">> Building linux amd64"
@env CGO=0 GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -o build/do-agent_linux_amd64 cmd/do-agent/main.go
build-latest-release: checkout-latest-release build
checkout-latest-release: master-branch-check
git fetch --tags
git checkout $(LAST_RELEASE)
install:
@go get $(GOFLAGS) ./...
test: dependencies
@echo " ==Running go test=="
@go test -v $(shell go list ./... | grep -v /vendor/)
@echo " ==Running go vet=="
@go vet $(shell go list ./... | grep -v /vendor/)
@go get -u github.com/golang/lint/golint
@echo " ==Running golint=="
@golint ./... | grep -v '^vendor\/' | grep -v ".pb.*.go:" || true
@echo " ==Done testing=="
clean:
rm do-agent
rm -fr build
dependencies: $(GOVENDOR)
@echo ">> fetching dependencies"
@$(GOVENDOR) sync
$(GOVENDOR):
@echo ">> fetching govendor"
@go get -u github.com/kardianos/govendor
docker:
docker build . \
--build-arg CURRENT_HASH="$(CURRENT_HASH)" \
--build-arg CURRENT_BRANCH="$(CURRENT_BRANCH)" \
--build-arg LAST_RELEASE="$(LAST_RELEASE).$(CURRENT_HASH)-docker" \
-t do-agent \
-t do-agent:$(LAST_RELEASE)
list-latest-release:
@echo $(LAST_RELEASE)
release-major-version: master-branch-check
@echo ">> release major version"
$(eval RELEASE_VERSION=$(shell echo $(LAST_RELEASE) | awk '{split($$0,a,"."); print a[1]+1"."0"."0}'))
@echo "Updating release version from=$(LAST_RELEASE) to=$(RELEASE_VERSION)"
git tag $(RELEASE_VERSION) -m"make release-major-version $(RELEASE_VERSION)"
git push origin --tags
release-minor-version: master-branch-check
@echo "release minor version"
$(eval RELEASE_VERSION=$(shell echo $(LAST_RELEASE) | awk '{split($$0,a,"."); print a[1]"."a[2]+1"."0}'))
@echo "Updating release version from=$(LAST_RELEASE) to=$(RELEASE_VERSION)"
git tag $(RELEASE_VERSION) -m"make release-minor-version $(RELEASE_VERSION)"
git push origin --tags
release-patch-version: master-branch-check
@echo "release patch version"
$(eval RELEASE_VERSION=$(shell echo $(LAST_RELEASE) | awk '{split($$0,a,"."); print a[1]"."a[2]"."a[3]+1}'))
@echo "Updating release version from=$(LAST_RELEASE) to=$(RELEASE_VERSION)"
git tag $(RELEASE_VERSION) -m"make release-patch-version $(RELEASE_VERSION)"
git push origin --tags
master-branch-check:
ifeq ("$(shell git rev-parse --abbrev-ref HEAD)", "master")
@echo "Current branch is master"
else
$(error Action requires the master branch)
endif