Files
architecture/legacy/scripts/pre-commit-checks.sh
Hugo Nijhuis cc72ad68ed Migrate from Claude Code to OpenCode structure
- Move legacy content to legacy/ folder (old, old2, docs, learnings, scripts)
- Create new .opencode/ structure with skills/, tools/, agents/ folders
- Update Makefile to symlink to ~/.config/opencode/ instead of ~/.claude/
- Update Makefile to manage skills, tools, and agents (remove settings.json)
- Simplify install/uninstall (no backup logic)
- Add README.md documenting the new structure
- Keep settings.json as historical reference
2026-05-02 13:41:59 +02:00

51 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Pre-commit validation script for Claude Code
# Validates YAML, checks for secrets, validates K8s manifests
set -e
# Get staged files
STAGED_FILES=$(git diff --cached --name-only 2>/dev/null || echo "")
if [ -z "$STAGED_FILES" ]; then
exit 0
fi
# Check for potential secrets in staged files
echo "Checking for potential secrets..."
SECRET_PATTERN='(password|secret|token|api_key|apikey|private_key).*[=:].{20,}'
if echo "$STAGED_FILES" | xargs grep -l -iE "$SECRET_PATTERN" 2>/dev/null | grep -v '.sops.yaml' | grep -v 'secret.*\.enc\.yaml'; then
echo "WARNING: Potential secrets detected in staged files (excluding SOPS-encrypted files)"
echo "Please verify these are encrypted or not actual secrets."
fi
# Validate YAML syntax
echo "Validating YAML syntax..."
for file in $(echo "$STAGED_FILES" | grep -E '\.ya?ml$'); do
if [ -f "$file" ]; then
if ! python3 -c "import yaml; yaml.safe_load(open('$file'))" 2>/dev/null; then
echo "ERROR: Invalid YAML syntax: $file"
exit 1
fi
fi
done
# Validate Kubernetes manifests (if kubectl available)
if command -v kubectl &>/dev/null; then
echo "Validating Kubernetes manifests..."
for file in $(echo "$STAGED_FILES" | grep -E '\.ya?ml$'); do
if [ -f "$file" ] && grep -q "^kind:" "$file" 2>/dev/null; then
# Skip SOPS-encrypted files and kustomization files
if echo "$file" | grep -qE '(\.sops\.yaml|\.enc\.yaml|kustomization\.yaml)$'; then
continue
fi
if ! kubectl apply --dry-run=client -f "$file" 2>/dev/null; then
echo "WARNING: Kubernetes validation failed: $file (may be expected for partial manifests)"
fi
fi
done
fi
echo "Pre-commit checks passed."
exit 0