Skip to content

Commit 83e649d

Browse files
authored
Fix rendering of external groups in READMEs (#3088)
Swap source and build package roots when updating READMEs, so the generator looks for fields in the source directory. In the build directory the external fields have been already resolved and they don't include the external key. For legacy reasons, elastic-package only renders groups in READMEs when they are external, so these fields were not being rendered. Naming of related variables is reviewed for consistency, so it is harder to misuse them. Fix also related tests, and introduce new ones that reproduce the issue.
1 parent 3b66308 commit 83e649d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+686
-628
lines changed

cmd/benchmark.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func pipelineCommandAction(cmd *cobra.Command, args []string) error {
142142
return fmt.Errorf("locating repository root failed: %w", err)
143143
}
144144

145-
packageRootPath, err := packages.FindPackageRoot()
145+
packageRoot, err := packages.FindPackageRoot()
146146
if err != nil {
147147
return fmt.Errorf("locating package root failed: %w", err)
148148
}
@@ -155,21 +155,21 @@ func pipelineCommandAction(cmd *cobra.Command, args []string) error {
155155
if len(dataStreams) > 0 {
156156
common.TrimStringSlice(dataStreams)
157157

158-
if err := validateDataStreamsFlag(packageRootPath, dataStreams); err != nil {
158+
if err := validateDataStreamsFlag(packageRoot, dataStreams); err != nil {
159159
return cobraext.FlagParsingError(err, cobraext.DataStreamsFlagName)
160160
}
161161
}
162162

163163
ctx, stop := signal.Enable(cmd.Context(), logger.Info)
164164
defer stop()
165165

166-
benchFolders, err := pipeline.FindBenchmarkFolders(packageRootPath, dataStreams)
166+
benchFolders, err := pipeline.FindBenchmarkFolders(packageRoot, dataStreams)
167167
if err != nil {
168168
return fmt.Errorf("unable to determine benchmark folder paths: %w", err)
169169
}
170170

171171
if useTestSamples {
172-
testFolders, err := testrunner.FindTestFolders(packageRootPath, dataStreams, testrunner.TestType(pipeline.BenchType))
172+
testFolders, err := testrunner.FindTestFolders(packageRoot, dataStreams, testrunner.TestType(pipeline.BenchType))
173173
if err != nil {
174174
return fmt.Errorf("unable to determine test folder paths: %w", err)
175175
}
@@ -202,7 +202,7 @@ func pipelineCommandAction(cmd *cobra.Command, args []string) error {
202202
opts := pipeline.NewOptions(
203203
pipeline.WithBenchmarkName(fmt.Sprintf("%s-%d", folder.Package, idx+1)),
204204
pipeline.WithFolder(folder),
205-
pipeline.WithPackageRootPath(packageRootPath),
205+
pipeline.WithPackageRoot(packageRoot),
206206
pipeline.WithESAPI(esClient.API),
207207
pipeline.WithNumTopProcs(numTopProcs),
208208
pipeline.WithFormat(reportFormat),
@@ -294,9 +294,9 @@ func rallyCommandAction(cmd *cobra.Command, args []string) error {
294294
return fmt.Errorf("getting package name and version failed, expected format: <package>-<version>: %w", err)
295295
}
296296

297-
var packageRootPath string
297+
var packageRoot string
298298
if len(packageName) == 0 {
299-
packageRootPath, err = packages.FindPackageRoot()
299+
packageRoot, err = packages.FindPackageRoot()
300300
if err != nil {
301301
return fmt.Errorf("locating package root failed: %w", err)
302302
}
@@ -333,7 +333,7 @@ func rallyCommandAction(cmd *cobra.Command, args []string) error {
333333
rally.WithVariant(variant),
334334
rally.WithBenchmarkName(benchName),
335335
rally.WithDataReindexing(dataReindex),
336-
rally.WithPackageRootPath(packageRootPath),
336+
rally.WithPackageRoot(packageRoot),
337337
rally.WithESAPI(esClient.API),
338338
rally.WithKibanaClient(kc),
339339
rally.WithProfile(profile),
@@ -471,7 +471,7 @@ func streamCommandAction(cmd *cobra.Command, args []string) error {
471471
return cobraext.FlagParsingError(err, cobraext.BenchStreamTimestampFieldFlagName)
472472
}
473473

474-
packageRootPath, err := packages.FindPackageRoot()
474+
packageRoot, err := packages.FindPackageRoot()
475475
if err != nil {
476476
return fmt.Errorf("locating package root failed: %w", err)
477477
}
@@ -511,7 +511,7 @@ func streamCommandAction(cmd *cobra.Command, args []string) error {
511511
stream.WithPeriodDuration(periodDuration),
512512
stream.WithPerformCleanup(performCleanup),
513513
stream.WithTimestampField(timestampField),
514-
stream.WithPackageRootPath(packageRootPath),
514+
stream.WithPackageRoot(packageRoot),
515515
stream.WithESAPI(esClient.API),
516516
stream.WithKibanaClient(kc),
517517
stream.WithProfile(profile),
@@ -581,7 +581,7 @@ func systemCommandAction(cmd *cobra.Command, args []string) error {
581581
return cobraext.FlagParsingError(err, cobraext.BenchReindexToMetricstoreFlagName)
582582
}
583583

584-
packageRootPath, err := packages.FindPackageRoot()
584+
packageRoot, err := packages.FindPackageRoot()
585585
if err != nil {
586586
return fmt.Errorf("locating package root failed: %w", err)
587587
}
@@ -615,7 +615,7 @@ func systemCommandAction(cmd *cobra.Command, args []string) error {
615615
system.WithDeferCleanup(deferCleanup),
616616
system.WithMetricsInterval(metricsInterval),
617617
system.WithDataReindexing(dataReindex),
618-
system.WithPackageRootPath(packageRootPath),
618+
system.WithPackageRoot(packageRoot),
619619
system.WithESAPI(esClient.API),
620620
system.WithKibanaClient(kc),
621621
system.WithProfile(profile),

cmd/build.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ func buildCommandAction(cmd *cobra.Command, args []string) error {
7979
logger.Debugf("Use build directory: %s", buildDir)
8080

8181
target, err := builder.BuildPackage(builder.BuildOptions{
82-
PackageRootPath: packageRoot,
83-
BuildDir: buildDir,
84-
CreateZip: createZip,
85-
SignPackage: signPackage,
86-
SkipValidation: skipValidation,
87-
RepositoryRoot: repositoryRoot,
88-
UpdateReadmes: true,
82+
PackageRoot: packageRoot,
83+
BuildDir: buildDir,
84+
CreateZip: createZip,
85+
SignPackage: signPackage,
86+
SkipValidation: skipValidation,
87+
RepositoryRoot: repositoryRoot,
88+
UpdateReadmes: true,
8989
})
9090
if err != nil {
9191
return fmt.Errorf("building package failed: %w", err)

cmd/install.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func installCommandAction(cmd *cobra.Command, _ []string) error {
4545
if err != nil {
4646
return cobraext.FlagParsingError(err, cobraext.ZipPackageFilePathFlagName)
4747
}
48-
packageRootPath, err := cmd.Flags().GetString(cobraext.PackageRootFlagName)
48+
packageRoot, err := cmd.Flags().GetString(cobraext.PackageRootFlagName)
4949
if err != nil {
5050
return cobraext.FlagParsingError(err, cobraext.PackageRootFlagName)
5151
}
@@ -73,9 +73,9 @@ func installCommandAction(cmd *cobra.Command, _ []string) error {
7373
return fmt.Errorf("could not create kibana client: %w", err)
7474
}
7575

76-
if zipPathFile == "" && packageRootPath == "" {
76+
if zipPathFile == "" && packageRoot == "" {
7777
var err error
78-
packageRootPath, err = packages.FindPackageRoot()
78+
packageRoot, err = packages.FindPackageRoot()
7979
if err != nil {
8080
return fmt.Errorf("locating package root failed: %w", err)
8181
}
@@ -87,11 +87,11 @@ func installCommandAction(cmd *cobra.Command, _ []string) error {
8787
}
8888

8989
installer, err := installer.NewForPackage(installer.Options{
90-
Kibana: kibanaClient,
91-
PackageRootPath: packageRootPath,
92-
SkipValidation: skipValidation,
93-
ZipPath: zipPathFile,
94-
RepositoryRoot: repositoryRoot,
90+
Kibana: kibanaClient,
91+
PackageRoot: packageRoot,
92+
SkipValidation: skipValidation,
93+
ZipPath: zipPathFile,
94+
RepositoryRoot: repositoryRoot,
9595
})
9696
if err != nil {
9797
return fmt.Errorf("package installation failed: %w", err)

cmd/lint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ func lintCommandAction(cmd *cobra.Command, args []string) error {
7373
}
7474

7575
func validateSourceCommandAction(cmd *cobra.Command, args []string) error {
76-
packageRootPath, err := packages.FindPackageRoot()
76+
packageRoot, err := packages.FindPackageRoot()
7777
if err != nil {
7878
return fmt.Errorf("locating package root failed: %w", err)
7979
}
80-
errs, skipped := validation.ValidateAndFilterFromPath(packageRootPath)
80+
errs, skipped := validation.ValidateAndFilterFromPath(packageRoot)
8181
if skipped != nil {
8282
logger.Infof("Skipped errors: %v", skipped)
8383
}

cmd/service.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ func upCommandAction(cmd *cobra.Command, args []string) error {
5151
return fmt.Errorf("locating package root failed: %w", err)
5252
}
5353

54-
var dataStreamPath string
54+
var dataStreamRoot string
5555
dataStreamFlag, _ := cmd.Flags().GetString(cobraext.DataStreamFlagName)
5656
if dataStreamFlag != "" {
57-
dataStreamPath = filepath.Join(packageRoot, "data_stream", dataStreamFlag)
57+
dataStreamRoot = filepath.Join(packageRoot, "data_stream", dataStreamFlag)
5858
}
5959

6060
variantFlag, _ := cmd.Flags().GetString(cobraext.VariantFlagName)
@@ -75,13 +75,13 @@ func upCommandAction(cmd *cobra.Command, args []string) error {
7575

7676
_, serviceName := filepath.Split(packageRoot)
7777
err = service.BootUp(cmd.Context(), service.Options{
78-
Profile: profile,
79-
ServiceName: serviceName,
80-
PackageRootPath: packageRoot,
81-
DevDeployDir: system.DevDeployDir,
82-
DataStreamRootPath: dataStreamPath,
83-
Variant: variantFlag,
84-
StackVersion: stackVersion.Version(),
78+
Profile: profile,
79+
ServiceName: serviceName,
80+
PackageRoot: packageRoot,
81+
DevDeployDir: system.DevDeployDir,
82+
DataStreamRoot: dataStreamRoot,
83+
Variant: variantFlag,
84+
StackVersion: stackVersion.Version(),
8585
})
8686
if err != nil {
8787
return fmt.Errorf("up command failed: %w", err)

cmd/status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ func getPackageStatus(packageName string, options registry.SearchOptions) (*stat
163163
if packageName != "" {
164164
return status.RemotePackage(packageName, options)
165165
}
166-
packageRootPath, err := packages.FindPackageRoot()
166+
packageRoot, err := packages.FindPackageRoot()
167167
if err != nil {
168168
if errors.Is(err, packages.ErrPackageRootNotFound) {
169169
return nil, errors.New("no package specified and package root not found")
170170
}
171171
return nil, fmt.Errorf("locating package root failed: %w", err)
172172
}
173-
return status.LocalPackage(packageRootPath, options)
173+
return status.LocalPackage(packageRoot, options)
174174
}
175175

176176
func getServerlessManifests(packageName string, options registry.SearchOptions) ([]status.ServerlessManifests, error) {

0 commit comments

Comments
 (0)