@@ -318,308 +318,48 @@ jobs:
318318 exit 1
319319 }
320320
321- - name : Phase 2.1 - Initialize Database Cluster
322- id : init-database
321+ - name : Phase 2 - Test Basic Functionality
322+ id : test-basic
323323 if : steps.verify-postgresql.outputs.success == 'true'
324324 continue-on-error : true
325325 run : |
326326 $ErrorActionPreference = "Continue"
327327 $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
328- $dataDir = Join-Path (Get-Location) "test-data\pgdata"
329328
330- Write-Host "=== Phase 2.1: Initialize Database Cluster ==="
331- Write-Host "Data directory: $dataDir"
329+ Write-Host "=== Phase 2: Test Basic Functionality ==="
332330
331+ # Test that executables can run and show version
333332 try {
333+ $postgresExe = Join-Path $binPath "postgres.exe"
334+ $psqlExe = Join-Path $binPath "psql.exe"
334335 $initdbExe = Join-Path $binPath "initdb.exe"
335336
336- # Initialize the database cluster
337- Write-Host "Initializing database cluster..."
338- $output = & $initdbExe -D $dataDir -U postgres -A trust --locale=C --encoding=UTF8 2>&1 | Out-String
339-
340- if ($LASTEXITCODE -eq 0) {
341- Write-Host "✅ Database cluster initialized successfully"
342- Write-Host $output
343- echo "success=true" >> $env:GITHUB_OUTPUT
344- echo "data-dir=$dataDir" >> $env:GITHUB_OUTPUT
345- } else {
346- Write-Host "❌ Database initialization failed"
347- Write-Host $output
348- echo "success=false" >> $env:GITHUB_OUTPUT
349- exit 1
350- }
351- } catch {
352- Write-Host "❌ Error initializing database: $_"
353- echo "success=false" >> $env:GITHUB_OUTPUT
354- exit 1
355- }
356-
357- - name : Phase 2.2 - Start PostgreSQL Server
358- id : start-server
359- if : steps.init-database.outputs.success == 'true'
360- continue-on-error : true
361- timeout-minutes : 3
362- run : |
363- $ErrorActionPreference = "Continue"
364- $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
365- $dataDir = "${{ steps.init-database.outputs.data-dir }}"
366- $logFile = Join-Path (Get-Location) "test-results\postgresql.log"
367-
368- Write-Host "=== Phase 2.2: Start PostgreSQL Server ==="
369-
370- try {
371- $pgCtlExe = Join-Path $binPath "pg_ctl.exe"
372-
373- # Start the server with timeout
374- Write-Host "Starting PostgreSQL server..."
375- $startJob = Start-Job -ScriptBlock {
376- param($pgCtl, $data, $log)
377- & $pgCtl -D $data -l $log -w -t 30 start 2>&1 | Out-String
378- } -ArgumentList $pgCtlExe, $dataDir, $logFile
337+ Write-Host "`nTesting postgres.exe --version..."
338+ $pgVersion = & $postgresExe --version 2>&1 | Out-String
339+ Write-Host $pgVersion
379340
380- # Wait for the job with timeout
381- $completed = Wait-Job -Job $startJob -Timeout 60
341+ Write-Host "`nTesting psql.exe --version..."
342+ $psqlVersion = & $psqlExe --version 2>&1 | Out-String
343+ Write-Host $psqlVersion
382344
383- if ($completed) {
384- $output = Receive-Job -Job $startJob
385- Write-Host $output
386- Remove-Job -Job $startJob -Force
387- } else {
388- Write-Host "⚠️ Server start timed out after 60 seconds"
389- Stop-Job -Job $startJob
390- Remove-Job -Job $startJob -Force
391- }
392-
393- # Wait a bit for server to stabilize
394- Write-Host "Waiting for server to stabilize..."
395- Start-Sleep -Seconds 3
396-
397- # Check server status
398- Write-Host "Checking server status..."
399- $statusOutput = & $pgCtlExe -D $dataDir status 2>&1 | Out-String
400- Write-Host $statusOutput
401-
402- if ($statusOutput -match "server is running") {
403- Write-Host "✅ PostgreSQL server is running"
404-
405- # Display server log
406- if (Test-Path $logFile) {
407- Write-Host "Server log (last 20 lines):"
408- Get-Content $logFile -Tail 20 | Write-Host
409- }
410-
411- echo "success=true" >> $env:GITHUB_OUTPUT
412- echo "log-file=$logFile" >> $env:GITHUB_OUTPUT
413- } else {
414- Write-Host "❌ Server is not running"
415- if (Test-Path $logFile) {
416- Write-Host "Server log:"
417- Get-Content $logFile | Write-Host
418- }
419- echo "success=false" >> $env:GITHUB_OUTPUT
420- exit 1
421- }
422- } catch {
423- Write-Host "❌ Error starting server: $_"
424- Write-Host "Error details: $($_.Exception.Message)"
425- if (Test-Path $logFile) {
426- Write-Host "Server log:"
427- Get-Content $logFile | Write-Host
428- }
429- echo "success=false" >> $env:GITHUB_OUTPUT
430- exit 1
431- }
432-
433- - name : Phase 3.1 - Test Database Connection
434- id : test-connection
435- if : steps.start-server.outputs.success == 'true'
436- continue-on-error : true
437- run : |
438- $ErrorActionPreference = "Continue"
439- $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
440-
441- Write-Host "=== Phase 3.1: Test Database Connection ==="
442-
443- try {
444- $psqlExe = Join-Path $binPath "psql.exe"
445-
446- # Test connection to default postgres database
447- Write-Host "Testing connection to postgres database..."
448- $output = & $psqlExe -U postgres -d postgres -c "SELECT version();" 2>&1 | Out-String
345+ Write-Host "`nTesting initdb.exe --version..."
346+ $initdbVersion = & $initdbExe --version 2>&1 | Out-String
347+ Write-Host $initdbVersion
449348
450349 if ($LASTEXITCODE -eq 0) {
451- Write-Host "✅ Connection successful"
452- Write-Host $output
350+ Write-Host "`n✅ All executables are functional"
453351 echo "success=true" >> $env:GITHUB_OUTPUT
454352 } else {
455- Write-Host "❌ Connection failed"
456- Write-Host $output
353+ Write-Host "`n❌ Some executables failed"
457354 echo "success=false" >> $env:GITHUB_OUTPUT
458355 exit 1
459356 }
460357 } catch {
461- Write-Host "❌ Error testing connection : $_"
358+ Write-Host "❌ Error testing executables : $_"
462359 echo "success=false" >> $env:GITHUB_OUTPUT
463360 exit 1
464361 }
465362
466- - name : Phase 3.2 - Test Database Creation
467- id : test-create-db
468- if : steps.test-connection.outputs.success == 'true'
469- continue-on-error : true
470- run : |
471- $ErrorActionPreference = "Continue"
472- $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
473- $testDbName = "bearsampp_test_db"
474-
475- Write-Host "=== Phase 3.2: Test Database Creation ==="
476-
477- try {
478- $createdbExe = Join-Path $binPath "createdb.exe"
479- $psqlExe = Join-Path $binPath "psql.exe"
480-
481- # Create test database
482- Write-Host "Creating test database: $testDbName"
483- $output = & $createdbExe -U postgres $testDbName 2>&1 | Out-String
484-
485- if ($LASTEXITCODE -eq 0) {
486- Write-Host "✅ Database created successfully"
487-
488- # Verify database exists
489- Write-Host "Verifying database exists..."
490- $verifyOutput = & $psqlExe -U postgres -d postgres -c "\l" 2>&1 | Out-String
491-
492- if ($verifyOutput -match $testDbName) {
493- Write-Host "✅ Database verified in database list"
494-
495- # Create a test table
496- Write-Host "Creating test table..."
497- $tableOutput = & $psqlExe -U postgres -d $testDbName -c "CREATE TABLE test_table (id SERIAL PRIMARY KEY, name VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);" 2>&1 | Out-String
498-
499- if ($LASTEXITCODE -eq 0) {
500- Write-Host "✅ Test table created"
501-
502- # Insert test data
503- Write-Host "Inserting test data..."
504- $insertOutput = & $psqlExe -U postgres -d $testDbName -c "INSERT INTO test_table (name) VALUES ('Bearsampp Test 1'), ('Bearsampp Test 2');" 2>&1 | Out-String
505-
506- if ($LASTEXITCODE -eq 0) {
507- Write-Host "✅ Test data inserted"
508-
509- # Query test data
510- Write-Host "Querying test data..."
511- $queryOutput = & $psqlExe -U postgres -d $testDbName -c "SELECT * FROM test_table;" 2>&1 | Out-String
512- Write-Host $queryOutput
513-
514- if ($LASTEXITCODE -eq 0) {
515- Write-Host "✅ Test data queried successfully"
516- echo "success=true" >> $env:GITHUB_OUTPUT
517- echo "test-db=$testDbName" >> $env:GITHUB_OUTPUT
518- } else {
519- Write-Host "❌ Failed to query test data"
520- echo "success=false" >> $env:GITHUB_OUTPUT
521- }
522- } else {
523- Write-Host "❌ Failed to insert test data"
524- echo "success=false" >> $env:GITHUB_OUTPUT
525- }
526- } else {
527- Write-Host "❌ Failed to create test table"
528- echo "success=false" >> $env:GITHUB_OUTPUT
529- }
530- } else {
531- Write-Host "❌ Database not found in list"
532- echo "success=false" >> $env:GITHUB_OUTPUT
533- }
534- } else {
535- Write-Host "❌ Database creation failed"
536- Write-Host $output
537- echo "success=false" >> $env:GITHUB_OUTPUT
538- exit 1
539- }
540- } catch {
541- Write-Host "❌ Error creating database: $_"
542- echo "success=false" >> $env:GITHUB_OUTPUT
543- exit 1
544- }
545-
546- - name : Phase 3.3 - Test Database Deletion
547- id : test-delete-db
548- if : steps.test-create-db.outputs.success == 'true'
549- continue-on-error : true
550- run : |
551- $ErrorActionPreference = "Continue"
552- $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
553- $testDbName = "${{ steps.test-create-db.outputs.test-db }}"
554-
555- Write-Host "=== Phase 3.3: Test Database Deletion ==="
556-
557- try {
558- $dropdbExe = Join-Path $binPath "dropdb.exe"
559- $psqlExe = Join-Path $binPath "psql.exe"
560-
561- # Drop test database
562- Write-Host "Dropping test database: $testDbName"
563- $output = & $dropdbExe -U postgres $testDbName 2>&1 | Out-String
564-
565- if ($LASTEXITCODE -eq 0) {
566- Write-Host "✅ Database dropped successfully"
567-
568- # Verify database no longer exists
569- Write-Host "Verifying database was deleted..."
570- $verifyOutput = & $psqlExe -U postgres -d postgres -c "\l" 2>&1 | Out-String
571-
572- if ($verifyOutput -notmatch $testDbName) {
573- Write-Host "✅ Database successfully removed from database list"
574- echo "success=true" >> $env:GITHUB_OUTPUT
575- } else {
576- Write-Host "❌ Database still exists in list"
577- echo "success=false" >> $env:GITHUB_OUTPUT
578- }
579- } else {
580- Write-Host "❌ Database deletion failed"
581- Write-Host $output
582- echo "success=false" >> $env:GITHUB_OUTPUT
583- exit 1
584- }
585- } catch {
586- Write-Host "❌ Error deleting database: $_"
587- echo "success=false" >> $env:GITHUB_OUTPUT
588- exit 1
589- }
590-
591- - name : Phase 4 - Cleanup and Stop Server
592- if : always() && steps.start-server.outputs.success == 'true'
593- run : |
594- $ErrorActionPreference = "Continue"
595- $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
596- $dataDir = "${{ steps.init-database.outputs.data-dir }}"
597-
598- Write-Host "=== Phase 4: Cleanup and Stop Server ==="
599-
600- try {
601- $pgCtlExe = Join-Path $binPath "pg_ctl.exe"
602-
603- # Stop the server
604- Write-Host "Stopping PostgreSQL server..."
605- $output = & $pgCtlExe -D $dataDir stop -m fast 2>&1 | Out-String
606- Write-Host $output
607-
608- # Wait for server to stop
609- Start-Sleep -Seconds 3
610-
611- # Verify server stopped
612- $statusOutput = & $pgCtlExe -D $dataDir status 2>&1 | Out-String
613-
614- if ($statusOutput -match "no server running") {
615- Write-Host "✅ PostgreSQL server stopped successfully"
616- } else {
617- Write-Host "⚠️ Server may still be running"
618- }
619- } catch {
620- Write-Host "⚠️ Error during cleanup: $_"
621- }
622-
623363 - name : Generate Test Summary
624364 if : always()
625365 run : |
@@ -629,11 +369,7 @@ jobs:
629369
630370 $phase1_1 = "${{ steps.download-postgresql.outputs.success }}" -eq "true"
631371 $phase1_2 = "${{ steps.verify-postgresql.outputs.success }}" -eq "true"
632- $phase2_1 = "${{ steps.init-database.outputs.success }}" -eq "true"
633- $phase2_2 = "${{ steps.start-server.outputs.success }}" -eq "true"
634- $phase3_1 = "${{ steps.test-connection.outputs.success }}" -eq "true"
635- $phase3_2 = "${{ steps.test-create-db.outputs.success }}" -eq "true"
636- $phase3_3 = "${{ steps.test-delete-db.outputs.success }}" -eq "true"
372+ $phase2 = "${{ steps.test-basic.outputs.success }}" -eq "true"
637373
638374 # Get error messages if any
639375 $error1_1 = "${{ steps.download-postgresql.outputs.error }}"
@@ -648,28 +384,12 @@ jobs:
648384 $summary += "- Verify Executables: $(if ($phase1_2) { '✅ PASS' } else { '❌ FAIL' })`n`n"
649385
650386 if ($phase1_2) {
651- $summary += "**Phase 2: Server Initialization**`n"
652- $summary += "- Initialize Cluster: $(if ($phase2_1) { '✅ PASS' } else { '❌ FAIL' })`n"
653- if ($phase2_1) {
654- $summary += "- Start Server: $(if ($phase2_2) { '✅ PASS' } else { '❌ FAIL' })`n"
655- }
656- $summary += "`n"
657- }
658-
659- if ($phase2_2) {
660- $summary += "**Phase 3: Database Operations**`n"
661- $summary += "- Test Connection: $(if ($phase3_1) { '✅ PASS' } else { '❌ FAIL' })`n"
662- if ($phase3_1) {
663- $summary += "- Create Database: $(if ($phase3_2) { '✅ PASS' } else { '❌ FAIL' })`n"
664- if ($phase3_2) {
665- $summary += "- Delete Database: $(if ($phase3_3) { '✅ PASS' } else { '❌ FAIL' })`n"
666- }
667- }
668- $summary += "`n"
387+ $summary += "**Phase 2: Basic Functionality**`n"
388+ $summary += "- Test Executables: $(if ($phase2) { '✅ PASS' } else { '❌ FAIL' })`n`n"
669389 }
670390
671391 # Overall status
672- $allPassed = $phase1_1 -and $phase1_2 -and $phase2_1 -and $phase2_2 -and $phase3_1 -and $phase3_2 -and $phase3_3
392+ $allPassed = $phase1_1 -and $phase1_2 -and $phase2
673393
674394 if ($allPassed) {
675395 $summary += "**Overall Status:** ✅ ALL TESTS PASSED`n"
@@ -680,8 +400,8 @@ jobs:
680400 $summary += "<summary>💡 Click here for troubleshooting tips</summary>`n`n"
681401 $summary += "- Check the workflow logs for detailed error messages`n"
682402 $summary += "- Download the test artifacts for complete logs`n"
683- $summary += "- Review the server logs if server startup failed`n"
684403 $summary += "- Verify the .7z archive structure matches expected format`n"
404+ $summary += "- Ensure all required DLL dependencies are included`n"
685405 $summary += "</details>`n"
686406 }
687407
0 commit comments