[#58] pre-commit: Add pre-commit and related Makefile targets

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-09-02 14:59:24 +03:00
parent 54812ba857
commit 6b0f3b01e0
No known key found for this signature in database
3 changed files with 52 additions and 1 deletions

24
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.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: ".svg$"
- repo: local
hooks:
- id: make-fmt
name: Run make fmt
entry: make fmt
language: system
pass_filenames: false

View file

@ -1,7 +1,10 @@
#!/usr/bin/make -f
SHELL=bash
.PHONY: doc
include help.mk
.PHONY: doc fmt pre-commit unpre-commit pre-commit-run
# Regenerate documentation for proto files:
doc:
@for f in `find . -type f -name '*.proto' -exec dirname {} \; | sort -u `; do \
@ -12,8 +15,21 @@ doc:
--doc_out=proto-docs/ $${f}/*.proto; \
done
# Run clang-format
fmt:
@for f in `ls **/*.proto`; do \
echo "⇒ Formatting $$f"; \
clang-format -i $$f; \
done
# Activate pre-commit hooks
pre-commit:
pre-commit install --hook-type pre-commit
# Deactivate pre-commit hooks
unpre-commit:
pre-commit uninstall --hook-type pre-commit
# Run pre-commit hooks
pre-commit-run:
@pre-commit run --all-files --hook-stage manual

11
help.mk Normal file
View file

@ -0,0 +1,11 @@
.PHONY: help
# Show this help prompt
help:
@echo ' Usage:'
@echo ''
@echo ' make <target>'
@echo ''
@echo ' Targets:'
@echo ''
@awk '/^#/{ comment = substr($$0,3) } /^[a-zA-Z][a-zA-Z0-9_-]+:/{ print " ", $$1, comment; comment = "" }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort | uniq