diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7a046a2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/golangci/golangci-lint + rev: v1.60.3 + hooks: + - id: golangci-lint + entry: golangci-lint run + args: [--timeout=5m] + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.38.0 + hooks: + - id: markdownlint + args: [--disable, MD013, MD002] + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: shellcheck + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f11e8a5 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +.PHONY: lint test unittest help all + +UNITTEST_PKG ?= "./..." + +all: test + +help: + @echo "Make targets:" + @echo + @echo 'Usage:' + @echo ' make lint Execute pre-commit linters' + @echo ' make unittest Execute unittest' + @echo ' make help Show this message' + +test: lint unittest + +unittest: + ginkgo -r --randomize-all --randomize-suites --fail-on-pending --cover --trace --v --coverprofile=coverage.out ${UNITTEST_PKG} + +lint: + @echo "Executing pre-commit for all files" + pre-commit run --all-files + @echo "pre-commit executed." diff --git a/README.md b/README.md index c0cb827..7c31311 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,15 @@ [![codecov](https://codecov.io/github/cloud-bulldozer/go-commons/branch/main/graph/badge.svg?token=CFPW1UV7FO)](https://codecov.io/github/cloud-bulldozer/go-commons) [![Go Report Card](https://goreportcard.com/badge/github.com/cloud-bulldozer/go-commons)](https://goreportcard.com/report/github.com/cloud-bulldozer/go-commons) -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) \ No newline at end of file +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + +## Running test locally +Use `make` to run lint and unittest locally. See `make help` for details + +### `lint` +The `lint` tests are executed using [pre-commit](https://pre-commit.com/). +Make sure to install it before running. + +### `unittest` +The `unittest` tests are executed using [ginkgo](https://onsi.github.io/ginkgo/). +Make sure to install it locally before running.