Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makefile #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,11 @@ func main() {
fmt.Println(output) // prints true
}
```

## 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