From 2ca1da8c9ca51de6b1248fd0bf3dc105782d2add Mon Sep 17 00:00:00 2001 From: Matt Stofko Date: Thu, 23 May 2019 22:20:47 -0700 Subject: [PATCH] Adding make build process --- .travis.yml | 5 +++-- Makefile | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 12 +++++++++--- 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 Makefile diff --git a/.travis.yml b/.travis.yml index 27b2dca..2c34220 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,14 @@ env: go: - 1.12.x -gobuild_args: -v -coverprofile c.out - install: - GO111MODULE=off go get -v github.com/codeclimate/test-reporter before_script: - test-reporter before-build +script: + - make test + after_script: - test-reporter after-build --coverage-input-type gocov --exit-code $TRAVIS_TEST_RESULT diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8917ece --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +PKG := $(shell head -1 go.mod | sed -e 's/module //') +OUT := $(shell basename ${PKG}) +VERSION := $(shell git describe --tag --long --dirty) +PKG_LIST := $(shell go list ${PKG}/...) +GO_FILES := $(shell find . -name '*.go') + +all: build + +build: + go build -v -o ${OUT} -ldflags="-X main.version=${VERSION}" ${PKG} + +c.out: + go test -coverprofile=c.out -v ${PKG}/... + +test: c.out + +coverhtml: test + go tool cover -html=c.out + +vet: + @go vet ${PKG_LIST} + +lint: + @for file in ${GO_FILES} ; do \ + golint $$file ; \ + done + +static: vet lint + go build -v -o ${OUT}-${VERSION} -a \ + -tags netgo \ + -gcflags=all=-trimpath=${GOPATH} \ + -asmflags=all=-trimpath=${GOPATH} \ + -ldflags="-extldflags \"-static\" -w -s -X main.version=${VERSION}" \ + ${PKG} + +clean: + rm -f ${OUT} ${OUT}-v* c.out + +.PHONY: build test coverhtml vet lint static clean diff --git a/README.md b/README.md index 0f2efac..a94d8af 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,17 @@ authentication to an otherwise unsecured API, and easily adaptable to other auth Build and Test --- -Standard Go build and test methods apply. Uses modules (Go 1.11+). +This project uses Go and make to build and test. Go 1.11+ is required for the use of Go modules. ```bash -go test -cover ./... -go build -o auth-plug +# Run tests +make test + +# Run the standard build process +make build + +# Build a statically linked binary for release +make static ``` Configure and Run