Skip to content
Snippets Groups Projects
Commit 14104773 authored by Will McCutchen's avatar Will McCutchen
Browse files

Wire up automated code coverage reports

parent a4ee88cb
No related branches found
No related tags found
No related merge requests found
# To validate this config:
#
# cat codecov.yml | curl --data-binary @- https://codecov.io/validate
#
# See https://docs.codecov.io/docs for more info
# https://docs.codecov.io/docs/coverage-configuration
coverage:
precision: 2
round: down
range: "90..100"
# https://docs.codecov.io/docs/commit-status
status:
target: auto
threshold: 2
patch: no
changes: no
parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no
# https://docs.codecov.io/docs/pull-request-comments
comment:
layout: "header, diff, files"
behavior: default
require_changes: no
...@@ -24,3 +24,4 @@ _testmain.go ...@@ -24,3 +24,4 @@ _testmain.go
*.prof *.prof
dist/* dist/*
coverage.txt
...@@ -5,9 +5,26 @@ go: ...@@ -5,9 +5,26 @@ go:
- '1.10' - '1.10'
- '1.11' - '1.11'
- '1.12' - '1.12'
go_import_path: github.com/mccutchen/go-httpbin
script: script:
- make lint - make lint
- make test - make testci
after_success:
# Upload test coverage results to codecov.io
# https://github.com/codecov/example-go/blob/b85638743b972bd0bd2af63421fe513c6f968930/README.md
- bash <(curl -s https://codecov.io/bash)
# With this filter, we aim to restrict Travis's "Build Pushes" feature to build
# only pushes to master, while allowing the "Build Pull Requests" to build all
# incoming pull requests without redundant double-builds.
#
# This is confusing on Travis's end; this captures the exact problem we're
# trying to solve:
# https://stackoverflow.com/a/31882307
branches:
only:
- master
notifications: notifications:
email: false email: false
.PHONY: clean deploy deps image imagepush lint run stagedeploy test testcover .PHONY: clean deploy deps image imagepush lint run stagedeploy test testci testcover
GCLOUD_PROJECT ?= httpbingo # The version that will be used in docker tags (e.g. to push a
TEST_ARGS ?= -race # go-httpbin:latest image use `make imagepush VERSION=latest)`
VERSION ?= $(shell git rev-parse --short HEAD) VERSION ?= $(shell git rev-parse --short HEAD)
# Override this to deploy to a different App Engine project
GCLOUD_PROJECT ?= httpbingo
# Built binaries will be placed here
DIST_PATH ?= dist
# Default flags used by the test, testci, testcover targets
COVERAGE_PATH ?= coverage.txt
COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH)
TEST_ARGS ?= -race
GENERATED_ASSETS_PATH := httpbin/assets/assets.go GENERATED_ASSETS_PATH := httpbin/assets/assets.go
BIN_DIR := $(GOPATH)/bin BIN_DIR := $(GOPATH)/bin
...@@ -15,16 +26,16 @@ GO_SOURCES = $(wildcard **/*.go) ...@@ -15,16 +26,16 @@ GO_SOURCES = $(wildcard **/*.go)
# ============================================================================= # =============================================================================
# build # build
# ============================================================================= # =============================================================================
build: dist/go-httpbin build: $(DIST_PATH)/go-httpbin
dist/go-httpbin: assets $(GO_SOURCES) $(DIST_PATH)/go-httpbin: assets $(GO_SOURCES)
mkdir -p dist mkdir -p $(DIST_PATH)
go build -o dist/go-httpbin ./cmd/go-httpbin go build -o $(DIST_PATH)/go-httpbin ./cmd/go-httpbin
assets: $(GENERATED_ASSETS_PATH) assets: $(GENERATED_ASSETS_PATH)
clean: clean:
rm -r dist rm -rf $(DIST_PATH) $(COVERAGE_PATH)
$(GENERATED_ASSETS_PATH): $(GOBINDATA) static/* $(GENERATED_ASSETS_PATH): $(GOBINDATA) static/*
$(GOBINDATA) -o $(GENERATED_ASSETS_PATH) -pkg=assets -prefix=static static $(GOBINDATA) -o $(GENERATED_ASSETS_PATH) -pkg=assets -prefix=static static
...@@ -42,10 +53,14 @@ $(GENERATED_ASSETS_PATH): $(GOBINDATA) static/* ...@@ -42,10 +53,14 @@ $(GENERATED_ASSETS_PATH): $(GOBINDATA) static/*
test: test:
go test $(TEST_ARGS) ./... go test $(TEST_ARGS) ./...
testcover: # Test command to run for continuous integration, which includes code coverage
mkdir -p dist # based on codecov.io's documentation:
go test $(TEST_ARGS) -coverprofile=dist/coverage.out github.com/mccutchen/go-httpbin/httpbin # https://github.com/codecov/example-go/blob/b85638743b972bd0bd2af63421fe513c6f968930/README.md
go tool cover -html=dist/coverage.out testci:
go test $(TEST_ARGS) $(COVERAGE_ARGS) ./...
testcover: testci
go tool cover -html=$(COVERAGE_PATH)
lint: $(GOLINT) lint: $(GOLINT)
test -z "$$(gofmt -d -s -e .)" || (gofmt -d -s -e . ; exit 1) test -z "$$(gofmt -d -s -e .)" || (gofmt -d -s -e . ; exit 1)
...@@ -63,7 +78,7 @@ stagedeploy: build ...@@ -63,7 +78,7 @@ stagedeploy: build
gcloud app deploy --quiet --project=$(GCLOUD_PROJECT) --version=$(VERSION) --no-promote gcloud app deploy --quiet --project=$(GCLOUD_PROJECT) --version=$(VERSION) --no-promote
run: build run: build
./dist/go-httpbin $(DIST_PATH)/go-httpbin
# ============================================================================= # =============================================================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment