|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Auto-detect which TypeScript tests to run based on changed files from paths-filter |
| 5 | +# Uses paths-filter outputs from GitHub Actions: |
| 6 | +# ALL_CHANGED_FILES - all files changed in the PR (for logging) |
| 7 | +# SHARED_CHANGED - boolean indicating if shared infrastructure changed |
| 8 | +# MODULE_CHANGED_FILES - only files in registry/**/modules/** (for processing) |
| 9 | +# Runs all tests if shared infrastructure changes |
| 10 | +# |
| 11 | +# This script only runs tests for changed modules. Documentation and template changes are ignored. |
| 12 | + |
| 13 | +echo "==> Detecting changed files..." |
| 14 | + |
| 15 | +if [[ -n "${ALL_CHANGED_FILES:-}" ]]; then |
| 16 | + echo "Changed files in PR:" |
| 17 | + echo "$ALL_CHANGED_FILES" | tr ' ' '\n' | sed 's/^/ - /' |
| 18 | + echo "" |
| 19 | +fi |
| 20 | + |
| 21 | +if [[ "${SHARED_CHANGED:-false}" == "true" ]]; then |
| 22 | + echo "==> Shared infrastructure changed" |
| 23 | + echo "==> Running all tests for safety" |
| 24 | + exec bun test |
| 25 | +fi |
| 26 | + |
| 27 | +if [[ -z "${MODULE_CHANGED_FILES:-}" ]]; then |
| 28 | + echo "✓ No module files changed, skipping tests" |
| 29 | + exit 0 |
| 30 | +fi |
| 31 | + |
| 32 | +CHANGED_FILES=$(echo "$MODULE_CHANGED_FILES" | tr ' ' '\n') |
| 33 | + |
| 34 | +MODULE_DIRS=() |
| 35 | +while IFS= read -r file; do |
| 36 | + if [[ "$file" =~ \.(md|png|jpg|jpeg|svg)$ ]]; then |
| 37 | + continue |
| 38 | + fi |
| 39 | + |
| 40 | + if [[ "$file" =~ ^registry/([^/]+)/modules/([^/]+)/ ]]; then |
| 41 | + namespace="${BASH_REMATCH[1]}" |
| 42 | + module="${BASH_REMATCH[2]}" |
| 43 | + module_dir="registry/${namespace}/modules/${module}" |
| 44 | + |
| 45 | + if [[ -f "$module_dir/main.test.ts" ]] && [[ ! " ${MODULE_DIRS[*]} " =~ " ${module_dir} " ]]; then |
| 46 | + MODULE_DIRS+=("$module_dir") |
| 47 | + fi |
| 48 | + fi |
| 49 | +done <<< "$CHANGED_FILES" |
| 50 | + |
| 51 | +if [[ ${#MODULE_DIRS[@]} -eq 0 ]]; then |
| 52 | + echo "✓ No TypeScript tests to run" |
| 53 | + echo " (documentation, templates, namespace files, or modules without tests)" |
| 54 | + exit 0 |
| 55 | +fi |
| 56 | + |
| 57 | +echo "==> Running TypeScript tests for ${#MODULE_DIRS[@]} changed module(s):" |
| 58 | +for dir in "${MODULE_DIRS[@]}"; do |
| 59 | + echo " - $dir" |
| 60 | +done |
| 61 | +echo "" |
| 62 | + |
| 63 | +exec bun test "${MODULE_DIRS[@]}" |
0 commit comments