Skip to content

Commit

Permalink
Fix invalid tagname and move index path validation (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: Reinhard Nägele <unguiculus@gmail.com>
  • Loading branch information
unguiculus authored May 23, 2019
1 parent 452a96e commit 5132b26
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ chart-releaser
.idea
/dist
/vendor
.vscode
13 changes: 0 additions & 13 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package config
import (
"fmt"
"github.com/mitchellh/go-homedir"
"os"
"path"
"reflect"
"strings"
Expand Down Expand Up @@ -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
}
19 changes: 16 additions & 3 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ package releaser
import (
"context"
"fmt"
"github.com/helm/chart-releaser/pkg/config"
"github.com/pkg/errors"
"io/ioutil"
"net/url"
"os"
"path"
"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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions pkg/releaser/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
})
Expand Down

0 comments on commit 5132b26

Please sign in to comment.