diff --git a/pkg/git/git.go b/pkg/git/git.go index f5260b26..f743ace2 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -83,8 +83,16 @@ func (g *Git) GetPushURL(remote string, token string) (string, error) { return "", err } - pushURLArray := strings.SplitAfter(strings.TrimSpace(string(pushURL)), "https://") - pushURLWithToken := fmt.Sprintf("https://x-access-token:%s@%s", token, pushURLArray[1]) + pushURLStr := string(pushURL) + found := false + + if pushURLStr, found = strings.CutPrefix(pushURLStr, "git@"); found { + pushURLStr = strings.ReplaceAll(pushURLStr, ":", "/") + pushURLStr = strings.TrimSuffix(pushURLStr, ".git\n") + } else { + pushURLStr = strings.TrimPrefix(pushURLStr, "https://") + } + pushURLWithToken := fmt.Sprintf("https://x-access-token:%s@%s", token, strings.Trim(pushURLStr, "\n")) return pushURLWithToken, nil } diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 7974647e..4895ea71 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -185,7 +185,7 @@ func (r *Releaser) UpdateIndexFile() (bool, error) { packageName, packageVersion := tagParts[0], tagParts[1] fmt.Printf("Found %s-%s.tgz\n", packageName, packageVersion) if _, err := indexFile.Get(packageName, packageVersion); err != nil { - if err := r.addToIndexFile(indexFile, downloadURL.String()); err != nil { + if err := r.addToIndexFile(indexFile, downloadURL.String(), name); err != nil { return false, err } update = true @@ -267,8 +267,8 @@ func (r *Releaser) splitPackageNameAndVersion(pkg string) []string { return []string{pkg[0:delimIndex], pkg[delimIndex+1:]} } -func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error { - arch := filepath.Join(r.config.PackagePath, filepath.Base(url)) +func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, downloadUrl, fileName string) error { + arch := filepath.Join(r.config.PackagePath, filepath.Base(fileName)) // extract chart metadata fmt.Printf("Extracting chart metadata from %s\n", arch) @@ -286,7 +286,7 @@ func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error { // remove url name from url as helm's index library // adds it in during .Add // there should be a better way to handle this :( - s := strings.Split(url, "/") + s := strings.Split(downloadUrl, "/") s = s[:len(s)-1] if r.config.PackagesWithIndex { diff --git a/pkg/releaser/releaser_test.go b/pkg/releaser/releaser_test.go index 55c7841f..2843107f 100644 --- a/pkg/releaser/releaser_test.go +++ b/pkg/releaser/releaser_test.go @@ -288,6 +288,7 @@ func TestReleaser_addToIndexFile(t *testing.T) { name string chart string version string + filename string releaser *Releaser packagesWithIndex bool error bool @@ -296,6 +297,7 @@ func TestReleaser_addToIndexFile(t *testing.T) { "invalid-package", "does-not-exist", "0.1.0", + "missing-test-chart-0.1.0.tgz", &Releaser{ config: &config.Options{ PackagePath: "testdata/release-packages", @@ -309,6 +311,21 @@ func TestReleaser_addToIndexFile(t *testing.T) { "valid-package", "test-chart", "0.1.0", + "test-chart-0.1.0.tgz", + &Releaser{ + config: &config.Options{ + PackagePath: "testdata/release-packages", + PackagesWithIndex: false, + }, + }, + false, + false, + }, + { + "valid-package-extra-sem-ver", + "test-chart", + "0.1.0+Chart1", + "test-chart-0.1.0+Chart1.tgz", &Releaser{ config: &config.Options{ PackagePath: "testdata/release-packages", @@ -322,6 +339,7 @@ func TestReleaser_addToIndexFile(t *testing.T) { "valid-package-with-index", "test-chart", "0.1.0", + "test-chart-0.1.0.tgz", &Releaser{ config: &config.Options{ PackagePath: "testdata/release-packages", @@ -336,7 +354,7 @@ func TestReleaser_addToIndexFile(t *testing.T) { t.Run(tt.name, func(t *testing.T) { indexFile := repo.NewIndexFile() url := fmt.Sprintf("https://myrepo/charts/%s-%s.tgz", tt.chart, tt.version) - err := tt.releaser.addToIndexFile(indexFile, url) + err := tt.releaser.addToIndexFile(indexFile, url, tt.filename) if tt.error { assert.Error(t, err) assert.False(t, indexFile.Has(tt.chart, tt.version)) @@ -467,7 +485,7 @@ func TestReleaser_CreateReleases(t *testing.T) { assert.Equal(t, tt.commit, fakeGitHub.release.Commit) assert.Equal(t, tt.latest, fakeGitHub.release.MakeLatest) assert.Equal(t, tt.Releaser.config.Commit, fakeGitHub.release.Commit) - fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 1) + fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 2) } }) } diff --git a/pkg/releaser/testdata/release-packages/test-chart-0.1.0+Chart1.tgz b/pkg/releaser/testdata/release-packages/test-chart-0.1.0+Chart1.tgz new file mode 100644 index 00000000..9ba6d6c3 Binary files /dev/null and b/pkg/releaser/testdata/release-packages/test-chart-0.1.0+Chart1.tgz differ