difftreelog
Merge pull request #838 from UniqueNetwork/feature/pre-push-checks
in: master
4 files changed
.envrcdiffbeforeafterboth--- 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
.githooks/pre-commitdiffbeforeafterboth--- /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
Makefilediffbeforeafterboth168clippy:168clippy:169 cargo clippy --features=quartz-runtime,unique-runtime,try-runtime,runtime-benchmarks --tests169 cargo clippy --features=quartz-runtime,unique-runtime,try-runtime,runtime-benchmarks --tests170171.PHONY: git-hooks172git-hooks:173 cp .githooks/pre-commit .git/hooks/pre-commit174175.PHONY: init176init:177 make git-hooks178 cd tests179 yarn install170180README.mddiffbeforeafterboth--- 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