Skip to content

Commit

Permalink
Moved to GH actions; Added lint; Added issue/PR templates.
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed May 30, 2020
1 parent a0e7c73 commit 5b83c99
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 43 deletions.
11 changes: 11 additions & 0 deletions .bingo/.gitignore
@@ -0,0 +1,11 @@

# Ignore everything
*

# But not these files:
!.gitignore
!*.mod
!*.md
!*.mk

*tmp.mod
12 changes: 12 additions & 0 deletions .bingo/README.md
@@ -0,0 +1,12 @@
# 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 <tool>` to install <tool> that have own module file in this directory.
* If `Variables.mk` is present, use $(<upper case tool name>) variable where <tool> is the <root>/.bingo/<tool>.mod.
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies.

## Requirements

* Go 1.14+
52 changes: 52 additions & 0 deletions .bingo/Variables.mk
@@ -0,0 +1,52 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.1.0. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
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 faillint variable:
#
# In your main Makefile (for non array binaries):
#
#include .bingo/Variables.mk # (If not generated automatically by bingo).
#
#command: $(FAILLINT)
# @echo "Running faillint"
# @$(FAILLINT) <flags/args..>
#
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"
@$(GO) build -modfile=.bingo/faillint.mod -o=$(GOBIN)/faillint-v1.5.0 "github.com/fatih/faillint"
.bingo/faillint.mod: ;

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"
@$(GO) build -modfile=.bingo/goimports.mod -o=$(GOBIN)/goimports-v0.0.0-20200529172331-a64b76657301 "golang.org/x/tools/cmd/goimports"
.bingo/goimports.mod: ;

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"
@$(GO) build -modfile=.bingo/golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.27.0 "github.com/golangci/golangci-lint/cmd/golangci-lint"
.bingo/golangci-lint.mod: ;

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"
@$(GO) build -modfile=.bingo/misspell.mod -o=$(GOBIN)/misspell-v0.3.4 "github.com/client9/misspell/cmd/misspell"
.bingo/misspell.mod: ;

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"
@$(GO) build -modfile=.bingo/protoc-gen-gogofast.mod -o=$(GOBIN)/protoc-gen-gogofast-v1.3.1 "github.com/gogo/protobuf/protoc-gen-gogofast"
.bingo/protoc-gen-gogofast.mod: ;

5 changes: 5 additions & 0 deletions .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
5 changes: 5 additions & 0 deletions .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
8 changes: 8 additions & 0 deletions .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
)
5 changes: 5 additions & 0 deletions .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
5 changes: 5 additions & 0 deletions .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
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE.md
@@ -0,0 +1,15 @@
<!--
Template relevant to bug reports only!
Keep issue title verbose enough.
-->

**Go version used**:

**What happened**:

**What you expected to happen**:

**How to reproduce it (as minimally and precisely as possible)**:

-->
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,24 @@
<!--
Keep PR title verbose enough.
-->

<!--
Don't forget about CHANGELOG!
Changelog entry format:
- [#<PR-id>](<PR-URL>) ...
<PR-id> Id of your pull request.
<PR-URL> URL of your PR such as https://github.com/grpc-ecosystem/go-grpc-middleware/pull/<PR-id>
-->

* [ ] I added CHANGELOG entry for this change.
* [ ] Change is not relevant to the end user.

## Changes

<!-- Enumerate changes you made -->

## Verification

<!-- How you tested it? How do you know it works? -->
52 changes: 52 additions & 0 deletions .github/stale.yml
@@ -0,0 +1,52 @@
# 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 last 1 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 will be no activity for next 2 weeks, this issue will be closed (we can always reopen a PR if you get back to this!).
Alternatively, use [`remind` command](https://probot.github.io/apps/reminders/) if you wish to be reminded at some point in future.
#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 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 will be no activity for next 2 weeks, this issue will be closed (we can always reopen an issue if we need!).
Alternatively, use [`remind` command](https://probot.github.io/apps/reminders/) if you wish to be reminded at some point in future.
#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
57 changes: 57 additions & 0 deletions .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)
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

84 changes: 61 additions & 23 deletions Makefile
@@ -1,37 +1,75 @@
include .bingo/Variables.mk
SHELL=/bin/bash

GODIRS_NOVENDOR ?= $(shell go list ./... | grep -v /vendor/)
PROVIDER_MODULES ?= $(shell ls -d $(PWD)/providers/*)
MODULES ?= $(PROVIDER_MODULES) $(PWD)/

GOFILES_NOVENDOR ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print)

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 $(GOFILES_NOVENDOR)
@$(foreach dir,$(MODULES),$(MAKE) fmt_module DIR=$(dir))

all: vet fmt test
.PHONY: fmt_module
fmt_module:
go fmt $(shell cd $(DIR) && go list ./... | grep -v /vendor/)

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 ./...
.PHONY: proto
proto: $(PROTOC_GEN_GOGOFAST) $(GOIMPORTS) $(PROTOC) ./grpctesting/testpb/test.proto
@GOIMPORTS_BIN="$(GOIMPORTS)" PROTOC_BIN="$(PROTOC)" scripts/genproto.sh

.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:
@echo "Running lint for all modules: ${MODULES}"
@$(foreach dir,$(MODULES),$(MAKE) test_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) fmt_module
$(call require_clean_work_tree,"detected not clean master before running lint")
@echo ">> verifying modules being imported"
@$(FAILLINT) -paths "errors=github.com/pkg/errors" ./...
@$(FAILLINT) -paths "fmt.{Print,PrintfPrintln,Sprint}" -ignore-tests ./...
@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)"
5 changes: 1 addition & 4 deletions scripts/genproto.sh
Expand Up @@ -18,10 +18,7 @@ if ! [[ $(${PROTOC_BIN} --version) =~ "3.4.0" ]]; 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"
Expand Down

0 comments on commit 5b83c99

Please sign in to comment.