@@ -219,76 +219,70 @@ jobs:
219219
220220 - name : Analyze test changes
221221 id : analyze_tests
222+ shell : bash
222223 run : |
223- # Create temporary files for storing test lists
224+ set -e
225+
226+ echo "Creating temporary files..."
224227 current_tests_file=$(mktemp)
225228 base_tests_file=$(mktemp)
226229
227- # Function to extract test names from a file
228- extract_tests() {
229- local file=$1
230- if [ -f "$file" ]; then
231- grep -E "test\(['\"]" "$file" | sed -E "s/.*test\(['\"]([^'\"]+)['\"].*/\1/"
232- fi
230+ function cleanup {
231+ echo "Cleaning up temporary files..."
232+ rm -f "$current_tests_file" "$base_tests_file"
233233 }
234+ trap cleanup EXIT
234235
235- # Get list of test files
236- test_files=$(find tests/suites -type f -name "*.test.ts")
236+ echo "Setting up git configuration..."
237+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
238+ git config --global user.name "github-actions[bot]"
237239
238- # First pass: current branch tests
239- for file in $test_files; do
240- tests=$(extract_tests "$file")
241- if [ ! -z "$tests" ]; then
242- while IFS= read -r test_name; do
243- echo "$test_name|$file" >> "$current_tests_file"
244- done <<< "$tests"
245- fi
246- done
240+ echo "Extracting current branch tests..."
241+ find tests/suites -type f -name "*.test.ts" -exec sh -c '
242+ file="$1"
243+ grep -E "test\(['\\\"]" "$file" | sed -E "s/.*test\(['\\\"]([^'\\\"]+)['\\\"].*/\1/" | while read -r test_name; do
244+ echo "$test_name|$file"
245+ done
246+ ' sh {} \; > "$current_tests_file"
247247
248- # Fetch and checkout main branch temporarily
248+ echo "Fetching main branch..."
249249 git fetch origin main:main
250+
251+ echo "Saving current branch name..."
250252 current_branch=$(git rev-parse --abbrev-ref HEAD)
253+
254+ echo "Checking out main branch..."
251255 git checkout main
252256
253- # Second pass: main branch tests
254- for file in $test_files; do
255- if [ -f "$file" ]; then
256- tests=$(extract_tests "$file")
257- if [ ! -z "$tests" ]; then
258- while IFS= read -r test_name; do
259- echo "$test_name|$file" >> "$base_tests_file"
260- done <<< "$tests"
261- fi
262- fi
263- done
264-
265- # Switch back to original branch
257+ echo "Extracting main branch tests..."
258+ find tests/suites -type f -name "*.test.ts" -exec sh -c '
259+ file="$1"
260+ if [ -f "$file" ]; then
261+ grep -E "test\(['\\\"]" "$file" | sed -E "s/.*test\(['\\\"]([^'\\\"]+)['\\\"].*/\1/" | while read -r test_name; do
262+ echo "$test_name|$file"
263+ done
264+ fi
265+ ' sh {} \; > "$base_tests_file"
266+
267+ echo "Returning to original branch..."
266268 git checkout "$current_branch"
267269
268- # Compare and build test details
270+ echo "Comparing test files..."
269271 new_tests=0
270272 test_details=""
271273
272274 while IFS='|' read -r test_name file; do
273- if ! grep -Fq "$test_name|" "$base_tests_file"; then
274- ((new_tests++))
275- test_details+="- ✨ Added test: \`$test_name\` in \`$file\`\\n"
276- fi
275+ if ! grep -Fq "$test_name|" "$base_tests_file"; then
276+ ((new_tests++))
277+ test_details+="- ✨ Added test: \`$test_name\` in \`$file\`\\n"
278+ fi
277279 done < "$current_tests_file"
278280
279- # Escape the test details for GitHub Actions
280- test_details="${test_details//'%'/'%25'}"
281- test_details="${test_details//$'\n'/'%0A'}"
282- test_details="${test_details//$'\r'/'%0D'}"
283-
284281 echo "new_tests=$new_tests" >> $GITHUB_OUTPUT
285282 echo "test_details<<EOF" >> $GITHUB_OUTPUT
286- echo "$test_details" >> $GITHUB_OUTPUT
283+ echo -e "$test_details" >> $GITHUB_OUTPUT
287284 echo "EOF" >> $GITHUB_OUTPUT
288285
289- # Cleanup
290- rm "$current_tests_file" "$base_tests_file"
291-
292286 - name : Update PR description
293287 uses : actions/github-script@v6
294288 with :
0 commit comments