Skip to content

Commit

Permalink
ci: Use Go modules and ./...
Browse files Browse the repository at this point in the history
This switches the Makefile and travis setup to rely on Go modules and
`./...` instead of `glide nv`.

Note that a tradeoff of making `benchmarks/` its own module is that
`./...` in the Zap directory will no longer include the `benchmarks/`
directory. So where necessary, we need to run commands separately in
that directory as well, which complicates the build script ever so
slightly.
  • Loading branch information
abhinav committed Oct 29, 2019
1 parent d5882c9 commit 3c19977
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -26,3 +26,7 @@ _testmain.go
*.pprof
*.out
*.log

/bin
profile.out
cover.html
8 changes: 2 additions & 6 deletions .travis.yml
@@ -1,17 +1,13 @@
language: go
sudo: false
go:
- 1.11.x
- 1.12.x
- 1.13.x
go_import_path: go.uber.org/zap
env:
global:
- TEST_TIMEOUT_SCALE=10
cache:
directories:
- vendor
install:
- make dependencies
- GO111MODULE=on
script:
- make lint
- make test
Expand Down
63 changes: 28 additions & 35 deletions Makefile
@@ -1,74 +1,67 @@
export GO15VENDOREXPERIMENT=1
export GOBIN ?= $(shell pwd)/bin

GOLINT = $(GOBIN)/golint
BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
PKGS ?= $(shell glide novendor)

# Directories containing independent Go modules.
MODULE_DIRS = . ./benchmarks

# Many Go tools take file globs or directories as arguments instead of packages.
PKG_FILES ?= *.go zapcore benchmarks buffer zapgrpc zaptest zaptest/observer internal/bufferpool internal/exit internal/color internal/ztest
GO_FILES := $(shell \
find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
-o -name '*.go' -print | cut -b3-)

# The linting tools evolve with each Go version, so run them only on the latest
# stable release.
# The linting tools evolve with each Go version, so run them only on the
# latest stable release.
GO_VERSION := $(shell go version | cut -d " " -f 3)
GO_MINOR_VERSION := $(word 2,$(subst ., ,$(GO_VERSION)))
LINTABLE_MINOR_VERSIONS := 12
LINTABLE_MINOR_VERSIONS := 13

ifneq ($(filter $(LINTABLE_MINOR_VERSIONS),$(GO_MINOR_VERSION)),)
SHOULD_LINT := true
endif


.PHONY: all
all: lint test

.PHONY: dependencies
dependencies:
@echo "Installing Glide and locked dependencies..."
glide --version || go get -u -f github.com/Masterminds/glide
glide install
@echo "Installing test dependencies..."
go install ./vendor/github.com/axw/gocov/gocov
go install ./vendor/github.com/mattn/goveralls
ifdef SHOULD_LINT
@echo "Installing golint..."
go install ./vendor/golang.org/x/lint/golint
else
@echo "Not installing golint, since we don't expect to lint on" $(GO_VERSION)
endif

# Disable printf-like invocation checking due to testify.assert.Error()
VET_RULES := -printf=false

.PHONY: lint
lint:
lint: $(GOLINT)
ifdef SHOULD_LINT
@rm -rf lint.log
@echo "Checking formatting..."
@gofmt -d -s $(PKG_FILES) 2>&1 | tee lint.log
@echo "Installing test dependencies for vet..."
@go test -i $(PKGS)
@gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log
@echo "Checking vet..."
@go vet $(VET_RULES) $(PKGS) 2>&1 | tee -a lint.log
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go vet ./... 2>&1) &&) true | tee -a lint.log
@echo "Checking lint..."
@$(foreach dir,$(PKGS),golint $(dir) 2>&1 | tee -a lint.log;)
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && $(GOLINT) ./... 2>&1) &&) true | tee -a lint.log
@echo "Checking for unresolved FIXMEs..."
@git grep -i fixme | grep -v -e vendor -e Makefile | tee -a lint.log
@git grep -i fixme | grep -v -e Makefile | tee -a lint.log
@echo "Checking for license headers..."
@./checklicense.sh | tee -a lint.log
@[ ! -s lint.log ]
else
@echo "Skipping linters on" $(GO_VERSION)
endif

$(GOLINT):
go install golang.org/x/lint/golint

.PHONY: test
test:
go test -race $(PKGS)
go test -race ./...

.PHONY: cover
cover:
./scripts/cover.sh $(PKGS)
go test -race -coverprofile=profile.out -coverpkg=./... ./...
go tool cover -html=profile.out -o cover.html

.PHONY: bench
BENCH ?= .
bench:
@$(foreach pkg,$(PKGS),go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) $(pkg);)
@$(foreach dir,$(MODULE_DIRS), ( \
cd $(dir) && \
go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \
) &&) true

.PHONY: updatereadme
updatereadme:
Expand Down
12 changes: 0 additions & 12 deletions scripts/cover.sh

This file was deleted.

28 changes: 28 additions & 0 deletions tools.go
@@ -0,0 +1,28 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// +build tools

package zap

import (
// Tools we use during development.
_ "golang.org/x/lint/golint"
)

0 comments on commit 3c19977

Please sign in to comment.