From 4c4e3cd37186401e84ff3508bace0ff15778731b Mon Sep 17 00:00:00 2001 From: Hoang Do Date: Mon, 20 May 2024 21:51:45 +0700 Subject: [PATCH] chores(ci): Add setup script and git push hooks (#874) --- contrib/githooks/README.md | 18 +++++++++++++++++- contrib/githooks/pre-push | 37 +++++++++++++++++++++++++++++++++++++ scripts/setup-git-hooks.sh | 9 +++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100755 contrib/githooks/pre-push create mode 100755 scripts/setup-git-hooks.sh diff --git a/contrib/githooks/README.md b/contrib/githooks/README.md index b8f305131..a5db3e458 100644 --- a/contrib/githooks/README.md +++ b/contrib/githooks/README.md @@ -1,9 +1,13 @@ # Git hooks -Using +We have pre-commit and pre-push. + +Pre-commit using ## Installation +### Pre-commit hooks + Using pip: `pip install pre-commit` @@ -12,8 +16,20 @@ Or Using homebrew: `brew install pre-commit` +### Pre-push hooks + +Install golangci-lint: + +`go install github.com/golangci/golangci-lint/cmd/golangci-lint` + +Install markdownlint-cli: + +`npm install -g markdownlint-cli` + ## Installation of githook scripts From root directory: `pre-commit install -c ./contrib/githooks/pre-commit-config.yaml` + +`./scripts/setup-git-hooks.sh` diff --git a/contrib/githooks/pre-push b/contrib/githooks/pre-push new file mode 100755 index 000000000..f003fa007 --- /dev/null +++ b/contrib/githooks/pre-push @@ -0,0 +1,37 @@ +#!/bin/sh +# pre-push hook script + +# Ensure golangci-lint is installed +if ! command -v golangci-lint >/dev/null 2>&1; then + echo "golangci-lint is not installed. Please install it with 'go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.58.0'" + exit 1 +fi + +# Ensure markdownlint is installed +if ! command -v markdownlint >/dev/null 2>&1; then + echo "markdownlint-cli is not installed. Please install it with 'npm install -g markdownlint-cli'" + exit 1 +fi + +# Run golangci-lint +golangci-lint run + +# Capture the exit status of golangci-lint +RESULT=$? +if [ $RESULT -ne 0 ]; then + echo "golangci-lint checks failed. Aborting push." + exit 1 +fi + +# Run markdownlint +markdownlint . --config .markdownlint.yaml + +# Capture the exit status of markdownlint +RESULT=$? +if [ $RESULT -ne 0 ]; then + echo "markdownlint checks failed. Aborting push." + exit 1 +fi + +# If all tests pass, allow the push to proceed +exit 0 diff --git a/scripts/setup-git-hooks.sh b/scripts/setup-git-hooks.sh new file mode 100755 index 000000000..fd2cd5e7e --- /dev/null +++ b/scripts/setup-git-hooks.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Copy pre-push hook to .git/hooks/ +cp ./contrib/githooks/pre-push ./.git/hooks/pre-push + +# Make the pre-push hook executable +chmod +x .git/hooks/pre-push + +echo "Git push hooks installed successfully."