diff --git a/.bingo/.gitignore b/.bingo/.gitignore new file mode 100755 index 000000000..4f2055b6e --- /dev/null +++ b/.bingo/.gitignore @@ -0,0 +1,12 @@ + +# Ignore everything +* + +# But not these files: +!.gitignore +!*.mod +!README.md +!Variables.mk +!variables.env + +*tmp.mod diff --git a/.bingo/README.md b/.bingo/README.md new file mode 100755 index 000000000..70f928603 --- /dev/null +++ b/.bingo/README.md @@ -0,0 +1,13 @@ +# Project Development Dependencies. + +This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo. + +* Run `bingo get` to install all tools having each own module file in this directory. +* Run `bingo get ` to install that have own module file in this directory. +* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $() variable where is the .bingo/.mod. +* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool +* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies. + +## Requirements + +* Go 1.14+ diff --git a/.bingo/Variables.mk b/.bingo/Variables.mk new file mode 100644 index 000000000..cf7c8a9fa --- /dev/null +++ b/.bingo/Variables.mk @@ -0,0 +1,54 @@ +# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.1. DO NOT EDIT. +# All tools are designed to be build inside $GOBIN. +GOPATH ?= $(shell go env GOPATH) +GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin +GO ?= $(shell which go) + +# Bellow generated variables ensure that every time a tool under each variable is invoked, the correct version +# will be used; reinstalling only if needed. +# For example for bingo variable: +# +# In your main Makefile (for non array binaries): +# +#include .bingo/Variables.mk # Assuming -dir was set to .bingo . +# +#command: $(BINGO) +# @echo "Running bingo" +# @$(BINGO) +# +BINGO := $(GOBIN)/bingo-v0.2.1 +$(BINGO): .bingo/bingo.mod + @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. + @echo "(re)installing $(GOBIN)/bingo-v0.2.1" + @cd .bingo && $(GO) build -modfile=bingo.mod -o=$(GOBIN)/bingo-v0.2.1 "github.com/bwplotka/bingo" + +FAILLINT := $(GOBIN)/faillint-v1.5.0 +$(FAILLINT): .bingo/faillint.mod + @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. + @echo "(re)installing $(GOBIN)/faillint-v1.5.0" + @cd .bingo && $(GO) build -modfile=faillint.mod -o=$(GOBIN)/faillint-v1.5.0 "github.com/fatih/faillint" + +GOIMPORTS := $(GOBIN)/goimports-v0.0.0-20200529172331-a64b76657301 +$(GOIMPORTS): .bingo/goimports.mod + @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. + @echo "(re)installing $(GOBIN)/goimports-v0.0.0-20200529172331-a64b76657301" + @cd .bingo && $(GO) build -modfile=goimports.mod -o=$(GOBIN)/goimports-v0.0.0-20200529172331-a64b76657301 "golang.org/x/tools/cmd/goimports" + +GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.27.0 +$(GOLANGCI_LINT): .bingo/golangci-lint.mod + @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. + @echo "(re)installing $(GOBIN)/golangci-lint-v1.27.0" + @cd .bingo && $(GO) build -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.27.0 "github.com/golangci/golangci-lint/cmd/golangci-lint" + +MISSPELL := $(GOBIN)/misspell-v0.3.4 +$(MISSPELL): .bingo/misspell.mod + @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. + @echo "(re)installing $(GOBIN)/misspell-v0.3.4" + @cd .bingo && $(GO) build -modfile=misspell.mod -o=$(GOBIN)/misspell-v0.3.4 "github.com/client9/misspell/cmd/misspell" + +PROTOC_GEN_GOGOFAST := $(GOBIN)/protoc-gen-gogofast-v1.3.1 +$(PROTOC_GEN_GOGOFAST): .bingo/protoc-gen-gogofast.mod + @# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. + @echo "(re)installing $(GOBIN)/protoc-gen-gogofast-v1.3.1" + @cd .bingo && $(GO) build -modfile=protoc-gen-gogofast.mod -o=$(GOBIN)/protoc-gen-gogofast-v1.3.1 "github.com/gogo/protobuf/protoc-gen-gogofast" + diff --git a/.bingo/bingo.mod b/.bingo/bingo.mod new file mode 100644 index 000000000..68c171eac --- /dev/null +++ b/.bingo/bingo.mod @@ -0,0 +1,5 @@ +module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT + +go 1.14 + +require github.com/bwplotka/bingo v0.2.1 diff --git a/.bingo/faillint.mod b/.bingo/faillint.mod new file mode 100644 index 000000000..304af0e48 --- /dev/null +++ b/.bingo/faillint.mod @@ -0,0 +1,5 @@ +module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT + +go 1.14 + +require github.com/fatih/faillint v1.5.0 diff --git a/.bingo/go.mod b/.bingo/go.mod new file mode 100755 index 000000000..610249af0 --- /dev/null +++ b/.bingo/go.mod @@ -0,0 +1 @@ +module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files. \ No newline at end of file diff --git a/.bingo/goimports.mod b/.bingo/goimports.mod new file mode 100644 index 000000000..20e616bec --- /dev/null +++ b/.bingo/goimports.mod @@ -0,0 +1,5 @@ +module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT + +go 1.14 + +require golang.org/x/tools v0.0.0-20200529172331-a64b76657301 // cmd/goimports diff --git a/.bingo/golangci-lint.mod b/.bingo/golangci-lint.mod new file mode 100644 index 000000000..b4460743e --- /dev/null +++ b/.bingo/golangci-lint.mod @@ -0,0 +1,8 @@ +module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT + +go 1.14 + +require ( + github.com/golangci/golangci-lint v1.27.0 // cmd/golangci-lint + github.com/securego/gosec v0.0.0-20200316084457-7da9f46445fd // indirect +) diff --git a/.bingo/misspell.mod b/.bingo/misspell.mod new file mode 100644 index 000000000..60c1adc75 --- /dev/null +++ b/.bingo/misspell.mod @@ -0,0 +1,5 @@ +module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT + +go 1.14 + +require github.com/client9/misspell v0.3.4 // cmd/misspell diff --git a/.bingo/protoc-gen-gogofast.mod b/.bingo/protoc-gen-gogofast.mod new file mode 100644 index 000000000..c596d0970 --- /dev/null +++ b/.bingo/protoc-gen-gogofast.mod @@ -0,0 +1,5 @@ +module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT + +go 1.14 + +require github.com/gogo/protobuf v1.3.1 // protoc-gen-gogofast diff --git a/.bingo/variables.env b/.bingo/variables.env new file mode 100644 index 000000000..45ffed931 --- /dev/null +++ b/.bingo/variables.env @@ -0,0 +1,22 @@ +# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.1. DO NOT EDIT. +# All tools are designed to be build inside $GOBIN. +# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk. +local gobin=$(go env GOBIN) + +if [ -z "$gobin" ]; then + gobin="$(go env GOPATH)/bin" +fi + + +BINGO="${gobin}/bingo-v0.2.1" + +FAILLINT="${gobin}/faillint-v1.5.0" + +GOIMPORTS="${gobin}/goimports-v0.0.0-20200529172331-a64b76657301" + +GOLANGCI_LINT="${gobin}/golangci-lint-v1.27.0" + +MISSPELL="${gobin}/misspell-v0.3.4" + +PROTOC_GEN_GOGOFAST="${gobin}/protoc-gen-gogofast-v1.3.1" + diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..e94cac7d0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,15 @@ + + +**Go version used**: + +**What happened**: + +**What you expected to happen**: + +**How to reproduce it (as minimally and precisely as possible)**: + +--> diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..3dc1db3ed --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ + + + + +* [ ] I added CHANGELOG entry for this change. +* [ ] Change is not relevant to the end user. + +## Changes + + + +## Verification + + diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 000000000..cf47521e9 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,50 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) +onlyLabels: [] + +# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable. +# We want stale bot to notify us that something is stale so we can revisit it. +# If one issue is marked as 'reminder' by the reminder bot, we don't mark it as 'stale' again. +exemptLabels: + # This label is hardcoded on remind bot (https://probot.github.io/apps/reminders/) and is used by remind bot when + # issue is being reminded. + - reminder + +# Set to true to ignore issues in a project (defaults to false) +exemptProjects: false +# Set to true to ignore issues in a milestone (defaults to false) +exemptMilestones: false +# Set to true to ignore issues with an assignee (defaults to false) +exemptAssignees: false +# Label to use when marking as stale +staleLabel: stale + +pull: + daysUntilClose: 14 + daysUntilStale: 30 + markComment: > + Hello 👋 Looks like there was no activity on this amazing PR for the last month. + + **Do you mind updating us on the status?** Is there anything we can help with? If you plan to still work on it, just comment on this PR or push a commit. Thanks! 🤗 + + If there is no activity for the next 2 weeks, this PR will be closed (we can always reopen a PR if you get back to this!). + #unmarkComment: No need for unmark comment. + closeComment: > + Closing for now as promised, let us know if you need this to be reopened! 🤗 + +issues: + daysUntilClose: 14 + daysUntilStale: 60 + markComment: > + Hello 👋 Looks like there was no activity on this issue for the last 2 months. + + **Do you mind updating us on the status?** Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 + + If there is no activity for the next 2 weeks, this issue will be closed (we can always reopen an issue if requested!). + #unmarkComment: No need for unmark comment. + closeComment: > + Closing for now as promised, let us know if you need this to be reopened! 🤗 + +# Limit the number of actions per hour, from 1-30. Default is 30 +limitPerRun: 30 diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml new file mode 100644 index 000000000..e92d73989 --- /dev/null +++ b/.github/workflows/go.yaml @@ -0,0 +1,57 @@ +name: go + +on: + push: + branches: + - master + tags: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + name: Linters (Static Analysis) for Go + steps: + - name: Checkout code into the Go module directory. + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: Linting & vetting. + run: make lint + + tests: + runs-on: ${{ matrix.platform }} + name: Unit tests on Go ${{ matrix.go }} + strategy: + fail-fast: false + matrix: + go: [ '1.12.x', '1.13.x', '1.14.x' ] + platform: [ubuntu-latest, macos-latest] + steps: + - name: Checkout code into the Go module directory. + uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: Run unit tests. + run: make test + + - name: Calculating code coverage. + run: bash <(curl -s https://codecov.io/bash) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e46032fc2..000000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -sudo: false -language: go -go: - - 1.11.x - - 1.12.x - - 1.13.x - -env: - global: - - GO111MODULE=on - -script: - - make test - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index e1e923fe5..5249f24db 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,67 @@ +include .bingo/Variables.mk SHELL=/bin/bash -GODIRS_NOVENDOR ?= $(shell go list ./... | grep -v /vendor/) -GOFILES_NOVENDOR ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print) +PROVIDER_MODULES ?= $(shell ls -d $(PWD)/providers/*) +MODULES ?= $(PROVIDER_MODULES) $(PWD)/ -GOPATH ?= $(shell go env GOPATH) GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin + GO111MODULE ?= on export GO111MODULE GOPROXY ?= https://proxy.golang.org export GOPROXY -# TODO(bwplotka): Auto install using separate go.mod for tools. -GOIMPORTS ?= $(GOBIN)/goimports +.PHONY: fmt +fmt: + @echo "Running fmt for all modules: ${MODULES}" + @$(GOIMPORTS) -local github.com/grpc-ecosystem/go-grpc-middleware/v2 -w ${MODULES} -all: vet fmt test +.PHONY: proto +proto: $(PROTOC_GEN_GOGOFAST) $(GOIMPORTS) $(PROTOC) ./grpctesting/testpb/test.proto + @GOIMPORTS_BIN="$(GOIMPORTS)" PROTOC_BIN="$(PROTOC)" scripts/genproto.sh -fmt: - go fmt $(GODIRS_NOVENDOR) - @$(GOIMPORTS) -local github.com/grpc-ecosystem/go-grpc-middleware/v2 -w ${GOFILES_NOVENDOR} - -vet: - # Do not check lostcancel, they are intentional. - # TODO(bwplotka): Explain why intentional. - go vet -lostcancel=false $(GODIRS_NOVENDOR) - -proto: ./grpctesting/testpb/test.proto - @scripts/genproto.sh - -# TODO(bwplotka): This depends on test_proto, but CI does not have it, so let's skip it for now. -test: vet - cd ./providers/kit/ && go test -v -race ./... - cd ./providers/logrus/ && go test -v -race ./... - cd ./providers/zap/ && go test -v -race ./... - cd ./providers/zerolog/ && go test -v -race ./... +.PHONY: test +test: + @echo "Running tests for all modules: ${MODULES}" + @$(foreach dir,$(PROVIDER_MODULES),$(MAKE) test_module DIR=$(dir)) ./scripts/test_all.sh -.PHONY: all test +.PHONY: test_module +test_module: + cd $(DIR) && go test -v -race ./... + +.PHONY: lint +lint: fmt + @echo "Running lint for all modules: ${MODULES}" + @$(foreach dir,$(MODULES),$(MAKE) lint_module DIR=$(dir)) + +.PHONY: lint_module +# PROTIP: +# Add +# --cpu-profile-path string Path to CPU profile output file +# --mem-profile-path string Path to memory profile output file +# to debug big allocations during linting. +lint: ## Runs various static analysis against our code. +lint_module: $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL) + $(call require_clean_work_tree,"detected not clean master before running lint") + @echo ">> verifying modules being imported" + @$(FAILLINT) -paths "errors=github.com/pkg/errors,fmt.{Print,Printf,Println,Sprint}" ./... + @echo ">> examining all of the Go files" + @go vet -stdmethods=false ./... + @echo ">> linting all of the Go files GOGC=${GOGC}" + @$(GOLANGCI_LINT) run + @echo ">> detecting misspells" + @find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error + @echo ">> detecting white noise" + @find . -type f \( -name "*.md" -o -name "*.go" \) | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh + @echo ">> ensuring generated proto files are up to date" + @$(MAKE) proto + $(call require_clean_work_tree,"detected white noise or/and files without copyright; run 'make lint' file and commit changes.") + +$(PROTOC): + @mkdir -p $(TMP_GOPATH) + @echo ">> fetching protoc@${PROTOC_VERSION}" + @PROTOC_VERSION="$(PROTOC_VERSION)" TMP_GOPATH="$(TMP_GOPATH)" scripts/installprotoc.sh + @echo ">> installing protoc@${PROTOC_VERSION}" + @mv -- "$(TMP_GOPATH)/bin/protoc" "$(GOBIN)/protoc-$(PROTOC_VERSION)" + @echo ">> produced $(GOBIN)/protoc-$(PROTOC_VERSION)" \ No newline at end of file diff --git a/auth/examples_test.go b/auth/examples_test.go index 7f568b3a9..a156e4761 100644 --- a/auth/examples_test.go +++ b/auth/examples_test.go @@ -6,8 +6,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" pb "google.golang.org/grpc/examples/helloworld/helloworld" + "google.golang.org/grpc/status" "github.com/grpc-ecosystem/go-grpc-middleware/v2/auth" "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags" diff --git a/providers/kit/go.mod b/providers/kit/go.mod index dbb83484a..3a766d76f 100644 --- a/providers/kit/go.mod +++ b/providers/kit/go.mod @@ -1,4 +1,4 @@ -module github.com/grpc-ecosystem/go-grpc-middleware/v2/providers/kit +module github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2 go 1.14 diff --git a/providers/logrus/go.mod b/providers/logrus/go.mod index 4037aacb0..7d99f1fdc 100644 --- a/providers/logrus/go.mod +++ b/providers/logrus/go.mod @@ -1,4 +1,4 @@ -module github.com/grpc-ecosystem/go-grpc-middleware/v2/providers/logrus +module github.com/grpc-ecosystem/go-grpc-middleware/providers/logrus/v2 go 1.14 diff --git a/providers/zap/go.mod b/providers/zap/go.mod index f2904456c..604d03952 100644 --- a/providers/zap/go.mod +++ b/providers/zap/go.mod @@ -1,4 +1,4 @@ -module github.com/grpc-ecosystem/go-grpc-middleware/v2/providers/zap +module github.com/grpc-ecosystem/go-grpc-middleware/providers/zap/v2 go 1.14 diff --git a/providers/zerolog/go.mod b/providers/zerolog/go.mod index b39acb0b9..7aa781af8 100644 --- a/providers/zerolog/go.mod +++ b/providers/zerolog/go.mod @@ -1,4 +1,4 @@ -module github.com/grpc-ecosystem/go-grpc-middleware/v2/providers/zerolog +module github.com/grpc-ecosystem/go-grpc-middleware/providers/zerolog/v2 go 1.14 diff --git a/scripts/genproto.sh b/scripts/genproto.sh index 3f05149dc..7caf77eec 100755 --- a/scripts/genproto.sh +++ b/scripts/genproto.sh @@ -13,10 +13,7 @@ if ! [[ "$0" =~ "scripts/genproto.sh" ]]; then exit 255 fi -echo "installing gogofast" -GO111MODULE=on go install "github.com/gogo/protobuf/protoc-gen-gogofast" - -GOGOPROTO_ROOT="$(GO111MODULE=on go list -f '{{ .Dir }}' -m github.com/gogo/protobuf)" +GOGOPROTO_ROOT="$(GO111MODULE=on go list -modfile=.bingo/protoc-gen-gogofast.mod -f '{{ .Dir }}' -m github.com/gogo/protobuf)" GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf" DIRS="grpctesting/testpb grpctesting/gogotestpb" diff --git a/scripts/installprotoc.sh b/scripts/installprotoc.sh new file mode 100755 index 000000000..1ca843c6c --- /dev/null +++ b/scripts/installprotoc.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# +# Install the standard protocol buffer implementation - protoc. +set -e +set -u + +PROTOC_VERSION=${PROTOC_VERSION:-3.4.0} +TMP_GOPATH=${TMP_GOPATH:-/tmp/thanos-go} +PROTOC_DOWNLOAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}" + +OS=$(go env GOOS) +ARCH=$(go env GOARCH) +PLATFORM="${OS}/${ARCH}" + +is_supported_platform() { + platform=$1 + found=1 + case "$platform" in + darwin/amd64) found=0 ;; + darwin/i386) found=0 ;; + linux/amd64) found=0 ;; + linux/i386) found=0 ;; + linux/arm64) found=0 ;; + esac + return $found +} + +adjust_os() { + case ${OS} in + darwin) OS=osx ;; + esac + true +} + +adjust_arch() { + case ${ARCH} in + amd64) ARCH=x86_64 ;; + i386) ARCH=x86_32 ;; + arm64) ARCH=aarch_64 ;; + esac + true +} + +mkdir -p ${TMP_GOPATH} + +is_supported_platform "$PLATFORM" +if [[ $? -eq 1 ]]; then + echo "platform $PLATFORM is not supported. See https://github.com/protocolbuffers/protobuf/releases for details" + exit 1 +fi + +adjust_os + +adjust_arch + +PACKAGE="protoc-${PROTOC_VERSION}-${OS}-${ARCH}.zip" +PACKAGE_DOWNLOAD_URL="${PROTOC_DOWNLOAD_URL}/${PACKAGE}" +curl -LSs ${PACKAGE_DOWNLOAD_URL} -o ${TMP_GOPATH}/${PACKAGE} +unzip -qqj ${TMP_GOPATH}/${PACKAGE} "bin/protoc" -d "${TMP_GOPATH}/bin/"