|
| 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