|
1 | 1 | package helm |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "fmt" |
| 6 | + "os" |
| 7 | + "path/filepath" |
| 8 | + |
5 | 9 | "github.com/jfrog/build-info-go/entities" |
| 10 | + "github.com/jfrog/build-info-go/flexpack" |
6 | 11 | "github.com/jfrog/jfrog-client-go/artifactory" |
7 | | - "path/filepath" |
8 | 12 | ) |
9 | 13 |
|
| 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 | + |
10 | 20 | func handlePackageCommand(buildInfoOld *entities.BuildInfo, args []string, serviceManager artifactory.ArtifactoryServicesManager, buildName, buildNumber, project string) error { |
11 | 21 | 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. |
12 | 25 | for _, path := range packagePaths { |
13 | 26 | absolutePath, err := filepath.Abs(path) |
14 | 27 | if err != nil { |
15 | 28 | return fmt.Errorf("failed to get absolute path: %w", err) |
16 | 29 | } |
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 |
32 | 33 | } |
33 | 34 | } |
| 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 | + } |
34 | 54 | return nil |
35 | 55 | } |
0 commit comments