mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-09 06:22:57 +00:00
Add support for code format checking using rustfmt in optional
pre-commit hook and in ci pipeline. Found issues can be fixed automatically via make fmt.
This commit is contained in:
@@ -10,6 +10,16 @@ executors:
|
||||
- image: cimg/rust:1.52.1
|
||||
|
||||
jobs:
|
||||
check-codestyle:
|
||||
executor: zenith-build-executor
|
||||
steps:
|
||||
- checkout
|
||||
|
||||
- run:
|
||||
name: rustfmt
|
||||
when: always
|
||||
command: |
|
||||
cargo fmt --all -- --check
|
||||
|
||||
# A job to build postgres
|
||||
build-postgres:
|
||||
@@ -257,6 +267,7 @@ jobs:
|
||||
workflows:
|
||||
build_and_test:
|
||||
jobs:
|
||||
- check-codestyle
|
||||
- build-postgres
|
||||
- build-zenith:
|
||||
name: build-zenith-<< matrix.build_type >>
|
||||
|
||||
10
Makefile
10
Makefile
@@ -67,4 +67,14 @@ distclean:
|
||||
rm -rf tmp_install
|
||||
cargo clean
|
||||
|
||||
fmt:
|
||||
@files=$$(git diff --cached --name-only --diff-filter=ACM | grep ".rs"); \
|
||||
if [ "$$files" ]; then \
|
||||
rustfmt $$files --edition=2018; \
|
||||
fi;
|
||||
|
||||
|
||||
setup-pre-commit-hook:
|
||||
ln -s -f ../../pre-commit.sh.tpl .git/hooks/pre-commit
|
||||
|
||||
.PHONY: postgres-configure postgres postgres-headers zenith
|
||||
|
||||
34
pre-commit.sh.tpl
Executable file
34
pre-commit.sh.tpl
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;33m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function check {
|
||||
name=$1
|
||||
prefix=$2
|
||||
files=$(git diff --cached --name-only --diff-filter=ACM | grep $prefix)
|
||||
shift; shift;
|
||||
echo -n "checking $name ";
|
||||
if [ -z "$files" ]; then
|
||||
echo -e "${CYAN}[NOT APPLICABLE]${NC}"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
cd $(git rev-parse --show-toplevel)
|
||||
|
||||
out=$($@ $files)
|
||||
if [ $? -eq 0 ];
|
||||
then
|
||||
echo -e "${GREEN}[OK]${NC}"
|
||||
cd -
|
||||
else
|
||||
echo -e "${RED}[FAILED]${NC}"
|
||||
echo -e "Please inspect the output below and run make fmt to fix automatically\n"
|
||||
echo -e "$out"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check rustfmt .rs rustfmt --check --edition=2018
|
||||
Reference in New Issue
Block a user