|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Validates that all bridges have the correct "type" field in composer.json. |
| 4 | +# |
| 5 | +# Usage: validate-bridge-type.sh <bridge_type> [component] |
| 6 | +# |
| 7 | +# Arguments: |
| 8 | +# bridge_type Type of bridge (e.g., "store", "tool", "platform", "message-store") |
| 9 | +# This determines the expected composer.json type: symfony-ai-{bridge_type} |
| 10 | +# component Name of the parent component (e.g., agent, platform, store, chat) |
| 11 | +# If not provided, defaults to bridge_type |
| 12 | +# |
| 13 | +# Example: |
| 14 | +# validate-bridge-type.sh store |
| 15 | +# validate-bridge-type.sh tool agent |
| 16 | +# validate-bridge-type.sh message-store chat |
| 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, platform, message-store)}" |
| 23 | +COMPONENT="${2:-$BRIDGE_TYPE}" |
| 24 | +BRIDGE_PATH="src/${COMPONENT}/src/Bridge/*" |
| 25 | + |
| 26 | +EXPECTED_TYPE="symfony-ai-${BRIDGE_TYPE}" |
| 27 | +ERRORS=0 |
| 28 | + |
| 29 | +echo "Validating ${BRIDGE_TYPE} bridges have correct type (${BRIDGE_PATH})..." |
| 30 | +echo "Expected type: ${EXPECTED_TYPE}" |
| 31 | +echo "" |
| 32 | + |
| 33 | +for composer_file in ${BRIDGE_PATH}/composer.json; do |
| 34 | + if [[ ! -f "$composer_file" ]]; then |
| 35 | + continue |
| 36 | + fi |
| 37 | + |
| 38 | + bridge_dir=$(dirname "$composer_file") |
| 39 | + bridge_name=$(basename "$bridge_dir") |
| 40 | + |
| 41 | + actual_type=$(jq -r '.type // empty' "$composer_file") |
| 42 | + |
| 43 | + if [[ -z "$actual_type" ]]; then |
| 44 | + echo "::error file=$composer_file::${BRIDGE_TYPE} bridge '$bridge_name' is missing 'type' field in composer.json" |
| 45 | + ERRORS=$((ERRORS + 1)) |
| 46 | + elif [[ "$actual_type" != "$EXPECTED_TYPE" ]]; then |
| 47 | + echo "::error file=$composer_file::${BRIDGE_TYPE} bridge '$bridge_name' has incorrect type '$actual_type', expected '$EXPECTED_TYPE'" |
| 48 | + ERRORS=$((ERRORS + 1)) |
| 49 | + else |
| 50 | + echo "✓ $bridge_name: type '$actual_type' is correct" |
| 51 | + fi |
| 52 | +done |
| 53 | + |
| 54 | +if [[ $ERRORS -gt 0 ]]; then |
| 55 | + echo "" |
| 56 | + echo "::error::Found $ERRORS type validation error(s) in ${BRIDGE_TYPE} bridges" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +echo "" |
| 61 | +echo "All ${BRIDGE_TYPE} bridges have the correct type!" |
0 commit comments