Skip to content

Git Hooks Integration

Release Agent can be used as a git pre-push hook to automatically validate code before pushing.

Setup Options

Option 1: Simple Script

Create .git/hooks/pre-push manually:

cat > .git/hooks/pre-push << 'EOF'
#!/bin/bash
exec atrelease check
EOF

chmod +x .git/hooks/pre-push

Create a symlink to the Release Agent binary:

ln -sf $(which agent-team-release) .git/hooks/pre-push

Note: This runs atrelease with no arguments, which defaults to check.

Option 3: Shared Hooks Directory

For team-wide hooks, use a shared hooks directory:

# Create shared hooks directory
mkdir -p .githooks

# Create the hook
cat > .githooks/pre-push << 'EOF'
#!/bin/bash
exec atrelease check
EOF

chmod +x .githooks/pre-push

# Configure git to use shared hooks
git config core.hooksPath .githooks

Commit .githooks/ to your repository so all team members use the same hooks.

Hook Behavior

When the pre-push hook runs:

  1. Release Agent detects languages in your repository
  2. Runs all enabled checks for each language
  3. Exits with code 0 (success) if all hard checks pass
  4. Exits with code 1 (failure) if any hard check fails

Warnings Don't Block

Soft warnings (like untracked references) don't block the push:

=== Summary ===
✓ Go: build
✓ Go: tests
⚠ Go: untracked references (warning)

Passed: 6, Failed: 0, Skipped: 0, Warnings: 1

Pre-push checks passed with warnings.

Bypassing the Hook

To push without running checks (use sparingly):

git push --no-verify

Or:

git push -n

Customizing the Hook

Skip Certain Checks

#!/bin/bash
# Skip tests for faster push (run in CI)
exec atrelease check --no-test

Verbose Output

#!/bin/bash
exec atrelease check --verbose

Different Config for Hooks

#!/bin/bash
# Use hook-specific config
RELEASEAGENT_CONFIG=.releaseagent.hooks.yaml exec atrelease check

CI Integration

For complete coverage, run Release Agent in both:

  1. Pre-push hook - Fast feedback during development
  2. CI pipeline - Comprehensive checks with full test suite

GitHub Actions Example

name: Release Agent Checks
on: [push, pull_request]

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: '1.21'
      - name: Install Release Agent
        run: go install github.com/agentplexus/agent-team-release/cmd/atrelease@latest
      - name: Run checks
        run: atrelease check

Troubleshooting

Hook Not Running

Check that the hook is executable:

ls -la .git/hooks/pre-push
# Should show -rwxr-xr-x

Wrong Directory

The hook runs in the repository root. Use absolute paths if needed:

#!/bin/bash
cd "$(git rev-parse --show-toplevel)"
exec atrelease check

Release Agent Not Found

Ensure Release Agent is in your PATH:

#!/bin/bash
export PATH="$HOME/go/bin:$PATH"
exec atrelease check

Slow Hooks

For faster feedback, skip time-consuming checks:

#!/bin/bash
# Fast checks only - full checks run in CI
exec atrelease check --no-test --no-coverage

Team Guidelines

  1. Use shared hooks directory (Option 3)
  2. Commit .githooks/ to repository
  3. Document in README how to enable:
## Development Setup

Enable git hooks:
\`\`\`bash
git config core.hooksPath .githooks
\`\`\`

When to Bypass

Only bypass hooks (--no-verify) when:

  • Pushing work-in-progress to a feature branch
  • CI will catch any issues
  • You understand the risks

Never bypass when pushing to main or release branches.