|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Validates bridge naming conventions for Symfony AI components. |
| 4 | +# |
| 5 | +# Usage: validate-bridge-naming.sh <bridge_type> [component] [options_file] |
| 6 | +# |
| 7 | +# Arguments: |
| 8 | +# bridge_type Type of bridge (e.g., "store", "tool") - used in output messages and package suffix |
| 9 | +# component Name of the parent component (e.g., agent, platform, store) |
| 10 | +# If not provided, defaults to bridge_type |
| 11 | +# options_file Optional: Path to options.php file for config key validation (only needed for stores) |
| 12 | +# |
| 13 | +# Example: |
| 14 | +# validate-bridge-naming.sh store |
| 15 | +# validate-bridge-naming.sh store store src/ai-bundle/config/options.php |
| 16 | +# validate-bridge-naming.sh tool agent |
| 17 | +# |
| 18 | +# The script builds the bridge path internally as: src/${component}/src/Bridge/* |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +BRIDGE_TYPE="${1:?Bridge type is required (e.g., store, tool)}" |
| 23 | +COMPONENT="${2:-$BRIDGE_TYPE}" |
| 24 | +BRIDGE_PATH="src/${COMPONENT}/src/Bridge/*" |
| 25 | +OPTIONS_FILE="${3:-}" |
| 26 | + |
| 27 | +ERRORS=0 |
| 28 | + |
| 29 | +# Find all bridges with composer.json |
| 30 | +for composer_file in ${BRIDGE_PATH}/composer.json; do |
| 31 | + if [[ ! -f "$composer_file" ]]; then |
| 32 | + continue |
| 33 | + fi |
| 34 | + |
| 35 | + # Get the bridge directory name (e.g., ChromaDb) |
| 36 | + bridge_dir=$(dirname "$composer_file") |
| 37 | + bridge_name=$(basename "$bridge_dir") |
| 38 | + |
| 39 | + # Get the package name from composer.json |
| 40 | + package_name=$(jq -r '.name' "$composer_file") |
| 41 | + |
| 42 | + # Expected package name format: symfony/ai-{lowercase-with-dashes}-{type} |
| 43 | + # Convert PascalCase to kebab-case (e.g., ChromaDb -> chroma-db) |
| 44 | + expected_kebab=$(echo "$bridge_name" | sed 's/\([a-z]\)\([A-Z]\)/\1-\2/g' | tr '[:upper:]' '[:lower:]') |
| 45 | + expected_package="symfony/ai-${expected_kebab}-${BRIDGE_TYPE}" |
| 46 | + |
| 47 | + if [[ "$package_name" != "$expected_package" ]]; then |
| 48 | + echo "::error file=$composer_file::Package name '$package_name' does not match expected '$expected_package' for bridge '$bridge_name'" |
| 49 | + ERRORS=$((ERRORS + 1)) |
| 50 | + else |
| 51 | + echo "✓ $bridge_name: package name '$package_name' is correct" |
| 52 | + fi |
| 53 | + |
| 54 | + # Check options.php for the config key if options file is provided |
| 55 | + if [[ -n "$OPTIONS_FILE" && -f "$OPTIONS_FILE" ]]; then |
| 56 | + # Expected config key should be lowercase without dashes/underscores |
| 57 | + expected_config_key=$(echo "$bridge_name" | tr '[:upper:]' '[:lower:]') |
| 58 | + |
| 59 | + # Look for ->arrayNode('configkey') in the options file |
| 60 | + if ! grep -q -- "->arrayNode('$expected_config_key')" "$OPTIONS_FILE"; then |
| 61 | + echo "::error file=$OPTIONS_FILE::Missing or incorrect config key for bridge '$bridge_name'. Expected '->arrayNode('$expected_config_key')' in ${BRIDGE_TYPE} configuration" |
| 62 | + ERRORS=$((ERRORS + 1)) |
| 63 | + else |
| 64 | + echo "✓ $bridge_name: config key '$expected_config_key' found in options.php" |
| 65 | + fi |
| 66 | + fi |
| 67 | +done |
| 68 | + |
| 69 | +if [[ $ERRORS -gt 0 ]]; then |
| 70 | + echo "" |
| 71 | + echo "::error::Found $ERRORS naming convention violation(s)" |
| 72 | + exit 1 |
| 73 | +fi |
| 74 | + |
| 75 | +echo "" |
| 76 | +echo "All ${BRIDGE_TYPE} bridge naming conventions are valid!" |
0 commit comments