Skip to content

Commit

Permalink
Add travis/codecov for pre-commit validation (#13)
Browse files Browse the repository at this point in the history
The coverage.sh is from codecov. Once 1.10 lands, we'll no longer need
it!
  • Loading branch information
prashantv committed Jan 8, 2018
1 parent 85b87f5 commit 1874254
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
sudo: false
language: go
go_import_path: go.uber.org/goleak

go:
# TODO(prashant): Enable once we have fixed Linux issues with old versions.
#- 1.6
#- 1.7
#- 1.8
- 1.9.2
env:
- TEST=yes

matrix:
include:
- go: 1.9.2
env: COVERAGE=yes LINT=yes

cache:
directories:
- vendor

install:
- make install_deps

script:
- test -z "$TEST" || make test
- test -z "$COVERAGE" || scripts/coverage.sh
- test -z "$LINT" || make install_lint lint

after_success:
- test -z "$COVERAGE" || bash <(curl -s https://codecov.io/bash)
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
PACKAGES := $(shell glide nv)
# Many Go tools take file globs or directories as arguments instead of packages.
PACKAGE_FILES ?= *.go $(shell find internal -type f -iname '*.go')

.PHONY: build
build:
go build -i $(PACKAGES)


.PHONY: install_deps
install_deps:
glide --version || go get github.com/Masterminds/glide
glide install


.PHONY: test
test:
go test -v -race $(PACKAGES)

.PHONY: install_lint
install_lint:
go get github.com/golang/lint/golint

.PHONY: lint
lint:
@rm -rf lint.log
@echo "Checking formatting..."
@gofmt -d -s $(PACKAGE_FILES) 2>&1 | tee lint.log
@echo "Checking vet..."
@$(foreach dir,$(PACKAGE_FILES),go tool vet $(dir) 2>&1 | tee -a lint.log;)
@echo "Checking lint..."
@$(foreach dir,$(PACKAGES),golint $(dir) 2>&1 | tee -a lint.log;)
@echo "Checking for unresolved FIXMEs..."
@git grep -i fixme | grep -v -e '^vendor/' -e '^Makefile' | tee -a lint.log
@[ ! -s lint.log ]

12 changes: 12 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e
echo "" > coverage.txt

for d in $(go list ./...); do
go test -race -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done

0 comments on commit 1874254

Please sign in to comment.