Skip to content

Commit

Permalink
core: replace gometaliter by golangci-lint on validate (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchezgavier committed May 5, 2021
1 parent aed81d1 commit 47a4aac
Show file tree
Hide file tree
Showing 11 changed files with 1,868 additions and 783 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ env:
TAG: ${{ github.event.release.tag_name }}

jobs:
validate:
name: Validate code via linters
golangci-lint:
name: Validate code via golangci
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v1
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
username: ${{ secrets.OHAI_DOCKER_HUB_ID }}
password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }}
- name: Validate code
run: make ci/validate

only-new-issues: true
snyk:
name: Run security checks via snyk
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -110,7 +106,7 @@ jobs:
prerelease:
name: Build binary for *Nix/Win, create archives for *Nix/Win, create packages for *Nix, upload all artifacts into GH Release assets
runs-on: ubuntu-20.04
needs: [validate, snyk, test-nix, test-windows, test-integration-nix]
needs: [golangci-lint, snyk, test-nix, test-windows, test-integration-nix]
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/push_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,6 @@ env:
DOCKER_LOGIN_AVAILABLE: ${{ secrets.OHAI_DOCKER_HUB_ID }}

jobs:
validate:
name: Validate code via linters
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
if: ${{env.DOCKER_LOGIN_AVAILABLE}}
uses: docker/login-action@v1
with:
username: ${{ secrets.OHAI_DOCKER_HUB_ID }}
password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }}
- name: Validate code
run: make ci/validate

golangci-lint:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ src/versioninfo.json
src/resource.syso
dist/

vendor/

16 changes: 8 additions & 8 deletions .papers_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ reject:
- EPL-1.0

exceptions:
- "github.com/newrelic/nri-mysql/vendor/github.com/go-sql-driver/mysql"
- "github.com/newrelic/nri-mysql/vendor/github.com/newrelic/infra-integrations-sdk/args"
- "github.com/newrelic/nri-mysql/vendor/github.com/newrelic/infra-integrations-sdk/data/event"
- "github.com/newrelic/nri-mysql/vendor/github.com/newrelic/infra-integrations-sdk/data/inventory"
- "github.com/newrelic/nri-mysql/vendor/github.com/newrelic/infra-integrations-sdk/data/metric"
- "github.com/newrelic/nri-mysql/vendor/github.com/newrelic/infra-integrations-sdk/integration"
- "github.com/newrelic/nri-mysql/vendor/github.com/newrelic/infra-integrations-sdk/log"
- "github.com/newrelic/nri-mysql/vendor/github.com/newrelic/infra-integrations-sdk/persist"
- "github.com/go-sql-driver/mysql"
- "github.com/newrelic/infra-integrations-sdk/args"
- "github.com/newrelic/infra-integrations-sdk/data/event"
- "github.com/newrelic/infra-integrations-sdk/data/inventory"
- "github.com/newrelic/infra-integrations-sdk/data/metric"
- "github.com/newrelic/infra-integrations-sdk/integration"
- "github.com/newrelic/infra-integrations-sdk/log"
- "github.com/newrelic/infra-integrations-sdk/persist"
69 changes: 13 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,80 +1,37 @@
INTEGRATION := mysql
BINARY_NAME = nri-$(INTEGRATION)
SRC_DIR = ./src/
VALIDATE_DEPS = golang.org/x/lint/golint
TEST_DEPS = github.com/axw/gocov/gocov github.com/AlekSi/gocov-xml
INTEGRATIONS_DIR = /var/db/newrelic-infra/newrelic-integrations/
CONFIG_DIR = /etc/newrelic-infra/integrations.d
GO_FILES := ./src/
GOFLAGS = -mod=readonly
GOLANGCI_LINT = github.com/golangci/golangci-lint/cmd/golangci-lint
GOCOV = github.com/axw/gocov/gocov
GOCOV_XML = github.com/AlekSi/gocov-xml

all: build

build: clean validate-deps validate compile test
build: clean validate compile test

clean:
@echo "=== $(INTEGRATION) === [ clean ]: removing binaries and coverage file..."
@rm -rfv bin coverage.xml

validate-deps:
@echo "=== $(INTEGRATION) === [ validate-deps ]: installing validation dependencies..."
@go get -v $(VALIDATE_DEPS)

validate-only:
ifeq ($(strip $(GO_FILES)),)
@echo "=== $(INTEGRATION) === [ validate ]: no Go files found. Skipping validation."
else
@printf "=== $(INTEGRATION) === [ validate ]: running gofmt... "
@OUTPUT="$(shell gofmt -l $(GO_FILES))" ;\
if [ -z "$$OUTPUT" ]; then \
echo "passed." ;\
else \
echo "failed. Incorrect syntax in the following files:" ;\
echo "$$OUTPUT" ;\
exit 1 ;\
fi
@printf "=== $(INTEGRATION) === [ validate ]: running golint... "
@OUTPUT="$(shell golint $(SRC_DIR)...)" ;\
if [ -z "$$OUTPUT" ]; then \
echo "passed." ;\
else \
echo "failed. Issues found:" ;\
echo "$$OUTPUT" ;\
exit 1 ;\
fi
@printf "=== $(INTEGRATION) === [ validate ]: running go vet... "
@OUTPUT="$(shell go vet $(SRC_DIR)...)" ;\
if [ -z "$$OUTPUT" ]; then \
echo "passed." ;\
else \
echo "failed. Issues found:" ;\
echo "$$OUTPUT" ;\
exit 1;\
fi
endif

validate: validate-deps validate-only

compile-deps:
@echo "=== $(INTEGRATION) === [ compile-deps ]: installing build dependencies..."
@go get -v -d -t ./...
validate:
@echo "=== $(INTEGRATION) === [ validate ]: Validating source code running golangci-lint..."
@go run $(GOFLAGS) $(GOLANGCI_LINT) run --verbose

bin/$(BINARY_NAME):
@echo "=== $(INTEGRATION) === [ compile ]: building $(BINARY_NAME)..."
@go build -v -o bin/$(BINARY_NAME) $(GO_FILES)

compile: compile-deps bin/$(BINARY_NAME)
compile: bin/$(BINARY_NAME)

test-deps: compile-deps
@echo "=== $(INTEGRATION) === [ test-deps ]: installing testing dependencies..."
@go get -v $(TEST_DEPS)

test-only:
test:
@echo "=== $(INTEGRATION) === [ test ]: running unit tests..."
@gocov test ./... | gocov-xml > coverage.xml

test: test-deps test-only
@go run $(GOFLAGS) $(GOCOV) test ./... | go run $(GOFLAGS) $(GOCOV_XML) > coverage.xml

integration-test: test-deps
integration-test:
@echo "=== $(INTEGRATION) === [ test ]: running integration tests..."
@docker-compose -f tests/integration/docker-compose.yml up -d --build
@go test -tags=integration ./tests/integration/. || (ret=$$?; docker-compose -f tests/integration/docker-compose.yml down && exit $$ret)
Expand All @@ -90,4 +47,4 @@ install: bin/$(BINARY_NAME)
include $(CURDIR)/build/ci.mk
include $(CURDIR)/build/release.mk

.PHONY: all build clean validate-deps validate-only validate compile-deps compile test-deps test-only test integration-test install
.PHONY: all build clean validate compile test integration-test install
Loading

0 comments on commit 47a4aac

Please sign in to comment.