From b8c5f7cfe13f84ba1b0c650e6f9f2072c0890e48 Mon Sep 17 00:00:00 2001 From: Vlad Gorodetsky Date: Wed, 15 Jan 2020 13:47:52 +0200 Subject: [PATCH] Add GitHub Actions workflows, use golangci-lint --- .github/CODEOWNERS | 1 + .github/workflows/ci.yml | 62 +++++++++++++++++++++++++++++++++ .golangci.yml | 74 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 9 +++-- Makefile | 67 +++++++++++------------------------- Vagrantfile | 10 ++---- 6 files changed, 162 insertions(+), 61 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/ci.yml create mode 100644 .golangci.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..5621bb374 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @bai diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..4004ffd54 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: push + +jobs: + test: + name: Go ${{ matrix.go-version }} on Ubuntu + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go-version: [1.12.x, 1.13.x] + platform: [ubuntu-latest] + + env: + KAFKA_PEERS: localhost:9091,localhost:9092,localhost:9093,localhost:9094,localhost:9095 + TOXIPROXY_ADDR: http://localhost:8474 + KAFKA_INSTALL_ROOT: /home/runner/kafka + KAFKA_HOSTNAME: localhost + DEBUG: true + KAFKA_VERSION: 2.3.0 + KAFKA_SCALA_VERSION: 2.12 + + steps: + - uses: actions/checkout@v1 + + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go-version }} + + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + # See https://github.com/actions/setup-go/issues/14 + - name: Setup env + run: | + echo "::set-env name=GOPATH::$(go env GOPATH)" + echo "::add-path::$(go env GOPATH)/bin" + shell: bash + + - name: Install dependencies + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1 + export REPOSITORY_ROOT=${GITHUB_WORKSPACE} + vagrant/install_cluster.sh + vagrant/boot_cluster.sh + vagrant/create_topics.sh + vagrant/run_java_producer.sh + + - name: Run test suite + run: make test + + - name: Run linter + run: make lint + + - name: Teardown + run: vagrant/halt_cluster.sh diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..41b77f065 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,74 @@ +run: + timeout: 5m + deadline: 10m + +linters-settings: + govet: + check-shadowing: false + golint: + min-confidence: 0 + gocyclo: + min-complexity: 95 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 3 + misspell: + locale: US + goimports: + local-prefixes: github.com/Shopify/sarama + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - wrapperFunc + - ifElseChain + funlen: + lines: 300 + statements: 300 + +linters: + disable-all: true + enable: + - bodyclose + # - deadcode + - depguard + - dogsled + # - dupl + # - errcheck + - funlen + # - gocritic + - gocyclo + - gofmt + # - goimports + # - golint + # - gosec + # - gosimple + - govet + # - ineffassign + # - interfacer + # - misspell + # - nakedret + # - scopelint + # - staticcheck + # - structcheck + # - stylecheck + - typecheck + # - unconvert + # - unused + # - varcheck + - whitespace + # - goconst + # - gochecknoinits + +issues: + exclude: + - consider giving a name to these results + - include an explanation for nolint directive diff --git a/.travis.yml b/.travis.yml index cace313a7..9c9858635 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -dist: xenial +dist: bionic language: go go: - 1.12.x @@ -22,13 +22,12 @@ before_install: - vagrant/create_topics.sh - vagrant/run_java_producer.sh -install: make install_dependencies +before_script: +- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1 script: - make test -- make vet -- make errcheck -- if [[ "$TRAVIS_GO_VERSION" == 1.13* ]]; then make fmt; fi +- make lint after_success: - go tool cover -func coverage.txt diff --git a/Makefile b/Makefile index 9c8329e2f..c3b431a56 100644 --- a/Makefile +++ b/Makefile @@ -1,56 +1,27 @@ -export GO111MODULE=on +default: fmt get update test lint -default: fmt vet errcheck test lint +GO := GO111MODULE=on GOPRIVATE=github.com/linkedin GOSUMDB=off go +GOBUILD := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG) +GOTEST := $(GO) test -gcflags='-l' -p 3 -v -race -timeout 6m -coverprofile=profile.out -covermode=atomic -# Taken from https://github.com/codecov/example-go#caveat-multiple-files -.PHONY: test -test: - echo "mode: atomic" > coverage.txt - for d in `go list ./...`; do \ - go test -p 1 -v -timeout 6m -race -coverprofile=profile.out -covermode=atomic $$d || exit 1; \ - if [ -f profile.out ]; then \ - tail +2 profile.out >> coverage.txt; \ - rm profile.out; \ - fi \ - done - -GOLINT := $(shell command -v golint) +FILES := $(shell find . -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -not -name '*_test.go') +TESTS := $(shell find . -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -name '*_test.go') -.PHONY: lint -lint: -ifndef GOLINT - go get golang.org/x/lint/golint -endif - go list ./... | xargs golint - -.PHONY: vet -vet: - go vet ./... +get: + $(GO) get ./... + $(GO) mod verify + $(GO) mod tidy -ERRCHECK := $(shell command -v errcheck) -# See https://github.com/kisielk/errcheck/pull/141 for details on ignorepkg -.PHONY: errcheck -errcheck: -ifndef ERRCHECK - go get github.com/kisielk/errcheck -endif - errcheck -ignorepkg fmt github.com/Shopify/sarama/... +update: + $(GO) get -u -v all + $(GO) mod verify + $(GO) mod tidy -.PHONY: fmt fmt: - @if [ -n "$$(go fmt ./...)" ]; then echo 'Please run go fmt on your code.' && exit 1; fi + gofmt -s -l -w $(FILES) $(TESTS) -.PHONY : install_dependencies -install_dependencies: get - -.PHONY: get -get: - go get -v ./... - -.PHONY: clean -clean: - go clean ./... +lint: + golangci-lint run -.PHONY: tidy -tidy: - go mod tidy -v +test: + $(GOTEST) ./... diff --git a/Vagrantfile b/Vagrantfile index f4b848a30..07d7ffb8f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,14 +1,8 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = "2" - # We have 5 * 192MB ZK processes and 5 * 320MB Kafka processes => 2560MB MEMORY = 3072 -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - config.vm.box = "ubuntu/trusty64" +Vagrant.configure("2") do |config| + config.vm.box = "ubuntu/bionic64" config.vm.provision :shell, path: "vagrant/provision.sh"