Skip to content

Commit ef99dbd

Browse files
committed
Enhance PostgreSQL CI workflow with improved error handling and test reporting
1 parent 588ac8e commit ef99dbd

1 file changed

Lines changed: 160 additions & 25 deletions

File tree

.github/workflows/postgresql-test.yml

Lines changed: 160 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ jobs:
352352
if: steps.verify-postgresql.outputs.success == 'true'
353353
continue-on-error: true
354354
run: |
355-
$ErrorActionPreference = "Continue"
355+
$ErrorActionPreference = "Stop"
356356
$binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
357357
358358
Write-Host "=== Phase 2: Test Basic Functionality ==="
@@ -362,30 +362,81 @@ jobs:
362362
$postgresExe = Join-Path $binPath "postgres.exe"
363363
$psqlExe = Join-Path $binPath "psql.exe"
364364
$initdbExe = Join-Path $binPath "initdb.exe"
365+
$pgCtlExe = Join-Path $binPath "pg_ctl.exe"
365366
367+
$allFunctional = $true
368+
$testResults = @()
369+
366370
Write-Host "`nTesting postgres.exe --version..."
367-
$pgVersion = & $postgresExe --version 2>&1 | Out-String
368-
Write-Host $pgVersion
369-
371+
try {
372+
$pgVersion = & $postgresExe --version 2>&1
373+
Write-Host $pgVersion
374+
if ($LASTEXITCODE -eq 0) {
375+
Write-Host "✅ postgres.exe is functional"
376+
$testResults += "postgres: PASS"
377+
} else {
378+
Write-Host "❌ postgres.exe failed with exit code: $LASTEXITCODE"
379+
$allFunctional = $false
380+
$testResults += "postgres: FAIL"
381+
}
382+
} catch {
383+
Write-Host "❌ postgres.exe error: $_"
384+
$allFunctional = $false
385+
$testResults += "postgres: ERROR"
386+
}
387+
370388
Write-Host "`nTesting psql.exe --version..."
371-
$psqlVersion = & $psqlExe --version 2>&1 | Out-String
372-
Write-Host $psqlVersion
373-
389+
try {
390+
$psqlVersion = & $psqlExe --version 2>&1
391+
Write-Host $psqlVersion
392+
if ($LASTEXITCODE -eq 0) {
393+
Write-Host "✅ psql.exe is functional"
394+
$testResults += "psql: PASS"
395+
} else {
396+
Write-Host "❌ psql.exe failed with exit code: $LASTEXITCODE"
397+
$allFunctional = $false
398+
$testResults += "psql: FAIL"
399+
}
400+
} catch {
401+
Write-Host "❌ psql.exe error: $_"
402+
$allFunctional = $false
403+
$testResults += "psql: ERROR"
404+
}
405+
374406
Write-Host "`nTesting initdb.exe --version..."
375-
$initdbVersion = & $initdbExe --version 2>&1 | Out-String
376-
Write-Host $initdbVersion
377-
378-
if ($LASTEXITCODE -eq 0) {
407+
try {
408+
$initdbVersion = & $initdbExe --version 2>&1
409+
Write-Host $initdbVersion
410+
if ($LASTEXITCODE -eq 0) {
411+
Write-Host "✅ initdb.exe is functional"
412+
$testResults += "initdb: PASS"
413+
} else {
414+
Write-Host "❌ initdb.exe failed with exit code: $LASTEXITCODE"
415+
$allFunctional = $false
416+
$testResults += "initdb: FAIL"
417+
}
418+
} catch {
419+
Write-Host "❌ initdb.exe error: $_"
420+
$allFunctional = $false
421+
$testResults += "initdb: ERROR"
422+
}
423+
424+
Write-Host "`nTest Results:"
425+
$testResults | ForEach-Object { Write-Host " $_" }
426+
427+
if ($allFunctional) {
379428
Write-Host "`n✅ All executables are functional"
380429
echo "success=true" >> $env:GITHUB_OUTPUT
381430
} else {
382431
Write-Host "`n❌ Some executables failed"
383432
echo "success=false" >> $env:GITHUB_OUTPUT
433+
echo "error=One or more executables failed version test" >> $env:GITHUB_OUTPUT
384434
exit 1
385435
}
386436
} catch {
387437
Write-Host "❌ Error testing executables: $_"
388438
echo "success=false" >> $env:GITHUB_OUTPUT
439+
echo "error=$($_.Exception.Message)" >> $env:GITHUB_OUTPUT
389440
exit 1
390441
}
391442
@@ -402,6 +453,7 @@ jobs:
402453
403454
# Get error messages if any
404455
$error1_1 = "${{ steps.download-postgresql.outputs.error }}"
456+
$error2 = "${{ steps.test-basic.outputs.error }}"
405457
406458
$summary = "### PostgreSQL $version`n`n"
407459
@@ -414,7 +466,11 @@ jobs:
414466
415467
if ($phase1_2) {
416468
$summary += "**Phase 2: Basic Functionality**`n"
417-
$summary += "- Test Executables: $(if ($phase2) { '✅ PASS' } else { '❌ FAIL' })`n`n"
469+
$summary += "- Test Executables: $(if ($phase2) { '✅ PASS' } else { '❌ FAIL' })`n"
470+
if (-not $phase2 -and $error2) {
471+
$summary += " - Error: $error2`n"
472+
}
473+
$summary += "`n"
418474
}
419475
420476
# Overall status
@@ -436,6 +492,12 @@ jobs:
436492
437493
Write-Host $summary
438494
$summary | Out-File "test-results/summary.md"
495+
496+
# Set job outcome based on test results
497+
if (-not $allPassed) {
498+
Write-Host "##[error]Tests failed for PostgreSQL $version"
499+
exit 1
500+
}
439501
440502
- name: Upload Test Results
441503
if: always()
@@ -465,7 +527,22 @@ jobs:
465527
466528
# Determine overall test status
467529
TEST_STATUS="${{ needs.test-postgresql.result }}"
468-
if [ "$TEST_STATUS" = "success" ]; then
530+
VERSIONS='${{ needs.detect-versions.outputs.versions }}'
531+
532+
if [ "$TEST_STATUS" = "skipped" ] || [ "$VERSIONS" = "[]" ]; then
533+
echo "**Status:** ⏭️ Tests skipped - no versions to test" >> comment.md
534+
echo "" >> comment.md
535+
echo "ℹ️ **Why were tests skipped?**" >> comment.md
536+
echo "" >> comment.md
537+
echo "Tests are only run when:" >> comment.md
538+
echo "- \`releases.properties\` is modified with new/updated versions, OR" >> comment.md
539+
echo "- PR title contains version numbers (e.g., \"17.2\", \"16.6\") that exist in \`releases.properties\`" >> comment.md
540+
echo "" >> comment.md
541+
echo "**To trigger tests:**" >> comment.md
542+
echo "1. Add version numbers to your PR title (e.g., \"Update docs for PostgreSQL 17.2\")" >> comment.md
543+
echo "2. Or modify \`releases.properties\` to add/update versions" >> comment.md
544+
echo "3. Or manually trigger the workflow from the Actions tab" >> comment.md
545+
elif [ "$TEST_STATUS" = "success" ]; then
469546
echo "**Status:** ✅ All tests passed" >> comment.md
470547
elif [ "$TEST_STATUS" = "failure" ]; then
471548
echo "**Status:** ❌ Some tests failed" >> comment.md
@@ -475,6 +552,38 @@ jobs:
475552
476553
echo "" >> comment.md
477554
555+
# Generate badges for each version
556+
if [ "$TEST_STATUS" != "skipped" ] && [ "$VERSIONS" != "[]" ]; then
557+
echo "### 📊 Test Results by Version" >> comment.md
558+
echo "" >> comment.md
559+
560+
# Parse versions and check results
561+
VERSION_LIST=$(echo '${{ needs.detect-versions.outputs.versions }}' | jq -r '.[]')
562+
563+
for version in $VERSION_LIST; do
564+
# Check if summary file exists for this version
565+
SUMMARY_FILE="all-results/test-results-postgresql-${version}/summary.md"
566+
567+
if [ -f "$SUMMARY_FILE" ]; then
568+
# Check if tests passed by looking for "ALL TESTS PASSED" in summary
569+
if grep -q "ALL TESTS PASSED" "$SUMMARY_FILE"; then
570+
# Success badge (green)
571+
echo "![PostgreSQL ${version}](https://img.shields.io/badge/PostgreSQL_${version}-PASS-success?style=flat-square&logo=postgresql&logoColor=white)" >> comment.md
572+
else
573+
# Failure badge (red)
574+
echo "![PostgreSQL ${version}](https://img.shields.io/badge/PostgreSQL_${version}-FAIL-critical?style=flat-square&logo=postgresql&logoColor=white)" >> comment.md
575+
fi
576+
else
577+
# No results badge (gray)
578+
echo "![PostgreSQL ${version}](https://img.shields.io/badge/PostgreSQL_${version}-NO_RESULTS-inactive?style=flat-square&logo=postgresql&logoColor=white)" >> comment.md
579+
fi
580+
done
581+
582+
echo "" >> comment.md
583+
fi
584+
585+
echo "" >> comment.md
586+
478587
# Check if artifacts exist
479588
if [ -d "all-results" ]; then
480589
# Count expected vs actual results
@@ -484,30 +593,56 @@ jobs:
484593
echo "**Results:** $ACTUAL_COUNT of $EXPECTED_COUNT versions tested" >> comment.md
485594
echo "" >> comment.md
486595
596+
# Check if there are any failures
597+
HAS_FAILURES=false
487598
for version_dir in all-results/test-results-postgresql-*; do
488599
if [ -d "$version_dir" ]; then
489600
for summary_file in "$version_dir"/summary.md; do
490601
if [ -f "$summary_file" ]; then
491-
cat "$summary_file" >> comment.md
492-
echo "" >> comment.md
602+
if ! grep -q "ALL TESTS PASSED" "$summary_file"; then
603+
HAS_FAILURES=true
604+
break 2
605+
fi
493606
fi
494607
done
495608
fi
496609
done
497-
else
610+
611+
# Only show detailed results if there are failures
612+
if [ "$HAS_FAILURES" = true ]; then
613+
echo "### 📋 Detailed Test Results" >> comment.md
614+
echo "" >> comment.md
615+
616+
for version_dir in all-results/test-results-postgresql-*; do
617+
if [ -d "$version_dir" ]; then
618+
for summary_file in "$version_dir"/summary.md; do
619+
if [ -f "$summary_file" ]; then
620+
cat "$summary_file" >> comment.md
621+
echo "" >> comment.md
622+
fi
623+
done
624+
fi
625+
done
626+
else
627+
echo "_All tests passed successfully! ✨_" >> comment.md
628+
echo "" >> comment.md
629+
fi
630+
elif [ "$TEST_STATUS" != "skipped" ] && [ "$VERSIONS" != "[]" ]; then
498631
echo "⚠️ No test results available" >> comment.md
499632
echo "" >> comment.md
500633
fi
501634
502-
echo "---" >> comment.md
503-
echo "" >> comment.md
504-
echo "### 📋 Test Phases" >> comment.md
505-
echo "" >> comment.md
506-
echo "Each version is tested through the following phases:" >> comment.md
507-
echo "- **Phase 1:** Installation Validation (Download, Extract, Verify Executables)" >> comment.md
508-
echo "- **Phase 2:** Basic Functionality (Test Executable Versions)" >> comment.md
509-
echo "" >> comment.md
510-
echo "_Check artifacts for detailed logs._" >> comment.md
635+
if [ "$TEST_STATUS" != "skipped" ] && [ "$VERSIONS" != "[]" ]; then
636+
echo "---" >> comment.md
637+
echo "" >> comment.md
638+
echo "### 📋 Test Phases" >> comment.md
639+
echo "" >> comment.md
640+
echo "Each version is tested through the following phases:" >> comment.md
641+
echo "- **Phase 1:** Installation Validation (Download, Extract, Verify Executables)" >> comment.md
642+
echo "- **Phase 2:** Basic Functionality (Test Executable Versions)" >> comment.md
643+
echo "" >> comment.md
644+
echo "_Check artifacts for detailed logs._" >> comment.md
645+
fi
511646
512647
cat comment.md
513648

0 commit comments

Comments
 (0)