From dbfcbde0bb375d86a90339939d8e4944d73a7f6f Mon Sep 17 00:00:00 2001 From: jose Date: Wed, 8 May 2024 03:05:46 +0100 Subject: [PATCH] fix: allow package versions with extended semversioning Signed-off-by: jose --- pkg/git/git.go | 12 ++++++++-- pkg/releaser/releaser.go | 8 +++---- pkg/releaser/releaser_test.go | 22 ++++++++++++++++-- .../test-chart-0.1.0+Chart1.tgz | Bin 0 -> 679 bytes 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 pkg/releaser/testdata/release-packages/test-chart-0.1.0+Chart1.tgz 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 0000000000000000000000000000000000000000..9ba6d6c3a77a15c8d1eb7dd54eb09d4fa1f366da GIT binary patch literal 679 zcmV;Y0$BYYiwFS2t#n}k1MODZYTG~%&9lB@5Dl~`mL*$~!H|cN7Fr4^G$nluYiU$3 ztS;SMr7>y#y|XJtz7QudaT5YM57K%)o;h>3Mx_VIoJl=AF;8#7a&fR<_`W}hA~0{l z=G*s!XavDH3@2e2OeQ1ngYhVg4#3|tk2_H-%_LEIs-8{fUI|#m&rvE~7E`zk99C7` zM>p_%*GW+&l2_VZeSps>aV zoKvIAJ7=OsWhKAS;E+5;_zPOrMFR2I9(jINXBoc&cd%53#K@c*iYF4OfPr;3vRa4* z{H~ec8OIc8zFG2~^Aj8GR$dz$hO2@ZCahKnsw7&=@z%IZIz*~~Nd&=ju1TXVDGFS{ z+u6c~k>$lNP!%TcJm*UW5(P5V#w{re&3K{OF>3F)hCf^gvJPaNc#;uIzGZt~ zbdA`0gn8Bl^!CdxsJAj(1s)Z3p_ZE7SP!Phk5B9h&n_5^7Vmo#spiKW*R|W7309I9 zIs^Am4GxvNp{=pIOQ~%;ua)3RZcWp)yU^s-=C>`DMoO?5iu-eHpYB$VRs-Ig+bvGs zNTjKrkh=FSxEJnDuDhZs^vj5v5H7H8D^zw9XHfSHlacEX!Fp2!tcZ+xeK^Tmq zU=+u8|I_-9pLzeYd5-tF{LuHWbpQXLDb#HzlX&|dz>Z}sG;r1Jqcy3Qrro1Qj~+dq Nh=06*4dwt8006wENTdJ& literal 0 HcmV?d00001