Skip to content

Commit

Permalink
chore: ci lint update
Browse files Browse the repository at this point in the history
Signed-off-by: Eray Ates <[email protected]>
  • Loading branch information
rytsh committed Jan 7, 2024
1 parent cc0d9e1 commit b46a100
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: '1.21' # The Go version to download (if necessary) and use.
- name: golangci config
- name: download golangci.yml
run: |
[[ ! -f ".golangci.yml" ]] && curl -kfsSL -O https://raw.githubusercontent.com/worldline-go/guide/main/lint/.golangci.yml
echo GOPATH="$(dirname ${PWD})" >> $GITHUB_ENV
- name: golangci-lint general
[[ ! -f ".golangci.yml" ]] && curl -kfsSL -O https://raw.githubusercontent.com/worldline-go/guide/main/lint/.golangci.yml || true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --issues-exit-code 0 --out-format checkstyle:golangci-lint-report.out,colored-line-number
- name: golangci-lint critical check
run: |
golangci-lint run --new-from-rev remotes/origin/${{ github.event.repository.default_branch }} ./...
args: --timeout 5m --new-from-rev=HEAD~1 --issues-exit-code=0
- name: Run tests
run: |
GOPATH="$(dirname ${PWD})" golangci-lint run --out-format checkstyle ./... > golangci-lint-report.out || true
go test -coverprofile=coverage.out -json ./... > test-report.out
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
Expand Down
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,76 @@ LOCAL_BIN_DIR := $(PWD)/bin

## golangci configuration
GOLANGCI_CONFIG_URL := https://raw.githubusercontent.com/worldline-go/guide/main/lint/.golangci.yml
GOLANGCI_LINT_VERSION := v1.54.2
GOLANGCI_LINT_VERSION := v1.55.2

.DEFAULT_GOAL := help

.PHONY: env golangci lint test coverage html html-gen html-wsl help

.PHONY: env
env: ## Start env
docker compose -p wkafka -f env/docker-compose.yml up -d

.PHONY: env-up
env-up: ## Start env without detaching
docker compose -p wkafka -f env/docker-compose.yml up

.PHONY: env-logs
env-logs: ## Show env logs
docker compose -p wkafka logs -f

.PHONY: env-down
env-down: ## Stop env
docker compose -p wkafka down

.PHONY: run-example
run-example: LOG_LEVEL ?= debug
run-example: ## Run example
LOG_LEVEL=$(LOG_LEVEL) go run ./example/main.go

.PHONY: ci-run
ci-run: ## Run CI in local with act
act -j sonarcloud

.golangci.yml:
@$(MAKE) golangci

.PHONY: golangci
golangci: ## Download .golangci.yml file
@curl --insecure -o .golangci.yml -L'#' $(GOLANGCI_CONFIG_URL)

bin/golangci-lint-$(GOLANGCI_LINT_VERSION):
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN_DIR) $(GOLANGCI_LINT_VERSION)
@mv $(LOCAL_BIN_DIR)/golangci-lint $(LOCAL_BIN_DIR)/golangci-lint-$(GOLANGCI_LINT_VERSION)

.PHONY: lint
lint: .golangci.yml bin/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Lint Go files
@$(LOCAL_BIN_DIR)/golangci-lint-$(GOLANGCI_LINT_VERSION) --version
@GOPATH="$(shell dirname $(PWD))" $(LOCAL_BIN_DIR)/golangci-lint-$(GOLANGCI_LINT_VERSION) run ./...

.PHONY: test
test: ## Run unit tests
@go test -v -race ./...

.PHONY: test-without-cache
test-without-cache: ## Run unit tests without cache
@go test -count=1 -v -race ./...

.PHONY: coverage
coverage: ## Run unit tests with coverage
@go test -v -race -cover -coverpkg=./... -coverprofile=coverage.out -covermode=atomic ./...
@go tool cover -func=coverage.out

.PHONY: html
html: ## Show html coverage result
@go tool cover -html=./coverage.out

.PHONY: html-gen
html-gen: ## Export html coverage result
@go tool cover -html=./coverage.out -o ./coverage.html

.PHONY: html-wsl
html-wsl: html-gen ## Open html coverage result in wsl
@explorer.exe `wslpath -w ./coverage.html` || true

.PHONY: help
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ First set the connection config to create a new kafka client.
Main config struct that contains brokers, security settings and consumer validation.

```yaml
brokers:
brokers: # list of brokers, default is empty
- localhost:9092
security:
tls:
Expand Down

0 comments on commit b46a100

Please sign in to comment.