diff --git a/.gitattributes b/.gitattributes index 2377930..67e2d68 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,6 +3,7 @@ .travis.yml export-ignore /.github/ export-ignore +/githooks/ export-ignore Makefile export-ignore *.md export-ignore diff --git a/.travis.yml b/.travis.yml index d569b2b..0cf580e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,6 @@ go: - 1.13.x - 1.14.x -go_import_path: github.com/kamilsk/tracer - jobs: allow_failures: - go: master diff --git a/Makefile b/Makefile index 893150a..f2ed051 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,22 @@ # sourced by https://github.com/octomation/makefiles .DEFAULT_GOAL = test-with-coverage +GIT_HOOKS = post-merge pre-commit +GO_VERSIONS = 1.11 1.12 1.13 1.14 -SHELL = /bin/bash -euo pipefail +SHELL := /bin/bash -euo pipefail # `explain set -euo pipefail` + +OS = $(shell uname -s | tr '[:upper:]' '[:lower:]') +ARCH = $(shell uname -m | tr '[:upper:]' '[:lower:]') GO111MODULE = on GOFLAGS = -mod=vendor GOPRIVATE = go.octolab.net GOPROXY = direct LOCAL = $(MODULE) -MODULE = `go list -m` -PACKAGES = `go list ./... 2> /dev/null` -PATHS = $(shell echo $(PACKAGES) | sed -e "s|$(MODULE)/\{0,1\}||g") +MODULE = `GO111MODULE=on go list -m $(GOFLAGS)` +PACKAGES = `GO111MODULE=on go list $(GOFLAGS) ./...` +PATHS = $(shell echo $(PACKAGES) | sed -e "s|$(MODULE)/||g" | sed -e "s|$(MODULE)|$(PWD)/*.go|g") TIMEOUT = 1s ifeq (, $(PACKAGES)) @@ -51,19 +56,19 @@ deps-check: deps-clean: @go clean -modcache -.PHONY: deps-shake -deps-shake: - @go mod tidy +.PHONY: deps-fetch +deps-fetch: + @go mod download @if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi -.PHONY: module-deps -module-deps: - @go mod download +.PHONY: deps-tidy +deps-tidy: + @go mod tidy @if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi -.PHONY: update -update: selector = '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -update: +.PHONY: deps-update +deps-update: selector = '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' +deps-update: @if command -v egg > /dev/null; then \ packages="`egg deps list`"; \ else \ @@ -76,8 +81,8 @@ update: fi; \ if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi -.PHONY: update-all -update-all: +.PHONY: deps-update-all +deps-update-all: @if [[ "`go version`" == *1.1[1-3]* ]]; then \ go get -d -mod= -u ./...; \ else \ @@ -85,8 +90,8 @@ update-all: fi; \ if [[ "`go env GOFLAGS`" =~ -mod=vendor ]]; then go mod vendor; fi -.PHONY: format -format: +.PHONY: go-fmt +go-fmt: @if command -v goimports > /dev/null; then \ goimports -local $(LOCAL) -ungroup -w $(PATHS); \ else \ @@ -121,10 +126,17 @@ test-with-coverage: test-with-coverage-profile: @go test -cover -covermode count -coverprofile c.out -timeout $(TIMEOUT) $(PACKAGES) +.PHONY: hooks +hooks: + @ls .git/hooks | grep -v .sample | sed 's|.*|.git/hooks/&|' | xargs rm -f || true + @for hook in $(GIT_HOOKS); do cp githooks/$$hook .git/hooks/; done + +ifdef GO_VERSIONS + define go_tpl .PHONY: go$(1) go$(1): - docker run \ + @docker run \ --rm -it \ -v $(PWD):/src \ -w /src \ @@ -132,20 +144,31 @@ go$(1): endef render_go_tpl = $(eval $(call go_tpl,$(version))) -$(foreach version,1.11 1.12 1.13 1.14,$(render_go_tpl)) +$(foreach version,$(GO_VERSIONS),$(render_go_tpl)) + +endif + +.PHONY: init +init: deps test lint hooks .PHONY: clean clean: deps-clean test-clean .PHONY: deps -deps: module-deps +deps: deps-fetch .PHONY: env env: go-env +.PHONY: format +format: go-fmt + .PHONY: generate generate: go-generate format .PHONY: refresh -refresh: deps-shake update deps generate format test +refresh: deps-tidy update deps generate format test + +.PHONY: update +update: deps-update diff --git a/README.md b/README.md index 9a928b3..781f762 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ func Do(ctx context.Context) { } ``` -Full description of the idea is available [here][design]. +A full description of the idea is available [here][design.page]. ## 🏆 Motivation @@ -118,8 +118,8 @@ made with ❤️ for everyone [awesome.page]: https://github.com/avelino/awesome-go#performance [awesome.icon]: https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg -[build.page]: https://travis-ci.org/kamilsk/tracer -[build.icon]: https://travis-ci.org/kamilsk/tracer.svg?branch=master +[build.page]: https://travis-ci.com/kamilsk/tracer +[build.icon]: https://travis-ci.com/kamilsk/tracer.svg?branch=master [coverage.page]: https://codeclimate.com/github/kamilsk/tracer/test_coverage [coverage.icon]: https://api.codeclimate.com/v1/badges/fb66449d1f5c64542377/test_coverage [design.page]: https://www.notion.so/octolab/tracer-098c6f9fe97b41dcac4a30074463dc8f?r=0b753cbf767346f5a6fd51194829a2f3 @@ -130,6 +130,3 @@ made with ❤️ for everyone [quality.icon]: https://goreportcard.com/badge/github.com/kamilsk/tracer [template.page]: https://github.com/octomation/go-module [template.icon]: https://img.shields.io/badge/template-go--module-blue - -[tmp.docs]: https://nicedoc.io/kamilsk/tracer?theme=dark -[tmp.history]: https://github.githistory.xyz/kamilsk/tracer/blob/master/README.md diff --git a/githooks/post-merge b/githooks/post-merge new file mode 100755 index 0000000..4287e9c --- /dev/null +++ b/githooks/post-merge @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -euo pipefail + +make deps hooks diff --git a/githooks/pre-commit b/githooks/pre-commit new file mode 100755 index 0000000..a573893 --- /dev/null +++ b/githooks/pre-commit @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -euo pipefail + +make deps-tidy deps-fetch lint format +git diff --quiet --exit-code diff --git a/githooks/pre-push b/githooks/pre-push new file mode 100755 index 0000000..8f23c55 --- /dev/null +++ b/githooks/pre-push @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -euo pipefail + +make generate +git diff --quiet --exit-code