Skip to content

Commit

Permalink
Add Makefile
Browse files Browse the repository at this point in the history
- resue the build steps locally and in travis-ci
- avoid passing same argument all the time for running test
- avoid running multiple commands
  - golint
  - golancli-lint
  - go test
  - build
- use vendor for faster build
  • Loading branch information
jskswamy committed Oct 13, 2019
1 parent 6cd13fa commit 0a8c3fa
Show file tree
Hide file tree
Showing 47 changed files with 16,761 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# vendor/

### Go Patch ###
/vendor/
/Godeps/


Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ env:
- GO111MODULE=on

script:
- go test -v -race -cover ./...
- make setup-common
- make test-cover-html
- make build
105 changes: 105 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
.PHONY: help
help: ## Prints help (only for targets with comments)
@grep -E '^[a-zA-Z._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

SRC_PACKAGES=$(shell go list -mod=vendor ./... | grep -v "vendor")
BUILD?=$(shell git describe --always --dirty 2> /dev/null)
GOLINT:=$(shell command -v golint 2> /dev/null)
RICHGO=$(shell command -v richgo 2> /dev/null)
GOMETA_LINT=$(shell command -v golangci-lint 2> /dev/null)
GOLANGCI_LINT_VERSION=v1.20.0
GO111MODULE=on
SHELL=bash -o pipefail

ifeq ($(GOMETA_LINT),)
GOMETA_LINT=$(shell command -v $(PWD)/bin/golangci-lint 2> /dev/null)
endif

ifeq ($(RICHGO),)
GO_BINARY=go
else
GO_BINARY=richgo
endif

ifeq ($(BUILD),)
BUILD=dev
endif

ifdef CI_COMMIT_SHORT_SHA
BUILD=$(CI_COMMIT_SHORT_SHA)
endif

all: setup build

ci: setup-common build-common

ensure-build-dir:
mkdir -p out

build-deps: ## Install dependencies
go get
go mod tidy
go mod vendor

update-deps: ## Update dependencies
go get -u

compile: compile-app ## Compile library

compile-app: ensure-build-dir
$(GO_BINARY) build -mod=vendor ...

build: fmt build-common ## Build the library

build-common: vet lint-all test compile

fmt:
GOFLAGS="-mod=vendor" $(GO_BINARY) fmt $(SRC_PACKAGES)

vet:
$(GO_BINARY) vet -mod=vendor $(SRC_PACKAGES)

setup-common:
ifeq ($(GOMETA_LINT),)
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s $(GOLANGCI_LINT_VERSION)
endif
ifeq ($(GOLINT),)
GO111MODULE=off $(GO_BINARY) get -u golang.org/x/lint/golint
endif

setup-richgo:
ifeq ($(RICHGO),)
GO111MODULE=off $(GO_BINARY) get -u github.com/kyoh86/richgo
endif

setup: setup-richgo setup-common ensure-build-dir ## Setup environment

lint-all: lint setup-common
$(GOMETA_LINT) run

target:
for number in 1 2 3 4 ; do \
echo $$number ; \
done

lint:
golint $(SRC_PACKAGES)

test: ensure-build-dir ## Run tests
ENVIRONMENT=test $(GO_BINARY) test -mod=vendor $(SRC_PACKAGES) -race -coverprofile ./out/coverage -short -v | grep -viE "start|no test files"

test-cover-html: ## Run tests with coverage
mkdir -p ./out
@echo "mode: count" > coverage-all.out
$(foreach pkg, $(SRC_PACKAGES),\
ENVIRONMENT=test $(GO_BINARY) test -mod=vendor -coverprofile=coverage.out -covermode=count $(pkg);\
tail -n +2 coverage.out >> coverage-all.out;)
$(GO_BINARY) tool cover -html=coverage-all.out -o out/coverage.html

generate-test-summary:
ENVIRONMENT=test $(GO_BINARY) test -mod=vendor $(SRC_PACKAGES) -race -coverprofile ./out/coverage -short -v -json | grep -viE "start|no test files" | tee test-summary.json; \
sed -i '' -E "s/^(.+\| {)/{/" test-summary.json; \
passed=`cat test-summary.json | jq | rg '"Action": "pass"' | wc -l`; \
skipped=`cat test-summary.json | jq | rg '"Action": "skip"' | wc -l`; \
failed=`cat test-summary.json | jq | rg '"Action": "fail"' | wc -l`; \
echo "Passed: $$passed | Failed: $$failed | Skipped: $$skipped"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,10 @@ func main() {
fmt.Println(output) // prints 45
}
```
## Build

To build godash locally

```bash
make build
```
15 changes: 15 additions & 0 deletions vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 152 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a8c3fa

Please sign in to comment.