Skip to content

Commit

Permalink
sync with template
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Jun 3, 2020
1 parent 26851c8 commit 9654aab
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.travis.yml export-ignore

/.github/ export-ignore
/githooks/ export-ignore

Makefile export-ignore
*.md export-ignore
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ go:
- 1.13.x
- 1.14.x

go_import_path: github.com/kamilsk/tracer

jobs:
allow_failures:
- go: master
Expand Down
65 changes: 44 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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 \
Expand All @@ -76,17 +81,17 @@ 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 \
go get -d -u ./...; \
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 \
Expand Down Expand Up @@ -121,31 +126,49 @@ 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 \
golang:$(1) bash
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
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
5 changes: 5 additions & 0 deletions githooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

make deps hooks
6 changes: 6 additions & 0 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail

make deps-tidy deps-fetch lint format
git diff --quiet --exit-code
6 changes: 6 additions & 0 deletions githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail

make generate
git diff --quiet --exit-code

0 comments on commit 9654aab

Please sign in to comment.