diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ff1fe4e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Collapse vendored and generated files on GitHub +vendor/* linguist-vendored +rules.mk linguist-vendored +*/vendor/* linguist-vendored +*.gen.* linguist-generated +*.pb.go linguist-generated +go.sum linguist-generated +go.mod linguist-generated +gen.sum linguist-generated + +# Reduce conflicts on markdown files +*.md merge=union diff --git a/.gitignore b/.gitignore index 7d416d4..53b035e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,25 @@ -vendor/**/.travis.yml +# Temporary files +*~ +*# +.#* +coverage.txt -/protoc-gen-gotemplate - -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go +# Vendors +package-lock.json +node_modules/ +vendor/ +# Binaries for programs and plugins +dist/ +gin-bin *.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` *.test -*.prof + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..f692c65 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,28 @@ +# This file lists all individuals having contributed content to the repository. +# For how it is generated, see 'https://github.com/moul/rules.mk' + +Alexandre Beslic +Anastasia DERUELLE +Gero +gfanton +Guilhem Fanton +Jan Weitz +jhayotte +Julien Hayotte +Manfred Touron +Mathieu Acthernoene +Mike Lee +moul-bot <41326314+moul-bot@users.noreply.github.com> +Pat Moroney +Pat Moroney +Peter Monko +Pierre Roullon +Quentin Perez +Renovate Bot +Sacha Froment +Shogo Iwano +Thomas KERAMBLOCH +Tommy PAGEARD +Valerio Gheri +Victor Login +webii diff --git a/Makefile b/Makefile index 7395147..63e0e15 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ -.PHONY: build -build: - go build -v -i -o protoc-gen-gotemplate . +GOPKG ?= moul.io/protoc-gen-gotemplate +DOCKER_IMAGE ?= moul/golang-repo-template +GOBINS ?= . ./cmd/web-editor +GOLIBS ?= . -.PHONY: install -install: - go install . - go install ./cmd/web-editor +all: test install -.PHONY: test -test: install +include rules.mk + +.PHONY: examples +examples: install cd examples/time && make cd examples/enum && make cd examples/import && make @@ -18,19 +18,7 @@ test: install cd examples/flow && make cd examples/sitemap && make cd examples/go-generate && make -# cd examples/single-package-mode && make + #cd examples/single-package-mode && make cd examples/helpers && make cd examples/arithmetics && make -# cd examples/go-kit && make - -.PHONY: docker.build -docker.build: - docker build --pull -t moul/protoc-gen-gotemplate . - -.PHONY: docker.push -docker.push: docker.build - docker push moul/protoc-gen-gotemplate - -.PHONY: lint -lint: - golangci-lint run --verbose . ./helpers ./cmd/... + #cd examples/go-kit && make diff --git a/go.mod b/go.mod index cad2ec4..52811bd 100644 --- a/go.mod +++ b/go.mod @@ -19,3 +19,5 @@ require ( google.golang.org/genproto v0.0.0-20170517234824-bb3573be0c48 gopkg.in/yaml.v2 v2.2.2 // indirect ) + +go 1.13 diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 031be2c..0000000 --- a/renovate.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": [ - "config:base" - ], - "groupName": "all" -} diff --git a/rules.mk b/rules.mk new file mode 100644 index 0000000..020d7aa --- /dev/null +++ b/rules.mk @@ -0,0 +1,270 @@ +# +--------------------------------------------------------------+ +# | * * * moul.io/rules.mk | +# +--------------------------------------------------------------+ +# | | +# | ++ ______________________________________ | +# | ++++ / \ | +# | ++++ | | | +# | ++++++++++ | https://moul.io/rules.mk is a set | | +# | +++ | | of common Makefile rules that can | | +# | ++ | | be configured from the Makefile | | +# | + -== ==| | or with environment variables. | | +# | ( <*> <*> | | | +# | | | /| Manfred Touron | | +# | | _) / | manfred.life | | +# | | +++ / \______________________________________/ | +# | \ =+ / | +# | \ + | +# | |\++++++ | +# | | ++++ ||// | +# | ___| |___ _||/__ __| +# | / --- \ \| ||| __ _ ___ __ __/ /| +# |/ | | \ \ / / ' \/ _ \/ // / / | +# || | | | | | /_/_/_/\___/\_,_/_/ | +# +--------------------------------------------------------------+ + +all: help + +## +## Common helpers +## + +rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + +## +## rules.mk +## +ifneq ($(wildcard rules.mk),) +.PHONY: rulesmk.bumpdeps +rulesmk.bumpdeps: + wget -O rules.mk https://raw.githubusercontent.com/moul/rules.mk/master/rules.mk +BUMPDEPS_STEPS += rulesmk.bumpdeps +endif + +## +## Maintainer +## + +ifneq ($(wildcard .git/HEAD),) +.PHONY: generate.authors +generate.authors: AUTHORS +AUTHORS: .git/ + echo "# This file lists all individuals having contributed content to the repository." > AUTHORS + echo "# For how it is generated, see 'https://github.com/moul/rules.mk'" >> AUTHORS + echo >> AUTHORS + git log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf >> AUTHORS +GENERATE_STEPS += generate.authors +endif + +## +## Golang +## + +ifndef GOPKG +ifneq ($(wildcard go.mod),) +GOPKG = $(shell sed '/module/!d;s/^omdule\ //' go.mod) +endif +endif +ifdef GOPKG +GO ?= go +GOPATH ?= $(HOME)/go +GOLIBS ?= $(shell find . -type f -name "go.mod" | grep -v /vendor/ | sed 's@/[^/]*$$@@' | sort | uniq) +GO_INSTALL_OPTS ?= +GO_TEST_OPTS ?= -test.timeout=30s + +ifdef GOBINS +.PHONY: go.install +go.install: + @set -e; for dir in $(GOBINS); do ( set -xe; \ + cd $$dir; \ + $(GO) install $(GO_INSTALL_OPTS) .; \ + ); done +INSTALL_STEPS += go.install + +.PHONY: go.release +go.release: + goreleaser --snapshot --skip-publish --rm-dist + @echo -n "Do you want to release? [y/N] " && read ans && \ + if [ $${ans:-N} = y ]; then set -xe; goreleaser --rm-dist; fi +RELEASE_STEPS += go.release +endif + +.PHONY: go.unittest coverage.txt +go.unittest: coverage.txt +coverage.txt: + @rm -f /tmp/coverage.txt + @touch /tmp/coverage.txt + @set -e; for dir in $(GOLIBS); do ( set -xe; \ + cd $$dir; \ + $(GO) test $(GO_TEST_OPTS) -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \ + if [ -f /tmp/profile.out ]; then \ + cat /tmp/profile.out >> /tmp/coverage.txt; \ + rm -f /tmp/profile.out; \ + fi); done + mv /tmp/coverage.txt . + +.PHONY: go.coverfunc +go.coverfunc: coverage.txt + go tool cover -func=./coverage.txt | grep -v .pb.go: | grep -v .pb.gw.go: + +.PHONY: go.lint +go.lint: + @set -e; for dir in $(GOLIBS); do ( set -xe; \ + cd $$dir; \ + golangci-lint run --verbose ./...; \ + ); done + +.PHONY: go.tidy +go.tidy: + @set -e; for dir in $(GOLIBS); do ( set -xe; \ + cd $$dir; \ + $(GO) mod tidy; \ + ); done + +.PHONY: go.build +go.build: + @set -e; for dir in $(GOLIBS); do ( set -xe; \ + cd $$dir; \ + $(GO) build ./...; \ + ); done + +.PHONY: go.bump-deps +go.bumpdeps: + @set -e; for dir in $(GOLIBS); do ( set -xe; \ + cd $$dir; \ + $(GO) get -u ./...; \ + ); done + +.PHONY: go.bump-deps +go.fmt: + if ! command -v goimports &>/dev/null; then GO111MODULE=off go get golang.org/x/tools/cmd/goimports; fi + @set -e; for dir in $(GOLIBS); do ( set -xe; \ + cd $$dir; \ + goimports -w . \ + ); done + +BUILD_STEPS += go.build +BUMPDEPS_STEPS += go.bumpdeps +TIDY_STEPS += go.tidy +LINT_STEPS += go.lint +UNITTEST_STEPS += go.unittest +FMT_STEPS += go.fmt +endif + +## +## Node +## + +ifndef NPM_PACKAGES +ifneq ($(wildcard package.json),) +NPM_PACKAGES = . +endif +endif +ifdef NPM_PACKAGES +.PHONY: npm.publish +npm.publish: + @echo -n "Do you want to npm publish? [y/N] " && read ans && \ + @if [ $${ans:-N} = y ]; then \ + set -e; for dir in $(NPM_PACKAGES); do ( set -xe; \ + cd $$dir; \ + npm publish --access=public; \ + ); done; \ + fi +RELEASE_STEPS += npm.publish +endif + +## +## Docker +## + +ifndef DOCKER_IMAGE +ifneq ($(wildcard Dockerfile),) +DOCKER_IMAGE = $(notdir $(PWD)) +endif +endif +ifdef DOCKER_IMAGE +ifneq ($(DOCKER_IMAGE),none) +.PHONY: docker.build +docker.build: + docker build \ + --build-arg VCS_REF=`git rev-parse --short HEAD` \ + --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ + --build-arg VERSION=`git describe --tags --always` \ + -t $(DOCKER_IMAGE) . + +BUILD_STEPS += docker.build +endif +endif + +## +## Common +## + +TEST_STEPS += $(UNITTEST_STEPS) +TEST_STEPS += $(LINT_STEPS) +TEST_STEPS += $(TIDY_STEPS) + +ifneq ($(strip $(TEST_STEPS)),) +.PHONY: test +test: $(PRE_TEST_STEPS) $(TEST_STEPS) +endif + +ifdef INSTALL_STEPS +.PHONY: install +install: $(PRE_INSTALL_STEPS) $(INSTALL_STEPS) +endif + +ifdef UNITTEST_STEPS +.PHONY: unittest +unittest: $(PRE_UNITTEST_STEPS) $(UNITTEST_STEPS) +endif + +ifdef LINT_STEPS +.PHONY: lint +lint: $(PRE_LINT_STEPS) $(FMT_STEPS) $(LINT_STEPS) +endif + +ifdef TIDY_STEPS +.PHONY: tidy +tidy: $(PRE_TIDY_STEPS) $(TIDY_STEPS) +endif + +ifdef BUILD_STEPS +.PHONY: build +build: $(PRE_BUILD_STEPS) $(BUILD_STEPS) +endif + +ifdef RELEASE_STEPS +.PHONY: release +release: $(PRE_RELEASE_STEPS) $(RELEASE_STEPS) +endif + +ifdef BUMPDEPS_STEPS +.PHONY: bumpdeps +bumpdeps: $(PRE_BUMDEPS_STEPS) $(BUMPDEPS_STEPS) +endif + +ifdef FMT_STEPS +.PHONY: fmt +fmt: $(PRE_FMT_STEPS) $(FMT_STEPS) +endif + +ifdef GENERATE_STEPS +.PHONY: generate +generate: $(PRE_GENERATE_STEPS) $(GENERATE_STEPS) +endif + +.PHONY: help +help: + @echo "General commands:" + @[ "$(BUILD_STEPS)" != "" ] && echo " build" || true + @[ "$(BUMPDEPS_STEPS)" != "" ] && echo " bumpdeps" || true + @[ "$(FMT_STEPS)" != "" ] && echo " fmt" || true + @[ "$(GENERATE_STEPS)" != "" ] && echo " generate" || true + @[ "$(INSTALL_STEPS)" != "" ] && echo " install" || true + @[ "$(LINT_STEPS)" != "" ] && echo " lint" || true + @[ "$(RELEASE_STEPS)" != "" ] && echo " release" || true + @[ "$(TEST_STEPS)" != "" ] && echo " test" || true + @[ "$(TIDY_STEPS)" != "" ] && echo " tidy" || true + @[ "$(UNITTEST_STEPS)" != "" ] && echo " unittest" || true + @# FIXME: list other commands