From 57757612fe281af42368ba22dee370f8fcaca465 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Fri, 2 Aug 2024 11:43:46 +0400 Subject: [PATCH] fix: [TKC-2343] workflow execution url (#5716) * fix: show test workflow execution uri Signed-off-by: Vladislav Sukhin * fix: add uris to test workflow executions Signed-off-by: Vladislav Sukhin --------- Signed-off-by: Vladislav Sukhin --- .../commands/common/render/common.go | 26 ++++++++++++++++ .../commands/testworkflows/executions.go | 31 +++++++++++++------ .../commands/testworkflows/run.go | 4 +++ .../commands/testworkflows/watch.go | 4 +++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/cmd/kubectl-testkube/commands/common/render/common.go b/cmd/kubectl-testkube/commands/common/render/common.go index 485aece435a..0c88caf60f5 100644 --- a/cmd/kubectl-testkube/commands/common/render/common.go +++ b/cmd/kubectl-testkube/commands/common/render/common.go @@ -8,6 +8,7 @@ import ( "gopkg.in/yaml.v2" + "github.com/kubeshop/testkube/cmd/kubectl-testkube/config" "github.com/kubeshop/testkube/pkg/api/v1/client" "github.com/kubeshop/testkube/pkg/api/v1/testkube" "github.com/kubeshop/testkube/pkg/ui" @@ -182,3 +183,28 @@ func PrintTestSuiteExecutionURIs(execution *testkube.TestSuiteExecution, dashboa testSuiteName, execution.Id)) ui.NL() } + +func PrintTestWorkflowExecutionURIs(execution *testkube.TestWorkflowExecution) { + cfg, err := config.Load() + ui.ExitOnError("loading config file", err) + + if cfg.ContextType != config.ContextTypeCloud { + return + } + + if execution.Result == nil || !execution.Result.IsFinished() { + return + } + + ui.NL() + workflowName := "" + if execution.Workflow != nil { + workflowName = execution.Workflow.Name + } + + ui.ExecutionLink("Test Workflow URI:", fmt.Sprintf("%s/organization/%s/environment/%s/dashboard/test-workflows/%s", + cfg.CloudContext.UiUri, cfg.CloudContext.OrganizationId, cfg.CloudContext.EnvironmentId, workflowName)) + ui.ExecutionLink("Test Workflow Execution URI:", fmt.Sprintf("%s/organization/%s/environment/%s/dashboard/test-workflows/%s/execution/%s", + cfg.CloudContext.UiUri, cfg.CloudContext.OrganizationId, cfg.CloudContext.EnvironmentId, workflowName, execution.Id)) + ui.NL() +} diff --git a/cmd/kubectl-testkube/commands/testworkflows/executions.go b/cmd/kubectl-testkube/commands/testworkflows/executions.go index 0fc71ff32b0..b6cb99729bf 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/executions.go +++ b/cmd/kubectl-testkube/commands/testworkflows/executions.go @@ -29,6 +29,14 @@ func NewGetTestWorkflowExecutionsCmd() *cobra.Command { Long: `Gets TestWorkflow execution details by ID, or list if id is not passed`, Run: func(cmd *cobra.Command, args []string) { + outputFlag := cmd.Flag("output") + outputType := render.OutputPretty + if outputFlag != nil { + outputType = render.OutputType(outputFlag.Value.String()) + } + + outputPretty := outputType == render.OutputPretty + client, _, err := common.GetClient(cmd) ui.ExitOnError("getting client", err) @@ -51,19 +59,24 @@ func NewGetTestWorkflowExecutionsCmd() *cobra.Command { ui.ExitOnError("rendering obj", err) } - ui.Info("Getting logs for test workflow execution", executionID) + if outputPretty { + ui.Info("Getting logs for test workflow execution", executionID) - logs, err := client.GetTestWorkflowExecutionLogs(executionID) - ui.ExitOnError("getting logs from executor", err) + logs, err := client.GetTestWorkflowExecutionLogs(executionID) + ui.ExitOnError("getting logs from executor", err) - sigs := flattenSignatures(execution.Signature) + sigs := flattenSignatures(execution.Signature) - var results map[string]testkube.TestWorkflowStepResult - if execution.Result != nil { - results = execution.Result.Steps - } + var results map[string]testkube.TestWorkflowStepResult + if execution.Result != nil { + results = execution.Result.Steps + } - printRawLogLines(logs, sigs, results) + printRawLogLines(logs, sigs, results) + if !logsOnly { + render.PrintTestWorkflowExecutionURIs(&execution) + } + } }, } diff --git a/cmd/kubectl-testkube/commands/testworkflows/run.go b/cmd/kubectl-testkube/commands/testworkflows/run.go index 3bc06920646..b38a371ce31 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/run.go +++ b/cmd/kubectl-testkube/commands/testworkflows/run.go @@ -101,6 +101,10 @@ func NewRunTestWorkflowCmd() *cobra.Command { uiShellWatchExecution(execution.Id) } + execution, err = client.GetTestWorkflowExecution(execution.Id) + ui.ExitOnError("get execution failed", err) + + render.PrintTestWorkflowExecutionURIs(&execution) uiShellGetExecution(execution.Id) } diff --git a/cmd/kubectl-testkube/commands/testworkflows/watch.go b/cmd/kubectl-testkube/commands/testworkflows/watch.go index f4946dabe53..2387810b6ef 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/watch.go +++ b/cmd/kubectl-testkube/commands/testworkflows/watch.go @@ -34,6 +34,10 @@ func NewWatchTestWorkflowExecutionCmd() *cobra.Command { exitCode := uiWatch(execution, client) ui.NL() + execution, err = client.GetTestWorkflowExecution(execution.Id) + ui.ExitOnError("get execution failed", err) + + render.PrintTestWorkflowExecutionURIs(&execution) uiShellGetExecution(execution.Id) os.Exit(exitCode) },