Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5 from newrelic/jthurman/travis-ci
Browse files Browse the repository at this point in the history
Add travis-ci integration for build status
  • Loading branch information
Jonathan Thurman authored Jul 2, 2019
2 parents f0bd0fb + b2ac4ac commit c2b3aa3
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Application Specific
go-insights
bin/*
vendor/*

# Compiled Object files, Static and Dynamic libs (Shared Objects)
Expand Down
49 changes: 49 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 5m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true


# all available settings of specific linters
linters-settings:
govet:
# report about shadowed variables
check-shadowing: true
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.5
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 20
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/davecgh/go-spew/spew
misspell:
ignore-words:
- newrelic
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 150

linters:
enable-all: true
disable:
- dupl
- gochecknoglobals
- interfacer

5 changes: 0 additions & 5 deletions .gometalinter.json

This file was deleted.

4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: go

go:
- 1.x
115 changes: 70 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,108 +1,133 @@
PROJECT_NAME := $(shell basename $(shell pwd))
PROJECT_VER := $(shell git describe --tags --always --dirty)
GO_PKGS := $(shell go list ./... | grep -v -e "/vendor/" -e "/example")
GO_FILES := $(shell find ./ -type f -name "*.go")
NATIVEOS := $(shell go version | awk -F '[ /]' '{print $$4}')
NATIVEARCH := $(shell go version | awk -F '[ /]' '{print $$5}')
SRCDIR ?= .
BUILD_DIR := ./bin/
COVERAGE_DIR := ./coverage/
GOTOOLS = github.com/kardianos/govendor \
gopkg.in/alecthomas/gometalinter.v2 \
github.com/axw/gocov/gocov \
COVERMODE = atomic
GOTOOLS = github.com/axw/gocov/gocov \
github.com/AlekSi/gocov-xml \
github.com/stretchr/testify/assert \
github.com/robertkrimen/godocdown/godocdown \


GO = govendor
GODOC = godocdown
GOMETALINTER = gometalinter.v2
GOVENDOR = govendor
github.com/golangci/golangci-lint/cmd/golangci-lint

GO_CMD = go
GODOC = godocdown
DOC_DIR = ./docs/
GOLINTER = golangci-lint

# Determine package dep manager
ifneq ("$(wildcard Gopkg.toml)","")
VENDOR = dep
VENDOR_CMD = ${VENDOR} ensure
GOTOOLS += github.com/golang/dep
GO = ${GO_CMD}
else ifneq ("$(wildcard Godeps/*)","")
VENDOR = godep
VENDOR_CMD = echo "Not Implemented"
GOTOOLS += github.com/tools/godep
GO = godep go
else
VENDOR = govendor
VENDOR_CMD = ${VENDOR} sync
GOTOOLS += github.com/kardianos/govendor
GO = ${VENDOR}
endif

# Determine packages by looking into pkg/*
PACKAGES=client
ifneq ("$(wildcard ${SRCDIR}/pkg/*)","")
PACKAGES = $(wildcard ${SRCDIR}/pkg/*)
endif
ifneq ("$(wildcard ${SRCDIR}/internal/*)","")
PACKAGES += $(wildcard ${SRCDIR}/internal/*)
endif

# Determine commands by looking into cmd/*
COMMANDS=$(wildcard ${SRCDIR}/cmd/*)
COMMANDS = $(wildcard ${SRCDIR}/cmd/*)

GO_FILES := $(shell find $(COMMANDS) $(PACKAGES) -type f -name "*.go")

# Determine binary names by stripping out the dir names
BINS=$(foreach cmd,${COMMANDS},$(notdir ${cmd}))

#ifeq (${COMMANDS},)
# $(error Could not determine COMMANDS, set SRCDIR or run in source dir)
#endif
#ifeq (${BINS},)
# $(error Could not determine BINS, set SRCDIR or run in source dir)
#endif

LDFLAGS='-X main.Version=$(PROJECT_VER)'

all: build

build: check-version clean validate test coverage compile document
# Humans running make:
build: check-version clean validate test-unit cover-report compile document

# Build command for CI tooling
build-ci: check-version clean validate test compile-only

clean:
@echo "=== $(PROJECT_NAME) === [ clean ]: removing binaries and coverage file..."
@rm -rfv $(BUILD_DIR)/* $(COVERAGE_DIR)/*

tools: check-version
@echo "=== $(PROJECT_NAME) === [ tools ]: Installing tools required by the project..."
go get -u $(GOTOOLS)
@$(GOMETALINTER) --install
@$(GO_CMD) get $(GOTOOLS)

tools-update: check-version
@echo "=== $(PROJECT_NAME) === [ tools-update ]: Updating tools required by the project..."
@$(GO) get -u $(GOTOOLS)
@$(GOMETALINTER) --install
@$(GO_CMD) get -u $(GOTOOLS)

deps: tools deps-only

deps-only:
@echo "=== $(PROJECT_NAME) === [ deps ]: Installing package dependencies required by the project..."
@$(GOVENDOR) sync
@echo "=== $(PROJECT_NAME) === [ deps ]: Detected '$(VENDOR)'"
@$(VENDOR_CMD)

validate: deps
@echo "=== $(PROJECT_NAME) === [ validate ]: Validating source code running gometalinter..."
@$(GOMETALINTER) --config=.gometalinter.json ./...
@echo "=== $(PROJECT_NAME) === [ validate ]: Validating source code running $(GOLINTER)..."
@$(GOLINTER) run ./...

compile-only: deps-only
@echo "=== $(PROJECT_NAME) === [ compile ]: building commands:"
@for b in $(BINS); do \
echo "=== $(PROJECT_NAME) === [ compile ]: $$b"; \
BUILD_FILES=`find $(SRCDIR)/cmd/$$b -type f -name "*.go"` ; \
$(GO) build -o $(BUILD_DIR)/$$b $$BUILD_FILES ; \
$(GO) build -ldflags=$(LDFLAGS) -o $(BUILD_DIR)/$$b $$BUILD_FILES ; \
done

compile: deps compile-only

coverage:
@echo "=== $(PROJECT_NAME) === [ coverage ]: generating coverage results..."
@rm -rf $(COVERAGE_DIR)/*
@for d in $(GO_PKGS); do \
pkg=`basename $$d` ;\
$(GO) test -tags 'unit integration' -coverprofile $(COVERAGE_DIR)/$$pkg.tmp $$d ;\
done
@echo 'mode: set' > $(COVERAGE_DIR)/coverage.out
# || true to ignore grep return code if no matches (i.e. no tests written...)
@cat $(COVERAGE_DIR)/*.tmp | grep -v 'mode: set' >> $(COVERAGE_DIR)/coverage.out || true
@$(GO) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
test: test-deps test-only
test-only: test-unit test-integration

test-unit:
@echo "=== $(PROJECT_NAME) === [ unit-test ]: running unit tests..."
@$(GO) test -tags unit $(GO_PKGS)
@mkdir -p $(COVERAGE_DIR)
@$(GO) test -tags unit -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/unit.tmp $(GO_PKGS)

test-integration:
@echo "=== $(PROJECT_NAME) === [ integration-test ]: running integrtation tests..."
@$(GO) test -tags integration $(GO_PKGS)
@mkdir -p $(COVERAGE_DIR)
@$(GO) test -tags integration -covermode=$(COVERMODE) -coverprofile $(COVERAGE_DIR)/integration.tmp $(GO_PKGS)

cover-report:
@echo "=== $(PROJECT_NAME) === [ cover-report ]: generating coverage results..."
@mkdir -p $(COVERAGE_DIR)
@echo 'mode: $(COVERMODE)' > $(COVERAGE_DIR)/coverage.out
@cat $(COVERAGE_DIR)/*.tmp | grep -v 'mode: $(COVERMODE)' >> $(COVERAGE_DIR)/coverage.out || true
@$(GO) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@echo "=== $(PROJECT_NAME) === [ cover-report ]: $(COVERAGE_DIR)coverage.html"

document:
@echo "=== $(PROJECT_NAME) === [ documentation ]: Generating Godoc in Markdown..."
@for p in $(PACKAGES); do \
echo "=== $(PROJECT_NAME) === [ documentation ]: $$p"; \
$(GODOC) $$p > $$p/README.md ; \
mkdir -p $(DOC_DIR)/$$p ; \
$(GODOC) $$p > $(DOC_DIR)/$$p/README.md ; \
done
@for c in $(COMMANDS); do \
echo "=== $(PROJECT_NAME) === [ documentation ]: $$c"; \
mkdir -p $(DOC_DIR)/$$c ; \
$(GODOC) $$c > $(DOC_DIR)/$$c/README.md ; \
done

test-only: test-unit test-integration
test: test-deps test-only

check-version:
ifdef GOOS
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# New Relic Insights Client
A Go library for interacting with insights.

[![Build Status](https://travis-ci.org/newrelic/go-insights.svg?branch=master)](https://travis-ci.org/newrelic/go-insights)


## Disclaimer
New Relic has open-sourced this integration to enable monitoring of this technology. This integration is provided AS-IS WITHOUT WARRANTY OR SUPPORT, although you can report issues and contribute to this integration via GitHub. Support for this integration is available with an [Expert Services subscription](newrelic.com/expertservices).

Expand Down
5 changes: 0 additions & 5 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
"github.com/stretchr/testify/assert"
)

const (
testKey = "testKey"
testID = "12345"
)

func TestUseCustomURL(t *testing.T) {
c := &Client{
Logger: log.New(),
Expand Down
Loading

0 comments on commit c2b3aa3

Please sign in to comment.