Skip to content

Commit 6ddb6ba

Browse files
feat(tooling): add git pre-commit and pre-push hooks
Signed-off-by: Ankit Kr. Chowdhury <rakesh856100@gmail.com>
1 parent a37bb73 commit 6ddb6ba

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ lint: golangci-lint ## Run golangci-lint linter
7676
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
7777
$(GOLANGCI_LINT) run --fix
7878

79+
.PHONY: setup-git-hooks
80+
setup-git-hooks: ## Install pre-commit and pre-push Git hooks.
81+
./hack/setup-git-hooks.sh
82+
7983
##@ Build
8084

8185
.PHONY: build

hack/setup-git-hooks.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2026.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
21+
HOOKS_DIR="${REPO_ROOT}/.git/hooks"
22+
23+
if [ ! -d "${HOOKS_DIR}" ]; then
24+
echo "Error: .git/hooks directory not found. Are you in a git repository?"
25+
exit 1
26+
fi
27+
28+
echo "Setting up Agentrax Git hooks in ${HOOKS_DIR}..."
29+
30+
# 1. Create pre-commit hook
31+
cat << 'EOF' > "${HOOKS_DIR}/pre-commit"
32+
#!/usr/bin/env bash
33+
set -e
34+
35+
echo "🔍 [pre-commit] Checking formatting, vet, and lint..."
36+
37+
# Run go fmt
38+
echo " -> go fmt ./..."
39+
go fmt ./...
40+
41+
# Run go vet
42+
echo " -> go vet ./..."
43+
go vet ./...
44+
45+
# Run golangci-lint
46+
echo " -> golangci-lint run..."
47+
if [ -f "./bin/golangci-lint" ]; then
48+
./bin/golangci-lint run
49+
else
50+
make lint
51+
fi
52+
53+
echo "✅ [pre-commit] All pre-commit checks passed!"
54+
EOF
55+
56+
chmod +x "${HOOKS_DIR}/pre-commit"
57+
58+
# 2. Create pre-push hook
59+
cat << 'EOF' > "${HOOKS_DIR}/pre-push"
60+
#!/usr/bin/env bash
61+
set -e
62+
63+
echo "🧪 [pre-push] Running full test suite and manifest verification..."
64+
65+
# Verify manifests and code generation
66+
echo " -> make manifests generate..."
67+
make manifests generate
68+
69+
# Run test suite
70+
echo " -> make test..."
71+
make test
72+
73+
# Verify kustomize render
74+
echo " -> Verifying config/default kustomization..."
75+
if [ -f "./bin/kustomize" ]; then
76+
./bin/kustomize build config/default > /dev/null
77+
fi
78+
79+
echo "✅ [pre-push] All pre-push checks passed!"
80+
EOF
81+
82+
chmod +x "${HOOKS_DIR}/pre-push"
83+
84+
echo "✨ Git hooks installed successfully! (pre-commit & pre-push)"

0 commit comments

Comments
 (0)