Skip to content

Commit dbfcbde

Browse files
committed
fix: allow package versions with extended semversioning
Signed-off-by: jose <jose.pedrosa@reddit.com>
1 parent 8ad5692 commit dbfcbde

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

pkg/git/git.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,16 @@ func (g *Git) GetPushURL(remote string, token string) (string, error) {
8383
return "", err
8484
}
8585

86-
pushURLArray := strings.SplitAfter(strings.TrimSpace(string(pushURL)), "https://")
87-
pushURLWithToken := fmt.Sprintf("https://x-access-token:%s@%s", token, pushURLArray[1])
86+
pushURLStr := string(pushURL)
87+
found := false
88+
89+
if pushURLStr, found = strings.CutPrefix(pushURLStr, "git@"); found {
90+
pushURLStr = strings.ReplaceAll(pushURLStr, ":", "/")
91+
pushURLStr = strings.TrimSuffix(pushURLStr, ".git\n")
92+
} else {
93+
pushURLStr = strings.TrimPrefix(pushURLStr, "https://")
94+
}
95+
pushURLWithToken := fmt.Sprintf("https://x-access-token:%s@%s", token, strings.Trim(pushURLStr, "\n"))
8896
return pushURLWithToken, nil
8997
}
9098

pkg/releaser/releaser.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (r *Releaser) UpdateIndexFile() (bool, error) {
185185
packageName, packageVersion := tagParts[0], tagParts[1]
186186
fmt.Printf("Found %s-%s.tgz\n", packageName, packageVersion)
187187
if _, err := indexFile.Get(packageName, packageVersion); err != nil {
188-
if err := r.addToIndexFile(indexFile, downloadURL.String()); err != nil {
188+
if err := r.addToIndexFile(indexFile, downloadURL.String(), name); err != nil {
189189
return false, err
190190
}
191191
update = true
@@ -267,8 +267,8 @@ func (r *Releaser) splitPackageNameAndVersion(pkg string) []string {
267267
return []string{pkg[0:delimIndex], pkg[delimIndex+1:]}
268268
}
269269

270-
func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error {
271-
arch := filepath.Join(r.config.PackagePath, filepath.Base(url))
270+
func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, downloadUrl, fileName string) error {
271+
arch := filepath.Join(r.config.PackagePath, filepath.Base(fileName))
272272

273273
// extract chart metadata
274274
fmt.Printf("Extracting chart metadata from %s\n", arch)
@@ -286,7 +286,7 @@ func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error {
286286
// remove url name from url as helm's index library
287287
// adds it in during .Add
288288
// there should be a better way to handle this :(
289-
s := strings.Split(url, "/")
289+
s := strings.Split(downloadUrl, "/")
290290
s = s[:len(s)-1]
291291

292292
if r.config.PackagesWithIndex {

pkg/releaser/releaser_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
288288
name string
289289
chart string
290290
version string
291+
filename string
291292
releaser *Releaser
292293
packagesWithIndex bool
293294
error bool
@@ -296,6 +297,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
296297
"invalid-package",
297298
"does-not-exist",
298299
"0.1.0",
300+
"missing-test-chart-0.1.0.tgz",
299301
&Releaser{
300302
config: &config.Options{
301303
PackagePath: "testdata/release-packages",
@@ -309,6 +311,21 @@ func TestReleaser_addToIndexFile(t *testing.T) {
309311
"valid-package",
310312
"test-chart",
311313
"0.1.0",
314+
"test-chart-0.1.0.tgz",
315+
&Releaser{
316+
config: &config.Options{
317+
PackagePath: "testdata/release-packages",
318+
PackagesWithIndex: false,
319+
},
320+
},
321+
false,
322+
false,
323+
},
324+
{
325+
"valid-package-extra-sem-ver",
326+
"test-chart",
327+
"0.1.0+Chart1",
328+
"test-chart-0.1.0+Chart1.tgz",
312329
&Releaser{
313330
config: &config.Options{
314331
PackagePath: "testdata/release-packages",
@@ -322,6 +339,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
322339
"valid-package-with-index",
323340
"test-chart",
324341
"0.1.0",
342+
"test-chart-0.1.0.tgz",
325343
&Releaser{
326344
config: &config.Options{
327345
PackagePath: "testdata/release-packages",
@@ -336,7 +354,7 @@ func TestReleaser_addToIndexFile(t *testing.T) {
336354
t.Run(tt.name, func(t *testing.T) {
337355
indexFile := repo.NewIndexFile()
338356
url := fmt.Sprintf("https://myrepo/charts/%s-%s.tgz", tt.chart, tt.version)
339-
err := tt.releaser.addToIndexFile(indexFile, url)
357+
err := tt.releaser.addToIndexFile(indexFile, url, tt.filename)
340358
if tt.error {
341359
assert.Error(t, err)
342360
assert.False(t, indexFile.Has(tt.chart, tt.version))
@@ -467,7 +485,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
467485
assert.Equal(t, tt.commit, fakeGitHub.release.Commit)
468486
assert.Equal(t, tt.latest, fakeGitHub.release.MakeLatest)
469487
assert.Equal(t, tt.Releaser.config.Commit, fakeGitHub.release.Commit)
470-
fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 1)
488+
fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 2)
471489
}
472490
})
473491
}
Binary file not shown.

0 commit comments

Comments
 (0)