Skip to content

Commit 32e5b3f

Browse files
committed
fix: build-info gathering fails when helm chart path is different than helm chart archive
When `helm package /path/to/chart --destination /tmp/target` is executed, we need to filter out directories which doesn't contain Chart.yaml.
1 parent 4eac15c commit 32e5b3f

1 file changed

Lines changed: 36 additions & 16 deletions

File tree

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
11
package helm
22

33
import (
4+
"errors"
45
"fmt"
6+
"os"
7+
"path/filepath"
8+
59
"github.com/jfrog/build-info-go/entities"
10+
"github.com/jfrog/build-info-go/flexpack"
611
"github.com/jfrog/jfrog-client-go/artifactory"
7-
"path/filepath"
812
)
913

14+
func isChartDir(dir string) bool {
15+
chartPath := filepath.Join(dir, flexpack.ChartYaml)
16+
_, err := os.Stat(chartPath)
17+
return !errors.Is(err, os.ErrNotExist)
18+
}
19+
1020
func handlePackageCommand(buildInfoOld *entities.BuildInfo, args []string, serviceManager artifactory.ArtifactoryServicesManager, buildName, buildNumber, project string) error {
1121
packagePaths := getPaths(args)
22+
var chartPath string
23+
// helm package command has only 1 chart path directory.
24+
// we need to ignore other paths such as archive destination or signing keyring.
1225
for _, path := range packagePaths {
1326
absolutePath, err := filepath.Abs(path)
1427
if err != nil {
1528
return fmt.Errorf("failed to get absolute path: %w", err)
1629
}
17-
buildInfo, err := collectBuildInfoWithFlexPack(absolutePath, buildName, buildNumber)
18-
if err != nil {
19-
return fmt.Errorf("failed to collect build info: %w", err)
20-
}
21-
if buildInfo == nil {
22-
return fmt.Errorf("no build info collected, skipping further processing")
23-
}
24-
updateDependencyOCILayersInBuildInfo(buildInfo, serviceManager)
25-
if len(buildInfo.Modules) > 0 {
26-
appendModuleInExistingBuildInfo(buildInfoOld, &buildInfo.Modules[0])
27-
}
28-
removeDuplicateDependencies(buildInfoOld)
29-
err = saveBuildInfo(buildInfoOld, buildName, buildNumber, project)
30-
if err != nil {
31-
return fmt.Errorf("failed to save build info")
30+
if isChartDir(absolutePath) {
31+
chartPath = absolutePath
32+
break
3233
}
3334
}
35+
if chartPath == "" {
36+
return fmt.Errorf("no valid Helm chart directory found in the provided paths")
37+
}
38+
buildInfo, err := collectBuildInfoWithFlexPack(chartPath, buildName, buildNumber)
39+
if err != nil {
40+
return fmt.Errorf("failed to collect build info: %w", err)
41+
}
42+
if buildInfo == nil {
43+
return fmt.Errorf("no build info collected, skipping further processing")
44+
}
45+
updateDependencyOCILayersInBuildInfo(buildInfo, serviceManager)
46+
if len(buildInfo.Modules) > 0 {
47+
appendModuleInExistingBuildInfo(buildInfoOld, &buildInfo.Modules[0])
48+
}
49+
removeDuplicateDependencies(buildInfoOld)
50+
err = saveBuildInfo(buildInfoOld, buildName, buildNumber, project)
51+
if err != nil {
52+
return fmt.Errorf("failed to save build info")
53+
}
3454
return nil
3555
}

0 commit comments

Comments
 (0)