Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cmd/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/elastic/elastic-package/internal/testrunner/runners/static"
"github.com/elastic/elastic-package/internal/testrunner/runners/system"
"github.com/elastic/elastic-package/internal/testrunner/script"
"github.com/elastic/elastic-package/internal/version"
)

const testLongDescription = `Use this command to run tests on a package. Currently, the following types of tests are available:
Expand Down Expand Up @@ -178,6 +179,13 @@ func testRunnerAssetCommandAction(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to read global config: %w", err)
}

stackVersion, err := kibanaClient.Version()
if err != nil {
return fmt.Errorf("fetching stack version failed: %w", err)
}

logger.Info(version.Version())
logger.Infof("elastic-stack: %s\n", stackVersion.Version())
runner := asset.NewAssetTestRunner(asset.AssetTestRunnerOptions{
PackageRootPath: packageRootPath,
KibanaClient: kibanaClient,
Expand Down Expand Up @@ -266,6 +274,7 @@ func testRunnerStaticCommandAction(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to read global config: %w", err)
}

logger.Info(version.Version())
runner := static.NewStaticTestRunner(static.StaticTestRunnerOptions{
PackageRootPath: packageRootPath,
DataStreams: dataStreams,
Expand Down Expand Up @@ -384,6 +393,13 @@ func testRunnerPipelineCommandAction(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to read global config: %w", err)
}

esClientInfo, err := esClient.Info(ctx)
if err != nil {
return fmt.Errorf("fetching stack version failed: %w", err)
}

logger.Info(version.Version())
logger.Infof("elastic-stack: %s\n", esClientInfo.Version.Number)
runner := pipeline.NewPipelineTestRunner(pipeline.PipelineTestRunnerOptions{
Profile: profile,
PackageRootPath: packageRootPath,
Expand Down Expand Up @@ -576,6 +592,13 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to read global config: %w", err)
}

info, err := esClient.Info(ctx)
if err != nil {
return fmt.Errorf("fetching stack version failed: %w", err)
}

logger.Info(version.Version())
logger.Infof("elastic-stack: %s", info.Version.Number)
runner := system.NewSystemTestRunner(system.SystemTestRunnerOptions{
Profile: profile,
PackageRootPath: packageRootPath,
Expand Down Expand Up @@ -742,6 +765,13 @@ func testRunnerPolicyCommandAction(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to read global config: %w", err)
}

stackVersion, err := kibanaClient.Version()
if err != nil {
return fmt.Errorf("fetching stack version failed: %w", err)
}

logger.Info(version.Version())
logger.Infof("elastic-stack: %s", stackVersion.Version())
runner := policy.NewPolicyTestRunner(policy.PolicyTestRunnerOptions{
PackageRootPath: packageRootPath,
KibanaClient: kibanaClient,
Expand Down
10 changes: 1 addition & 9 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"

Expand All @@ -29,13 +28,6 @@ func setupVersionCommand() *cobraext.Command {
}

func versionCommandAction(cmd *cobra.Command, args []string) error {
var sb strings.Builder
sb.WriteString("elastic-package ")
if version.Tag != "" {
sb.WriteString(version.Tag)
sb.WriteString(" ")
}
sb.WriteString(fmt.Sprintf("version-hash %s (build time: %s)", version.CommitHash, version.BuildTimeFormatted()))
fmt.Println(sb.String())
fmt.Println(version.Version())
return nil
}
17 changes: 15 additions & 2 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package version

import (
"fmt"
"runtime/debug"
"strconv"
"strings"
"time"
)

Expand All @@ -32,8 +34,8 @@ func init() {
}
}

// BuildTimeFormatted method returns the build time preserving the RFC3339 format.
func BuildTimeFormatted() string {
// buildTimeFormatted method returns the build time preserving the RFC3339 format.
func buildTimeFormatted() string {
if BuildTime == "unknown" {
return BuildTime
}
Expand All @@ -44,3 +46,14 @@ func BuildTimeFormatted() string {
}
return time.Unix(seconds, 0).Format(time.RFC3339)
}

func Version() string {
var sb strings.Builder
sb.WriteString("elastic-package ")
if Tag != "" {
sb.WriteString(Tag)
sb.WriteString(" ")
}
sb.WriteString(fmt.Sprintf("version-hash %s (build time: %s)", CommitHash, buildTimeFormatted()))
return sb.String()
}