From 9a3d9a7184397fee67f317e2d652ab226d678960 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Fri, 22 Sep 2023 07:54:41 +0000 Subject: [PATCH] Merge pull request #838 from UniqueNetwork/feature/pre-push-checks --- --- a/.envrc +++ b/.envrc @@ -19,6 +19,10 @@ fi } +if ! diff .githooks/pre-commit .git/hooks/pre-commit >/dev/null; then +echo -e "${RED}Hooks are updated, run make git-hooks${RESET}" +fi + watch_file .baedeker/.bdk-env/discover.env if test -f .baedeker/.bdk-env/discover.env; then check_bdk baedeker --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Pre-push hook verifying that inappropriate code will not be pushed. + +# Colors for the terminal output +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +echo "Starting cargo fmt.." +cargo fmt --check +FMT_EXIT="$?" + +# Check that prettier formatting rules are not violated. +if [[ "${FMT_EXIT}" = 0 ]]; then + echo -e "${GREEN}cargo fmt succeded${NC}" +else + echo -e "${RED}Commit error!${NC}" + echo "Please format the code via 'cargo fmt', cannot commit unformatted code" + exit 1 +fi + +STAGED_TEST_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".ts$\|.js$") + +if [[ "$STAGED_TEST_FILES" = "" ]]; then + echo -e "${GREEN}eslint succeded${NC}" + exit 0 +fi + +echo "Starting eslint.." +./tests/node_modules/.bin/eslint --max-warnings 0 ${STAGED_TEST_FILES[@]} +ESLINT_EXIT="$?" + +if [[ "${ESLINT_EXIT}" = 0 ]]; then + echo -e "${GREEN}eslint succeded${NC}" +else + echo -e "${RED}Commit error!${NC}" + echo "Please format the code via 'yarn fix', cannot Commit unformatted code" + exit 1 +fi + +exit $? \ No newline at end of file --- a/Makefile +++ b/Makefile @@ -167,3 +167,13 @@ .PHONY: clippy clippy: cargo clippy --features=quartz-runtime,unique-runtime,try-runtime,runtime-benchmarks --tests + +.PHONY: git-hooks +git-hooks: + cp .githooks/pre-commit .git/hooks/pre-commit + +.PHONY: init +init: + make git-hooks + cd tests + yarn install --- a/README.md +++ b/README.md @@ -159,6 +159,11 @@ cd tests && yarn eslint --ext .ts,.js src/ ``` +### Enable checking of code style on commits +```bash +make git-hooks +``` + ## Karura token transfer -- gitstuff