diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 7974647e..687074df 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -301,6 +301,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 @@ -346,12 +352,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 @@ -364,10 +364,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 } } diff --git a/pkg/releaser/releaser_test.go b/pkg/releaser/releaser_test.go index 55c7841f..bbb7571a 100644 --- a/pkg/releaser/releaser_test.go +++ b/pkg/releaser/releaser_test.go @@ -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)