Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.

Commit d68a8c9

Browse files
committed
chore: Use Makefile.common and add basic checks in the Travis CI
Signed-off-by: Martin Chodur <[email protected]>
1 parent e5a9fe7 commit d68a8c9

File tree

3 files changed

+145
-7
lines changed

3 files changed

+145
-7
lines changed

.travis.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
sudo: false
2-
32
language: go
43

54
go:
6-
- 1.9.x
7-
- 1.10.x
5+
- 1.9.x
6+
- 1.10.x
87

98
go_import_path: github.com/prometheus/tsdb
109

10+
install:
11+
- go get -v -t ./...
12+
1113
script:
12-
- go test -timeout 5m ./...
14+
# `check_license` target is omitted due to some missing license headers
15+
# `staticcheck` target is omitted due to linting errors
16+
- make style unused test

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
TSDB_CLI_DIR="./cmd/tsdb"
14+
TSDB_PROJECT_DIR = "."
15+
TSDB_CLI_DIR="$(TSDB_PROJECT_DIR)/cmd/tsdb"
1516
TSDB_BIN = "$(TSDB_CLI_DIR)/tsdb"
1617
TSDB_BENCHMARK_NUM_METRICS ?= 1000
17-
TSDB_PROJECT_DIR = "."
1818
TSDB_BENCHMARK_DATASET ?= "$(TSDB_PROJECT_DIR)/testdata/20kseries.json"
1919
TSDB_BENCHMARK_OUTPUT_DIR ?= "$(TSDB_CLI_DIR)/benchout"
20-
GO = "go"
20+
21+
STATICCHECK_IGNORE =
22+
include Makefile.common
2123

2224
build:
2325
@$(GO) build -o $(TSDB_BIN) $(TSDB_CLI_DIR)

Makefile.common

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Copyright 2018 The Prometheus Authors
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
15+
# A common Makefile that includes rules to be reused in different prometheus projects.
16+
# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
17+
18+
# Example usage :
19+
# Create the main Makefile in the root project directory.
20+
# include Makefile.common
21+
# customTarget:
22+
# @echo ">> Running customTarget"
23+
#
24+
25+
# Ensure GOBIN is not set during build so that promu is installed to the correct path
26+
unexport GOBIN
27+
28+
GO ?= go
29+
GOFMT ?= $(GO)fmt
30+
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
31+
PROMU := $(FIRST_GOPATH)/bin/promu
32+
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
33+
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
34+
pkgs = ./...
35+
36+
PREFIX ?= $(shell pwd)
37+
BIN_DIR ?= $(shell pwd)
38+
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
39+
DOCKER_REPO ?= prom
40+
41+
.PHONY: all
42+
all: style staticcheck unused build test
43+
44+
# This rule is used to forward a target like "build" to "common-build". This
45+
# allows a new "build" target to be defined in a Makefile which includes this
46+
# one and override "common-build" without override warnings.
47+
%: common-% ;
48+
49+
.PHONY: common-style
50+
common-style:
51+
@echo ">> checking code style"
52+
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
53+
if [ -n "$${fmtRes}" ]; then \
54+
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
55+
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
56+
exit 1; \
57+
fi
58+
59+
.PHONY: common-check_license
60+
common-check_license:
61+
@echo ">> checking license header"
62+
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
63+
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
64+
done); \
65+
if [ -n "$${licRes}" ]; then \
66+
echo "license header checking failed:"; echo "$${licRes}"; \
67+
exit 1; \
68+
fi
69+
70+
.PHONY: common-test-short
71+
common-test-short:
72+
@echo ">> running short tests"
73+
$(GO) test -short $(pkgs)
74+
75+
.PHONY: common-test
76+
common-test:
77+
@echo ">> running all tests"
78+
$(GO) test -race $(pkgs)
79+
80+
.PHONY: common-format
81+
common-format:
82+
@echo ">> formatting code"
83+
$(GO) fmt $(pkgs)
84+
85+
.PHONY: common-vet
86+
common-vet:
87+
@echo ">> vetting code"
88+
$(GO) vet $(pkgs)
89+
90+
.PHONY: common-staticcheck
91+
common-staticcheck: $(STATICCHECK)
92+
@echo ">> running staticcheck"
93+
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
94+
95+
.PHONY: common-unused
96+
common-unused: $(GOVENDOR)
97+
@echo ">> running check for unused packages"
98+
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
99+
100+
.PHONY: common-build
101+
common-build: promu
102+
@echo ">> building binaries"
103+
$(PROMU) build --prefix $(PREFIX)
104+
105+
.PHONY: common-tarball
106+
common-tarball: promu
107+
@echo ">> building release tarball"
108+
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
109+
110+
.PHONY: common-docker
111+
common-docker:
112+
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
113+
114+
.PHONY: common-docker-publish
115+
common-docker-publish:
116+
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"
117+
118+
.PHONY: common-docker-tag-latest
119+
common-docker-tag-latest:
120+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):latest"
121+
122+
.PHONY: promu
123+
promu:
124+
GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
125+
126+
.PHONY: $(STATICCHECK)
127+
$(STATICCHECK):
128+
GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
129+
130+
.PHONY: $(GOVENDOR)
131+
$(GOVENDOR):
132+
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor

0 commit comments

Comments
 (0)