@@ -14,6 +14,8 @@ public static class Program
1414 private static int passedTests ;
1515 private static int failedTests ;
1616 private static int skippedTests ;
17+ private static readonly List < ( string Category , string Name , bool Passed , string ? Error ) > testResults = new ( ) ;
18+ private static string currentCategory = "" ;
1719
1820 public static async Task < int > Main ( )
1921 {
@@ -58,11 +60,15 @@ public static async Task<int> Main()
5860 AnsiConsole . WriteLine ( ) ;
5961 DisplaySummary ( ) ;
6062
63+ // Generate GitHub summary if running in CI
64+ GenerateGitHubSummary ( ) ;
65+
6166 return failedTests > 0 ? 1 : 0 ;
6267 }
6368
6469 private static async Task RunTestCategory ( string categoryName , Func < Task > testFunc )
6570 {
71+ currentCategory = categoryName ;
6672 AnsiConsole . Write ( new Rule ( $ "[bold blue]{ categoryName } [/]") . RuleStyle ( "blue dim" ) ) ;
6773 AnsiConsole . WriteLine ( ) ;
6874
@@ -686,18 +692,21 @@ private static async Task RunTest(string testName, Func<Task<bool>> testFunc)
686692 {
687693 AnsiConsole . MarkupLine ( $ "[green] ✓[/] { testName } ") ;
688694 passedTests ++ ;
695+ testResults . Add ( ( currentCategory , testName , true , null ) ) ;
689696 }
690697 else
691698 {
692699 AnsiConsole . MarkupLine ( $ "[red] ✗[/] { testName } ") ;
693700 failedTests ++ ;
701+ testResults . Add ( ( currentCategory , testName , false , "Test returned false" ) ) ;
694702 }
695703 }
696704 catch ( Exception ex )
697705 {
698706 AnsiConsole . MarkupLine ( $ "[red] ✗[/] { testName } : { Markup . Escape ( ex . Message ) } ") ;
699707 AnsiConsole . WriteException ( ex , ExceptionFormats . ShortenPaths | ExceptionFormats . ShortenTypes ) ;
700708 failedTests ++ ;
709+ testResults . Add ( ( currentCategory , testName , false , ex . Message ) ) ;
701710 }
702711 }
703712
@@ -729,5 +738,75 @@ private static void DisplaySummary()
729738 }
730739 }
731740
741+ private static void GenerateGitHubSummary ( )
742+ {
743+ var summaryFile = Environment . GetEnvironmentVariable ( "GITHUB_STEP_SUMMARY" ) ;
744+
745+ if ( string . IsNullOrEmpty ( summaryFile ) )
746+ return ;
747+
748+ try
749+ {
750+ var markdown = new StringBuilder ( ) ;
751+
752+ // Title
753+ markdown . AppendLine ( "# LibSSH2 Test Results" ) ;
754+ markdown . AppendLine ( ) ;
755+
756+ // Summary table
757+ markdown . AppendLine ( "## Summary" ) ;
758+ markdown . AppendLine ( ) ;
759+ markdown . AppendLine ( "| Result | Count |" ) ;
760+ markdown . AppendLine ( "|--------|-------|" ) ;
761+ markdown . AppendLine ( $ "| ✅ Passed | { passedTests } |") ;
762+ if ( failedTests > 0 )
763+ markdown . AppendLine ( $ "| ❌ Failed | { failedTests } |") ;
764+ if ( skippedTests > 0 )
765+ markdown . AppendLine ( $ "| ⏭️ Skipped | { skippedTests } |") ;
766+ markdown . AppendLine ( $ "| **Total** | **{ passedTests + failedTests + skippedTests } ** |") ;
767+ markdown . AppendLine ( ) ;
768+
769+ // Overall status
770+ if ( failedTests == 0 && passedTests > 0 )
771+ {
772+ markdown . AppendLine ( "> ✅ **All tests passed!** 🎉" ) ;
773+ }
774+ else if ( failedTests > 0 )
775+ {
776+ markdown . AppendLine ( $ "> ❌ **{ failedTests } test(s) failed.**") ;
777+ }
778+ markdown . AppendLine ( ) ;
779+
780+ // Detailed results by category
781+ markdown . AppendLine ( "## Detailed Results" ) ;
782+ markdown . AppendLine ( ) ;
783+
784+ var groupedResults = testResults . GroupBy ( t => t . Category ) ;
785+ foreach ( var group in groupedResults )
786+ {
787+ markdown . AppendLine ( $ "### { group . Key } ") ;
788+ markdown . AppendLine ( ) ;
789+
790+ foreach ( var test in group )
791+ {
792+ var icon = test . Passed ? "✅" : "❌" ;
793+ markdown . AppendLine ( $ "- { icon } { test . Name } ") ;
794+ if ( ! test . Passed && ! string . IsNullOrEmpty ( test . Error ) )
795+ {
796+ markdown . AppendLine ( $ " - Error: `{ test . Error } `") ;
797+ }
798+ }
799+ markdown . AppendLine ( ) ;
800+ }
801+
802+ File . WriteAllText ( summaryFile , markdown . ToString ( ) ) ;
803+ AnsiConsole . MarkupLine ( $ "[dim]GitHub summary written to { summaryFile } [/]") ;
804+ }
805+ catch ( Exception ex )
806+ {
807+ AnsiConsole . MarkupLine ( $ "[yellow]Failed to write GitHub summary: { Markup . Escape ( ex . Message ) } [/]") ;
808+ }
809+ }
810+
732811 #endregion
733812}
0 commit comments