|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +GitHub Action Indexer Installation Script |
| 4 | +
|
| 5 | +This script helps developers install the Augment GitHub Action Indexer |
| 6 | +into their repositories with minimal setup. |
| 7 | +
|
| 8 | +Usage: |
| 9 | + python install.py /path/to/your/repository |
| 10 | + python install.py # installs to current directory |
| 11 | +""" |
| 12 | + |
| 13 | +import argparse |
| 14 | +import shutil |
| 15 | +import sys |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +# Colors for console output |
| 19 | +COLORS = { |
| 20 | + "reset": "\033[0m", |
| 21 | + "bright": "\033[1m", |
| 22 | + "red": "\033[31m", |
| 23 | + "green": "\033[32m", |
| 24 | + "yellow": "\033[33m", |
| 25 | + "blue": "\033[34m", |
| 26 | + "cyan": "\033[36m", |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +def colorize(color: str, text: str) -> str: |
| 31 | + """Apply color to text.""" |
| 32 | + return f"{COLORS.get(color, '')}{text}{COLORS['reset']}" |
| 33 | + |
| 34 | + |
| 35 | +def log(message: str, color: str = "reset") -> None: |
| 36 | + """Print a colored message.""" |
| 37 | + print(colorize(color, message)) |
| 38 | + |
| 39 | + |
| 40 | +def log_step(step: str, message: str) -> None: |
| 41 | + """Print a step message.""" |
| 42 | + log(f"[{step}] {message}", "cyan") |
| 43 | + |
| 44 | + |
| 45 | +def log_success(message: str) -> None: |
| 46 | + """Print a success message.""" |
| 47 | + log(f"✅ {message}", "green") |
| 48 | + |
| 49 | + |
| 50 | +def log_warning(message: str) -> None: |
| 51 | + """Print a warning message.""" |
| 52 | + log(f"⚠️ {message}", "yellow") |
| 53 | + |
| 54 | + |
| 55 | +def log_error(message: str) -> None: |
| 56 | + """Print an error message.""" |
| 57 | + log(f"❌ {message}", "red") |
| 58 | + |
| 59 | + |
| 60 | +def copy_directory(src: Path, dst: Path) -> None: |
| 61 | + """Copy a directory recursively, excluding __pycache__ and .pyc files.""" |
| 62 | + if dst.exists(): |
| 63 | + shutil.rmtree(dst) |
| 64 | + |
| 65 | + def ignore_patterns(directory: str, files: list[str]) -> list[str]: |
| 66 | + return [f for f in files if f == "__pycache__" or f.endswith(".pyc")] |
| 67 | + |
| 68 | + shutil.copytree(src, dst, ignore=ignore_patterns) |
| 69 | + |
| 70 | + |
| 71 | +def update_gitignore(target_dir: Path) -> None: |
| 72 | + """Update .gitignore to include Augment indexer entries.""" |
| 73 | + gitignore_path = target_dir / ".gitignore" |
| 74 | + augment_entry = ".augment-index-state/" |
| 75 | + |
| 76 | + existing_content = "" |
| 77 | + if gitignore_path.exists(): |
| 78 | + existing_content = gitignore_path.read_text() |
| 79 | + |
| 80 | + if augment_entry not in existing_content: |
| 81 | + addition = "\n# Augment indexer files\n.augment-index-state/\n" |
| 82 | + if existing_content and not existing_content.endswith("\n"): |
| 83 | + addition = "\n" + addition |
| 84 | + gitignore_path.write_text(existing_content + addition) |
| 85 | + log_success("Updated .gitignore") |
| 86 | + else: |
| 87 | + log_warning(".gitignore already contains Augment indexer entries") |
| 88 | + |
| 89 | + |
| 90 | +def display_next_steps(target_dir: Path) -> None: |
| 91 | + """Display next steps after installation.""" |
| 92 | + log("\n" + colorize("bright", "🎉 Installation Complete!")) |
| 93 | + log("\nNext steps:\n") |
| 94 | + |
| 95 | + log(colorize("yellow", "1. Set up GitHub repository secrets:")) |
| 96 | + log(" Go to your repository Settings > Secrets and variables > Actions") |
| 97 | + log(" Add the following secrets:") |
| 98 | + log(" • AUGMENT_API_TOKEN - Your Augment API token") |
| 99 | + log(" • AUGMENT_API_URL - Your tenant-specific Augment API URL\n") |
| 100 | + |
| 101 | + log(colorize("yellow", "2. Push to trigger the workflow:")) |
| 102 | + log(" git add .") |
| 103 | + log(' git commit -m "Add Augment GitHub Action Indexer"') |
| 104 | + log(" git push\n") |
| 105 | + |
| 106 | + log(colorize("green", "The indexer will automatically run on pushes to main!")) |
| 107 | + |
| 108 | + log(colorize("yellow", "\n(Optional) Test locally first:")) |
| 109 | + log(f" cd {target_dir}") |
| 110 | + log(" pip install -r augment_indexer/requirements.txt") |
| 111 | + log(' export AUGMENT_API_TOKEN="your-token"') |
| 112 | + log(' export AUGMENT_API_URL="https://your-tenant.api.augmentcode.com/"') |
| 113 | + log(' export GITHUB_TOKEN="your-github-token"') |
| 114 | + log(' export GITHUB_REPOSITORY="owner/repo"') |
| 115 | + log(' export GITHUB_SHA="$(git rev-parse HEAD)"') |
| 116 | + log(" python -m augment_indexer.main") |
| 117 | + log(colorize("blue", "\nFor more information, see the documentation at:")) |
| 118 | + log("https://github.com/augmentcode/auggie/tree/main/examples/python-sdk/context/github_action_indexer\n") |
| 119 | + |
| 120 | + |
| 121 | +def main() -> None: |
| 122 | + """Main installation function.""" |
| 123 | + parser = argparse.ArgumentParser( |
| 124 | + description="Install the Augment GitHub Action Indexer into your repository" |
| 125 | + ) |
| 126 | + parser.add_argument( |
| 127 | + "target_dir", |
| 128 | + nargs="?", |
| 129 | + default=".", |
| 130 | + help="Target directory to install into (default: current directory)", |
| 131 | + ) |
| 132 | + args = parser.parse_args() |
| 133 | + |
| 134 | + # Resolve paths |
| 135 | + script_dir = Path(__file__).parent.resolve() |
| 136 | + target_dir = Path(args.target_dir).resolve() |
| 137 | + |
| 138 | + log(colorize("bright", "🚀 Augment GitHub Action Indexer Installation")) |
| 139 | + log("This script will set up the Augment GitHub Action Indexer in your repository.\n") |
| 140 | + |
| 141 | + log(colorize("bright", "📁 Target Directory")) |
| 142 | + log(f"Installing to: {colorize('cyan', str(target_dir))}\n") |
| 143 | + |
| 144 | + # Check if target directory exists |
| 145 | + if not target_dir.exists(): |
| 146 | + response = input(f"Directory {target_dir} doesn't exist. Create it? (y/N): ") |
| 147 | + if not response.lower().startswith("y"): |
| 148 | + log("Installation cancelled.") |
| 149 | + sys.exit(0) |
| 150 | + target_dir.mkdir(parents=True) |
| 151 | + log_success(f"Created directory {target_dir}") |
| 152 | + |
| 153 | + # Check if this looks like a git repository |
| 154 | + if not (target_dir / ".git").is_dir(): |
| 155 | + log_warning("This doesn't appear to be a Git repository.") |
| 156 | + response = input("Continue anyway? (y/N): ") |
| 157 | + if not response.lower().startswith("y"): |
| 158 | + log("Installation cancelled.") |
| 159 | + sys.exit(0) |
| 160 | + |
| 161 | + try: |
| 162 | + # Step 1: Copy augment_indexer directory (includes requirements.txt) |
| 163 | + log_step("1", "Copying augment_indexer directory...") |
| 164 | + src_indexer = script_dir / "augment_indexer" |
| 165 | + dst_indexer = target_dir / "augment_indexer" |
| 166 | + copy_directory(src_indexer, dst_indexer) |
| 167 | + log_success("Copied augment_indexer/ (includes requirements.txt)") |
| 168 | + |
| 169 | + # Step 2: Copy GitHub workflow |
| 170 | + log_step("2", "Creating GitHub workflow...") |
| 171 | + src_workflow = script_dir / ".github" / "workflows" / "augment-index.yml" |
| 172 | + dst_workflow_dir = target_dir / ".github" / "workflows" |
| 173 | + dst_workflow_dir.mkdir(parents=True, exist_ok=True) |
| 174 | + dst_workflow = dst_workflow_dir / "augment-index.yml" |
| 175 | + shutil.copy(src_workflow, dst_workflow) |
| 176 | + log_success("Created .github/workflows/augment-index.yml") |
| 177 | + |
| 178 | + # Step 3: Update .gitignore |
| 179 | + log_step("3", "Updating .gitignore...") |
| 180 | + update_gitignore(target_dir) |
| 181 | + |
| 182 | + # Display next steps |
| 183 | + display_next_steps(target_dir) |
| 184 | + |
| 185 | + except Exception as e: |
| 186 | + log_error(f"Installation failed: {e}") |
| 187 | + sys.exit(1) |
| 188 | + |
| 189 | + |
| 190 | +if __name__ == "__main__": |
| 191 | + main() |
| 192 | + |
0 commit comments