-
Notifications
You must be signed in to change notification settings - Fork 86
/
Makefile
128 lines (102 loc) · 3.7 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
SHELL := bash
PACKAGE_CHECKOUT := $(shell echo ${PWD})
PACKAGE := github.com/travis-ci/worker
ALL_PACKAGES := $(PACKAGE) $(shell script/list-packages) $(PACKAGE)/cmd/...
VERSION_VAR := $(PACKAGE).VersionString
VERSION_VALUE ?= $(shell git describe --always --dirty --tags 2>/dev/null)
REV_VAR := $(PACKAGE).RevisionString
REV_VALUE ?= $(shell git rev-parse HEAD 2>/dev/null || echo "'???'")
REV_URL_VAR := $(PACKAGE).RevisionURLString
REV_URL_VALUE ?= https://github.com/travis-ci/worker/tree/$(shell git rev-parse HEAD 2>/dev/null || echo "'???'")
GENERATED_VAR := $(PACKAGE).GeneratedString
GENERATED_VALUE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%S%z')
COPYRIGHT_VAR := $(PACKAGE).CopyrightString
COPYRIGHT_VALUE ?= $(shell grep -i ^copyright LICENSE | sed 's/^[Cc]opyright //')
DOCKER_IMAGE_REPO ?= gcr.io/travis-ci-prod-services-1/worker
DOCKER_DEST ?= $(DOCKER_IMAGE_REPO):$(VERSION_VALUE)
DOCKER ?= docker
GO ?= go
GOPATH := $(shell echo $${GOPATH%%:*})
GOPATH_BIN := $(GOPATH)/bin
GOBUILD_LDFLAGS ?= \
-X '$(VERSION_VAR)=$(VERSION_VALUE)' \
-X '$(REV_VAR)=$(REV_VALUE)' \
-X '$(REV_URL_VAR)=$(REV_URL_VALUE)' \
-X '$(GENERATED_VAR)=$(GENERATED_VALUE)' \
-X '$(COPYRIGHT_VAR)=$(COPYRIGHT_VALUE)'
export GO15VENDOREXPERIMENT
export DOCKER_DEST
COVERPROFILES := \
root-coverage.coverprofile \
backend-coverage.coverprofile \
config-coverage.coverprofile \
image-coverage.coverprofile
CROSSBUILD_BINARIES := \
build/darwin/amd64/travis-worker \
build/linux/amd64/travis-worker
SHFMT_URL := https://github.com/mvdan/sh/releases/download/v2.5.0/shfmt_v2.5.0_linux_amd64
%-coverage.coverprofile:
$(GO) test -covermode=count -coverprofile=$@ \
-tags netgo -ldflags "$(GOBUILD_LDFLAGS)" \
$(PACKAGE)/$(subst -,/,$(subst root,,$(subst -coverage.coverprofile,,$@)))
.PHONY: %
%:
./script/$@
.PHONY: all
all: clean test
.PHONY: test
test: .deps-fetched lintall build fmtpolice test-no-cover test-cover
.PHONY: test-cover
test-cover: coverage.html
.PHONY: test-no-cover
test-no-cover:
$(GO) test -race -tags netgo -ldflags "$(GOBUILD_LDFLAGS)" $(ALL_PACKAGES)
coverage.html: coverage.coverprofile
$(GO) tool cover -html=$^ -o $@
coverage.coverprofile: $(COVERPROFILES)
./script/fold-coverprofiles $^ > $@
$(GO) tool cover -func=$@
.PHONY: build
build: .deps-fetched
$(GO) install -tags netgo -ldflags "$(GOBUILD_LDFLAGS)" $(ALL_PACKAGES)
.PHONY: crossbuild
crossbuild: .deps-fetched $(CROSSBUILD_BINARIES)
.PHONY: docker-build
docker-build:
$(DOCKER) build -t $(DOCKER_DEST) .
build/darwin/amd64/travis-worker:
GOARCH=amd64 GOOS=darwin CGO_ENABLED=0 \
$(GO) build -o build/darwin/amd64/travis-worker \
-ldflags "$(GOBUILD_LDFLAGS)" $(PACKAGE)/cmd/travis-worker
build/linux/amd64/travis-worker:
GOARCH=amd64 GOOS=linux CGO_ENABLED=0 \
$(GO) build -o build/linux/amd64/travis-worker \
-ldflags "$(GOBUILD_LDFLAGS)" $(PACKAGE)/cmd/travis-worker
.PHONY: distclean
distclean: clean
rm -rf .deps-fetched build/
.PHONY: deps
deps: .ensure-shfmt .ensure-golangci-lint .deps-fetched
.deps-fetched: go.mod
GO111MODULE=on $(GO) mod download
GO111MODULE=on $(GO) mod vendor
touch $@
.PHONY: .ensure-shfmt
.ensure-shfmt:
if ! shfmt -version 2>/dev/null; then \
curl -o $(GOPATH_BIN)/shfmt -sSL $(SHFMT_URL); \
chmod +x $(GOPATH_BIN)/shfmt; \
shfmt -version; \
fi
.PHONY: .ensure-golangci-lint
.ensure-golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(HOME)/bin
if ! command -v $(go env GOPATH)/bin/golangci-lint &>/dev/null; then \
$(HOME)/bin/golangci-lint --version; \
fi
.PHONY: annotations
annotations:
@git grep -E '(TODO|FIXME|XXX):' | grep -v -E 'Makefile|vendor/'
$(DOCKER_ENV_FILE):
env | grep ^DOCKER | sort >$@
echo 'DOCKER_DEST=$(DOCKER_DEST)' >>$@