Skip to content

Commit

Permalink
Peform single push on upload in case of multiple releases (#314)
Browse files Browse the repository at this point in the history
* Move worktree creation out of loop and add single push on upload action

Signed-off-by: Ivan Panteleev <ispanteleev@gmail.com>
Signed-off-by: amalgamm <ispanteleev@gmail.com>

* Fix lint

Signed-off-by: amalgamm <ispanteleev@gmail.com>

---------

Signed-off-by: Ivan Panteleev <ispanteleev@gmail.com>
Signed-off-by: amalgamm <ispanteleev@gmail.com>
  • Loading branch information
amalgamm authored Oct 29, 2024
1 parent 862a0e5 commit f7e4366
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error {

// CreateReleases finds and uploads Helm chart packages to GitHub
func (r *Releaser) CreateReleases() error {
worktree, err := r.git.AddWorktree("", r.config.Remote+"/"+r.config.PagesBranch)
if err != nil {
return err
}
defer r.git.RemoveWorktree("", worktree) // nolint: errcheck

packages, err := r.getListOfPackages(r.config.PackagePath)
if err != nil {
return err
Expand Down Expand Up @@ -334,12 +340,6 @@ func (r *Releaser) CreateReleases() error {
}

if r.config.PackagesWithIndex {
worktree, err := r.git.AddWorktree("", r.config.Remote+"/"+r.config.PagesBranch)
if err != nil {
return err
}
defer r.git.RemoveWorktree("", worktree) //nolint: errcheck

pkgTargetPath := filepath.Join(worktree, filepath.Base(p))
if err := copyFile(p, pkgTargetPath); err != nil {
return err
Expand All @@ -352,10 +352,11 @@ func (r *Releaser) CreateReleases() error {
if err := r.git.Commit(worktree, fmt.Sprintf("Publishing chart package for %s", releaseName)); err != nil {
return err
}

if err := r.pushToPagesBranch(worktree); err != nil {
return err
}
}
}
if r.config.Push {
if err := r.pushToPagesBranch(worktree); err != nil {
return err
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/releaser/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,17 @@ func TestReleaser_ReleaseNotes(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fakeGitHub := new(FakeGitHub)
fakeGit := new(FakeGit)
r := &Releaser{
config: &config.Options{
PackagePath: "testdata/release-packages",
ReleaseNotesFile: tt.releaseNotesFile,
},
github: fakeGitHub,
git: fakeGit,
}
fakeGit.On("AddWorktree", mock.Anything, mock.Anything).Return("/tmp/chart-releaser-012345678", nil)
fakeGit.On("RemoveWorktree", mock.Anything, mock.Anything).Return(nil)
fakeGitHub.On("CreateRelease", mock.Anything, mock.Anything).Return(nil)
err := r.CreateReleases()
assert.NoError(t, err)
Expand Down

0 comments on commit f7e4366

Please sign in to comment.