From 05bb78b0933c4f94ce983a9064f75d6136730aa2 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Tue, 14 Oct 2025 13:18:16 -0500 Subject: [PATCH 1/6] ci: update CI workflow to run TypeScript tests with new script with diff based detection --- .github/workflows/ci.yaml | 2 +- scripts/ts_test_auto.sh | 81 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100755 scripts/ts_test_auto.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9c676ec17..404a9a2b4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: bun install - name: Run TypeScript tests - run: bun test + run: ./scripts/ts_test_auto.sh - name: Run Terraform tests run: ./scripts/terraform_test_all.sh - name: Run Terraform Validate diff --git a/scripts/ts_test_auto.sh b/scripts/ts_test_auto.sh new file mode 100755 index 000000000..7dbe03d25 --- /dev/null +++ b/scripts/ts_test_auto.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Auto-detect which TypeScript tests to run based on git diff +# Falls back to running all tests if shared infrastructure changes +# +# This script only runs tests for changed modules. Documentation and template changes are ignored. + +SHARED_FILES=( + "test/" + "package.json" + "bun.lock" + "bunfig.toml" + "tsconfig.json" + ".github/workflows/ci.yaml" + "scripts/ts_test_auto.sh" +) + +echo "==> Detecting changed files..." + +if [[ -n "${GITHUB_BASE_REF:-}" ]]; then + BASE_REF="HEAD^1" + echo "Detected GitHub Actions PR, comparing against merge base: $BASE_REF" +else + BASE_REF="origin/main" + echo "Local development mode, comparing against: $BASE_REF" +fi + +if ! CHANGED_FILES=$(git diff --name-only "${BASE_REF}...HEAD" 2> /dev/null); then + echo "⚠️ Could not detect changes (git diff failed)" + echo "==> Running all tests for safety" + exec bun test +fi + +if [[ -z "$CHANGED_FILES" ]]; then + echo "✓ No files changed, skipping tests" + exit 0 +fi + +echo "Changed files:" +echo "$CHANGED_FILES" | sed 's/^/ - /' +echo "" + +for shared_file in "${SHARED_FILES[@]}"; do + if echo "$CHANGED_FILES" | grep -q "^${shared_file}"; then + echo "==> Shared infrastructure changed ($shared_file)" + echo "==> Running all tests for safety" + exec bun test + fi +done + +MODULE_DIRS=() +while IFS= read -r file; do + if [[ "$file" =~ \.(md|png|jpg|jpeg|svg)$ ]]; then + continue + fi + + if [[ "$file" =~ ^registry/([^/]+)/modules/([^/]+)/ ]]; then + namespace="${BASH_REMATCH[1]}" + module="${BASH_REMATCH[2]}" + module_dir="registry/${namespace}/modules/${module}" + + if [[ -f "$module_dir/main.test.ts" ]] && [[ ! " ${MODULE_DIRS[*]} " =~ " ${module_dir} " ]]; then + MODULE_DIRS+=("$module_dir") + fi + fi +done <<< "$CHANGED_FILES" + +if [[ ${#MODULE_DIRS[@]} -eq 0 ]]; then + echo "✓ No TypeScript tests to run" + echo " (documentation, templates, namespace files, or modules without tests)" + exit 0 +fi + +echo "==> Running TypeScript tests for ${#MODULE_DIRS[@]} changed module(s):" +for dir in "${MODULE_DIRS[@]}"; do + echo " - $dir" +done +echo "" + +exec bun test "${MODULE_DIRS[@]}" From 865804906c80d51e1da1feabaf9316596b08cb52 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Tue, 14 Oct 2025 13:26:37 -0500 Subject: [PATCH 2/6] fix: update base reference detection --- scripts/ts_test_auto.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ts_test_auto.sh b/scripts/ts_test_auto.sh index 7dbe03d25..72339ef1c 100755 --- a/scripts/ts_test_auto.sh +++ b/scripts/ts_test_auto.sh @@ -19,8 +19,8 @@ SHARED_FILES=( echo "==> Detecting changed files..." if [[ -n "${GITHUB_BASE_REF:-}" ]]; then - BASE_REF="HEAD^1" - echo "Detected GitHub Actions PR, comparing against merge base: $BASE_REF" + BASE_REF="origin/${GITHUB_BASE_REF}" + echo "Detected GitHub Actions PR, comparing against: $BASE_REF" else BASE_REF="origin/main" echo "Local development mode, comparing against: $BASE_REF" From 4cf919d6f8294bd1735e1af8b0f41d9ae86842d1 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Tue, 14 Oct 2025 13:31:01 -0500 Subject: [PATCH 3/6] ci: fetch the base branch for accurate context for diff check --- .github/workflows/ci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 404a9a2b4..2205d2994 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,6 +13,10 @@ jobs: steps: - name: Check out code uses: actions/checkout@v5 + with: + fetch-depth: 0 + - name: Fetch base branch + run: git fetch origin ${{ github.base_ref }} - name: Set up Terraform uses: coder/coder/.github/actions/setup-tf@main - name: Set up Bun From a2b8378ecd846138c9e39e6e904599bb4eb79bc3 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 15 Oct 2025 09:16:44 -0500 Subject: [PATCH 4/6] feat: change to use dorny/paths-filter --- .github/workflows/ci.yaml | 23 ++++++++++++++++++--- scripts/ts_test_auto.sh | 43 +++++++++------------------------------ 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2205d2994..5b86b8703 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,10 +13,24 @@ jobs: steps: - name: Check out code uses: actions/checkout@v5 + - name: Detect changed files + uses: dorny/paths-filter@v3 + id: filter with: - fetch-depth: 0 - - name: Fetch base branch - run: git fetch origin ${{ github.base_ref }} + list-files: shell + filters: | + shared: + - 'test/**' + - 'package.json' + - 'bun.lock' + - 'bunfig.toml' + - 'tsconfig.json' + - '.github/workflows/ci.yaml' + - 'scripts/ts_test_auto.sh' + modules: + - 'registry/**/modules/**' + all: + - '**' - name: Set up Terraform uses: coder/coder/.github/actions/setup-tf@main - name: Set up Bun @@ -31,6 +45,9 @@ jobs: - name: Install dependencies run: bun install - name: Run TypeScript tests + env: + CHANGED_FILES: ${{ steps.filter.outputs.all_files }} + SHARED_CHANGED: ${{ steps.filter.outputs.shared }} run: ./scripts/ts_test_auto.sh - name: Run Terraform tests run: ./scripts/terraform_test_all.sh diff --git a/scripts/ts_test_auto.sh b/scripts/ts_test_auto.sh index 72339ef1c..4e475574f 100755 --- a/scripts/ts_test_auto.sh +++ b/scripts/ts_test_auto.sh @@ -1,54 +1,31 @@ #!/usr/bin/env bash set -euo pipefail -# Auto-detect which TypeScript tests to run based on git diff -# Falls back to running all tests if shared infrastructure changes +# Auto-detect which TypeScript tests to run based on changed files from paths-filter +# Uses paths-filter outputs from GitHub Actions (CHANGED_FILES and SHARED_CHANGED env vars) +# Runs all tests if shared infrastructure changes # # This script only runs tests for changed modules. Documentation and template changes are ignored. -SHARED_FILES=( - "test/" - "package.json" - "bun.lock" - "bunfig.toml" - "tsconfig.json" - ".github/workflows/ci.yaml" - "scripts/ts_test_auto.sh" -) - echo "==> Detecting changed files..." -if [[ -n "${GITHUB_BASE_REF:-}" ]]; then - BASE_REF="origin/${GITHUB_BASE_REF}" - echo "Detected GitHub Actions PR, comparing against: $BASE_REF" -else - BASE_REF="origin/main" - echo "Local development mode, comparing against: $BASE_REF" +if [[ -z "${CHANGED_FILES:-}" ]]; then + echo "✓ No files changed, skipping tests" + exit 0 fi -if ! CHANGED_FILES=$(git diff --name-only "${BASE_REF}...HEAD" 2> /dev/null); then - echo "⚠️ Could not detect changes (git diff failed)" +CHANGED_FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n') + +if [[ "${SHARED_CHANGED:-false}" == "true" ]]; then + echo "==> Shared infrastructure changed" echo "==> Running all tests for safety" exec bun test fi -if [[ -z "$CHANGED_FILES" ]]; then - echo "✓ No files changed, skipping tests" - exit 0 -fi - echo "Changed files:" echo "$CHANGED_FILES" | sed 's/^/ - /' echo "" -for shared_file in "${SHARED_FILES[@]}"; do - if echo "$CHANGED_FILES" | grep -q "^${shared_file}"; then - echo "==> Shared infrastructure changed ($shared_file)" - echo "==> Running all tests for safety" - exec bun test - fi -done - MODULE_DIRS=() while IFS= read -r file; do if [[ "$file" =~ \.(md|png|jpg|jpeg|svg)$ ]]; then From 576c509dd6dd99f59b269b6ff90a088d7f3039a3 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 15 Oct 2025 13:46:18 -0500 Subject: [PATCH 5/6] ci: add modified files logging, and use modules filter instead of script logic. --- .github/workflows/ci.yaml | 3 ++- scripts/ts_test_auto.sh | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5b86b8703..1079f8eac 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,8 +46,9 @@ jobs: run: bun install - name: Run TypeScript tests env: - CHANGED_FILES: ${{ steps.filter.outputs.all_files }} + ALL_CHANGED_FILES: ${{ steps.filter.outputs.all_files }} SHARED_CHANGED: ${{ steps.filter.outputs.shared }} + MODULE_CHANGED_FILES: ${{ steps.filter.outputs.modules_files }} run: ./scripts/ts_test_auto.sh - name: Run Terraform tests run: ./scripts/terraform_test_all.sh diff --git a/scripts/ts_test_auto.sh b/scripts/ts_test_auto.sh index 4e475574f..62cf705da 100755 --- a/scripts/ts_test_auto.sh +++ b/scripts/ts_test_auto.sh @@ -2,19 +2,26 @@ set -euo pipefail # Auto-detect which TypeScript tests to run based on changed files from paths-filter -# Uses paths-filter outputs from GitHub Actions (CHANGED_FILES and SHARED_CHANGED env vars) +# Uses paths-filter outputs from GitHub Actions: +# ALL_CHANGED_FILES - all files changed in the PR (for logging) +# SHARED_CHANGED - boolean indicating if shared infrastructure changed +# MODULE_CHANGED_FILES - only files in registry/**/modules/** (for processing) # Runs all tests if shared infrastructure changes # # This script only runs tests for changed modules. Documentation and template changes are ignored. echo "==> Detecting changed files..." -if [[ -z "${CHANGED_FILES:-}" ]]; then - echo "✓ No files changed, skipping tests" - exit 0 +if [[ -n "${ALL_CHANGED_FILES:-}" ]]; then + echo "Changed files in PR:" + echo "$ALL_CHANGED_FILES" | tr ' ' '\n' | sed 's/^/ - /' + echo "" fi -CHANGED_FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n') +if [[ -z "${MODULE_CHANGED_FILES:-}" ]]; then + echo "✓ No module files changed, skipping tests" + exit 0 +fi if [[ "${SHARED_CHANGED:-false}" == "true" ]]; then echo "==> Shared infrastructure changed" @@ -22,9 +29,7 @@ if [[ "${SHARED_CHANGED:-false}" == "true" ]]; then exec bun test fi -echo "Changed files:" -echo "$CHANGED_FILES" | sed 's/^/ - /' -echo "" +CHANGED_FILES=$(echo "$MODULE_CHANGED_FILES" | tr ' ' '\n') MODULE_DIRS=() while IFS= read -r file; do From b6f2ff4366e30033c9b798f0c99fc2fdd3130c0f Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 15 Oct 2025 13:51:47 -0500 Subject: [PATCH 6/6] fix: reorder module change check in TypeScript test automation script --- scripts/ts_test_auto.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/ts_test_auto.sh b/scripts/ts_test_auto.sh index 62cf705da..5f28e3385 100755 --- a/scripts/ts_test_auto.sh +++ b/scripts/ts_test_auto.sh @@ -18,17 +18,17 @@ if [[ -n "${ALL_CHANGED_FILES:-}" ]]; then echo "" fi -if [[ -z "${MODULE_CHANGED_FILES:-}" ]]; then - echo "✓ No module files changed, skipping tests" - exit 0 -fi - if [[ "${SHARED_CHANGED:-false}" == "true" ]]; then echo "==> Shared infrastructure changed" echo "==> Running all tests for safety" exec bun test fi +if [[ -z "${MODULE_CHANGED_FILES:-}" ]]; then + echo "✓ No module files changed, skipping tests" + exit 0 +fi + CHANGED_FILES=$(echo "$MODULE_CHANGED_FILES" | tr ' ' '\n') MODULE_DIRS=()