diff --git a/pkg/helm/export.go b/pkg/helm/export.go index 2c40d30f..921e85e8 100644 --- a/pkg/helm/export.go +++ b/pkg/helm/export.go @@ -5,6 +5,7 @@ import ( "math" "os" "path/filepath" + "strings" "github.com/blang/semver" "github.com/go-git/go-billy/v5" @@ -30,6 +31,10 @@ var ( // helmChartPath is a relative path (rooted at the package level) that contains the chart. func ExportHelmChart(rootFs, fs billy.Filesystem, helmChartPath string, packageVersion *int, version *semver.Version, autoGenBumpVersion *semver.Version, upstreamChartVersion string, omitBuildMetadata bool) error { + if err := removeOrigFiles(filesystem.GetAbsPath(fs, helmChartPath)); err != nil { + return fmt.Errorf("failed to remove .orig files: %s", err) + } + chart, err := loadHelmChart(fs, helmChartPath) if err != nil { return err @@ -65,6 +70,23 @@ func ExportHelmChart(rootFs, fs billy.Filesystem, helmChartPath string, packageV return nil } +// removeOrigFiles removes all files ending with .orig in the specified directory +func removeOrigFiles(dir string) error { + err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() && strings.HasSuffix(info.Name(), ".orig") { + if err := os.Remove(path); err != nil { + return err + } + logrus.Infof("Removed file: %s", path) + } + return nil + }) + return err +} + func loadHelmChart(fs billy.Filesystem, helmChartPath string) (*chart.Chart, error) { // Try to load the chart to see if it can be exported absHelmChartPath := filesystem.GetAbsPath(fs, helmChartPath)