diff --git a/.gitignore b/.gitignore index f26d1d1d..d12c272d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ chart-releaser .idea /dist /vendor +.vscode diff --git a/pkg/config/config.go b/pkg/config/config.go index a6b8320e..27cfda6d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,7 +17,6 @@ package config import ( "fmt" "github.com/mitchellh/go-homedir" - "os" "path" "reflect" "strings" @@ -94,17 +93,5 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, requiredFlags []strin } } - // if path doesn't end with index.yaml we can try and fix it - if path.Base(opts.IndexPath) != "index.yaml" { - // if path is a directory then add index.yaml - if stat, err := os.Stat(opts.IndexPath); err == nil && stat.IsDir() { - opts.IndexPath = path.Join(opts.IndexPath, "index.yaml") - // otherwise error out - } else { - fmt.Printf("path (%s) should be a directory or a file called index.yaml\n", opts.IndexPath) - os.Exit(1) - } - } - return opts, nil } diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index e2b60fac..1dd10a91 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -17,8 +17,6 @@ package releaser import ( "context" "fmt" - "github.com/helm/chart-releaser/pkg/config" - "github.com/pkg/errors" "io/ioutil" "net/url" "os" @@ -26,6 +24,9 @@ import ( "path/filepath" "strings" + "github.com/helm/chart-releaser/pkg/config" + "github.com/pkg/errors" + "github.com/helm/chart-releaser/pkg/github" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/provenance" @@ -53,6 +54,18 @@ func NewReleaser(config *config.Options, github GitHub) *Releaser { //UpdateIndexFile index.yaml file for a give git repo func (r *Releaser) UpdateIndexFile() (bool, error) { + // if path doesn't end with index.yaml we can try and fix it + if path.Base(r.config.IndexPath) != "index.yaml" { + // if path is a directory then add index.yaml + if stat, err := os.Stat(r.config.IndexPath); err == nil && stat.IsDir() { + r.config.IndexPath = path.Join(r.config.IndexPath, "index.yaml") + // otherwise error out + } else { + fmt.Printf("path (%s) should be a directory or a file called index.yaml\n", r.config.IndexPath) + os.Exit(1) + } + } + var indexFile = &repo.IndexFile{} if _, err := os.Stat(r.config.IndexPath); err == nil { @@ -152,7 +165,7 @@ func (r *Releaser) CreateReleases() error { } for _, p := range packages { - baseName := strings.TrimSuffix(p, filepath.Ext(p)) + baseName := filepath.Base(strings.TrimSuffix(p, filepath.Ext(p))) chart, err := chartutil.Load(p) if err != nil { return err diff --git a/pkg/releaser/releaser_test.go b/pkg/releaser/releaser_test.go index 8fe85cca..c54cee2d 100644 --- a/pkg/releaser/releaser_test.go +++ b/pkg/releaser/releaser_test.go @@ -17,15 +17,16 @@ package releaser import ( "context" "fmt" + "io/ioutil" + "os" + "path/filepath" + "testing" + "github.com/helm/chart-releaser/pkg/github" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "io/ioutil" "k8s.io/helm/pkg/provenance" "k8s.io/helm/pkg/repo" - "os" - "path/filepath" - "testing" "github.com/helm/chart-releaser/pkg/config" ) @@ -217,12 +218,13 @@ func TestReleaser_CreateReleases(t *testing.T) { fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 0) } else { assert.NoError(t, err) - releaseName := fmt.Sprintf("%s/%s-%s", r.config.PackagePath, tt.chart, tt.version) + releaseName := fmt.Sprintf("%s-%s", tt.chart, tt.version) + assetPath := fmt.Sprintf("%s/%s-%s.tgz", r.config.PackagePath, tt.chart, tt.version) releaseDescription := "A Helm chart for Kubernetes" assert.Equal(t, releaseName, fakeGitHub.release.Name) assert.Equal(t, releaseDescription, fakeGitHub.release.Description) assert.Len(t, fakeGitHub.release.Assets, 1) - assert.Equal(t, fmt.Sprintf("%s.tgz", releaseName), fakeGitHub.release.Assets[0].Path) + assert.Equal(t, assetPath, fakeGitHub.release.Assets[0].Path) fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 1) } })