From fb90c0f52c947c8ec540e96c654929e5f869195a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 22 Mar 2023 17:16:05 +0300 Subject: [PATCH] [#65] Enable pre-commit Signed-off-by: Alex Vanin --- .gitlint | 11 ++++++++++ .pre-commit-config.yaml | 45 +++++++++++++++++++++++++++++++++++++++++ Makefile | 14 ++++++++++--- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 .gitlint create mode 100644 .pre-commit-config.yaml mode change 100644 => 100755 Makefile diff --git a/.gitlint b/.gitlint new file mode 100644 index 000000000..e7218ac53 --- /dev/null +++ b/.gitlint @@ -0,0 +1,11 @@ +[general] +fail-without-commits=True +regex-style-search=True +contrib=CC1 + +[title-match-regex] +regex=^\[\#[0-9Xx]+\]\s + +[ignore-by-title] +regex=^Release(.*) +ignore=title-match-regex diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..4fde2a0e9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,45 @@ +ci: + autofix_prs: false + +repos: + - repo: https://github.com/jorisroovers/gitlint + rev: v0.19.1 + hooks: + - id: gitlint + stages: [commit-msg] + - id: gitlint-ci + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + - id: check-merge-conflict + - id: check-json + - id: check-xml + - id: check-yaml + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] + - id: end-of-file-fixer + exclude: ".key$" + + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.2 + hooks: + - id: shellcheck + + - repo: https://github.com/golangci/golangci-lint + rev: v1.51.2 + hooks: + - id: golangci-lint + + - repo: local + hooks: + - id: go-unit-tests + name: go unit tests + entry: make test + pass_filenames: false + types: [go] + language: system diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 86dba46d0..76b8c0362 --- a/Makefile +++ b/Makefile @@ -16,14 +16,14 @@ REPO_BASENAME = $(shell basename `go list -m`) HUB_IMAGE ?= "truecloudlab/$(REPO_BASENAME)" HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')" -.PHONY: all $(BINS) $(BINDIR) dep docker/ test cover format image image-push dirty-image lint docker/lint version clean protoc +.PHONY: all $(BINS) $(BINDIR) dep docker/ test cover format image image-push dirty-image lint docker/lint pre-commit unpre-commit version clean protoc # .deb package versioning OS_RELEASE = $(shell lsb_release -cs) PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \ sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \ sed "s/-/~/")-${OS_RELEASE} -.PHONY: debpackage debclean +.PHONY: debpackage debclean # Make all binaries all: $(BINS) @@ -115,6 +115,14 @@ docker/lint: --env HOME=/src \ golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint' +# Activate pre-commit hooks +pre-commit: + pre-commit install -t pre-commit -t commit-msg + +# Deactivate pre-commit hooks +unpre-commit: + pre-commit uninstall -t pre-commit -t commit-msg + # Show current version version: @echo $(VERSION) @@ -143,6 +151,6 @@ debpackage: dpkg-buildpackage --no-sign -b debclean: - dh clean + dh clean include help.mk