Skip to content

Commit 2e73048

Browse files
committed
Add Makefile
- 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
1 parent 6cd13fa commit 2e73048

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+16760
-2
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# vendor/
1717

1818
### Go Patch ###
19-
/vendor/
2019
/Godeps/
2120

2221

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ env:
88
- GO111MODULE=on
99

1010
script:
11-
- go test -v -race -cover ./...
11+
- make test-cover-html
12+
- make build

Makefile

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
.PHONY: help
2+
help: ## Prints help (only for targets with comments)
3+
@grep -E '^[a-zA-Z._-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
4+
5+
SRC_PACKAGES=$(shell go list -mod=vendor ./... | grep -v "vendor")
6+
BUILD?=$(shell git describe --always --dirty 2> /dev/null)
7+
GOLINT:=$(shell command -v golint 2> /dev/null)
8+
RICHGO=$(shell command -v richgo 2> /dev/null)
9+
GOMETA_LINT=$(shell command -v golangci-lint 2> /dev/null)
10+
GOLANGCI_LINT_VERSION=v1.20.0
11+
GO111MODULE=on
12+
SHELL=bash -o pipefail
13+
14+
ifeq ($(GOMETA_LINT),)
15+
GOMETA_LINT=$(shell command -v $(PWD)/bin/golangci-lint 2> /dev/null)
16+
endif
17+
18+
ifeq ($(RICHGO),)
19+
GO_BINARY=go
20+
else
21+
GO_BINARY=richgo
22+
endif
23+
24+
ifeq ($(BUILD),)
25+
BUILD=dev
26+
endif
27+
28+
ifdef CI_COMMIT_SHORT_SHA
29+
BUILD=$(CI_COMMIT_SHORT_SHA)
30+
endif
31+
32+
all: setup build
33+
34+
ci: setup-common build-common
35+
36+
ensure-build-dir:
37+
mkdir -p out
38+
39+
build-deps: ## Install dependencies
40+
go get
41+
go mod tidy
42+
go mod vendor
43+
44+
update-deps: ## Update dependencies
45+
go get -u
46+
47+
compile: compile-app ## Compile library
48+
49+
compile-app: ensure-build-dir
50+
$(GO_BINARY) build -mod=vendor ...
51+
52+
build: fmt build-common ## Build the library
53+
54+
build-common: vet lint-all test compile
55+
56+
fmt:
57+
GOFLAGS="-mod=vendor" $(GO_BINARY) fmt $(SRC_PACKAGES)
58+
59+
vet:
60+
$(GO_BINARY) vet -mod=vendor $(SRC_PACKAGES)
61+
62+
setup-common:
63+
ifeq ($(GOMETA_LINT),)
64+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s $(GOLANGCI_LINT_VERSION)
65+
endif
66+
ifeq ($(GOLINT),)
67+
GO111MODULE=off $(GO_BINARY) get -u golang.org/x/lint/golint
68+
endif
69+
70+
setup-richgo:
71+
ifeq ($(RICHGO),)
72+
GO111MODULE=off $(GO_BINARY) get -u github.com/kyoh86/richgo
73+
endif
74+
75+
setup: setup-richgo setup-common ensure-build-dir ## Setup environment
76+
77+
lint-all: lint setup-common
78+
$(GOMETA_LINT) run
79+
80+
target:
81+
for number in 1 2 3 4 ; do \
82+
echo $$number ; \
83+
done
84+
85+
lint:
86+
golint $(SRC_PACKAGES)
87+
88+
test: ensure-build-dir ## Run tests
89+
ENVIRONMENT=test $(GO_BINARY) test -mod=vendor $(SRC_PACKAGES) -race -coverprofile ./out/coverage -short -v | grep -viE "start|no test files"
90+
91+
test-cover-html: ## Run tests with coverage
92+
mkdir -p ./out
93+
@echo "mode: count" > coverage-all.out
94+
$(foreach pkg, $(SRC_PACKAGES),\
95+
ENVIRONMENT=test $(GO_BINARY) test -mod=vendor -coverprofile=coverage.out -covermode=count $(pkg);\
96+
tail -n +2 coverage.out >> coverage-all.out;)
97+
$(GO_BINARY) tool cover -html=coverage-all.out -o out/coverage.html
98+
99+
generate-test-summary:
100+
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; \
101+
sed -i '' -E "s/^(.+\| {)/{/" test-summary.json; \
102+
passed=`cat test-summary.json | jq | rg '"Action": "pass"' | wc -l`; \
103+
skipped=`cat test-summary.json | jq | rg '"Action": "skip"' | wc -l`; \
104+
failed=`cat test-summary.json | jq | rg '"Action": "fail"' | wc -l`; \
105+
echo "Passed: $$passed | Failed: $$failed | Skipped: $$skipped"

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,10 @@ func main() {
139139
fmt.Println(output) // prints 45
140140
}
141141
```
142+
## Build
143+
144+
To build godash locally
145+
146+
```bash
147+
make build
148+
```

vendor/github.com/davecgh/go-spew/LICENSE

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypass.go

+152
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)