From 879fa2a779ade414df35720d67d71a102b4d5b06 Mon Sep 17 00:00:00 2001 From: Harish R S Date: Sat, 9 May 2026 02:49:19 +0530 Subject: [PATCH] feat(test): add --output-format flag for GitHub Actions annotations Add --output-format flag to the test command with two values: - plain (default): existing behavior unchanged - github-actions: emits workflow commands for inline PR annotations ::notice title=Test Passed:: tests PASSED for endpoint ::error title=Test Failed:: tests FAILED for endpoint Fixes #332 Signed-off-by: Harish R S --- cmd/test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/test.go b/cmd/test.go index 70ecb4f..39bfdd6 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -29,7 +29,8 @@ import ( ) var ( - runnerChoices = map[string]bool{"HTTP": true, "SOAP_HTTP": true, "SOAP_UI": true, "POSTMAN": true, "OPEN_API_SCHEMA": true, "ASYNC_API_SCHEMA": true, "GRPC_PROTOBUF": true, "GRAPHQL_SCHEMA": true} + runnerChoices = map[string]bool{"HTTP": true, "SOAP_HTTP": true, "SOAP_UI": true, "POSTMAN": true, "OPEN_API_SCHEMA": true, "ASYNC_API_SCHEMA": true, "GRPC_PROTOBUF": true, "GRAPHQL_SCHEMA": true} + outputFormatChoices = map[string]bool{"plain": true, "github-actions": true} ) func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { @@ -39,6 +40,7 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { filteredOperations string operationsHeaders string oAuth2Context string + outputFormat string ) var testCmd = &cobra.Command{ @@ -73,6 +75,10 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { fmt.Println(" should be one of: HTTP, SOAP, SOAP_UI, POSTMAN, OPEN_API_SCHEMA, ASYNC_API_SCHEMA, GRPC_PROTOBUF, GRAPHQL_SCHEMA") os.Exit(1) } + if _, validChoice := outputFormatChoices[outputFormat]; !validChoice { + fmt.Println("--output-format should be one of: plain, github-actions") + os.Exit(1) + } // Validate presence and values of flags. if !strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min") { @@ -205,6 +211,14 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { fmt.Printf("Full TestResult details are available here: %s/#/tests/%s \n", serverAddr, testResultID) + if outputFormat == "github-actions" { + if success { + fmt.Printf("::notice title=Test Passed::%s tests PASSED for endpoint %s\n", serviceRef, testEndpoint) + } else { + fmt.Printf("::error title=Test Failed::%s tests FAILED for endpoint %s\n", serviceRef, testEndpoint) + } + } + if !success { os.Exit(1) } @@ -216,6 +230,7 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { testCmd.Flags().StringVar(&filteredOperations, "filteredOperations", "", "List of operations to launch a test for") testCmd.Flags().StringVar(&operationsHeaders, "operationsHeaders", "", "Override of operations headers as JSON string") testCmd.Flags().StringVar(&oAuth2Context, "oAuth2Context", "", "Spec of an OAuth2 client context as JSON string") + testCmd.Flags().StringVar(&outputFormat, "output-format", "plain", "Output format for test results: plain, github-actions") return testCmd }