From 0bc0479d65e4e7e10dd4bb4e32b880953dfa9c9c Mon Sep 17 00:00:00 2001 From: Ivan Panteleev Date: Wed, 26 Jul 2023 15:44:50 +0300 Subject: [PATCH 1/2] Move worktree creation out of loop and add single push on upload action Signed-off-by: Ivan Panteleev Signed-off-by: amalgamm --- pkg/releaser/releaser.go | 20 +++++++++----------- pkg/releaser/releaser_test.go | 4 ++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 7974647e..f66f604d 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -301,10 +301,13 @@ func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error { // CreateReleases finds and uploads Helm chart packages to GitHub func (r *Releaser) CreateReleases() error { - packages, err := r.getListOfPackages(r.config.PackagePath) + 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 len(packages) == 0 { return errors.Errorf("no charts found at %s", r.config.PackagePath) @@ -346,12 +349,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 +361,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) From 8ea317061dcf71475267ce7b8836fe608f5d3690 Mon Sep 17 00:00:00 2001 From: amalgamm Date: Mon, 5 Feb 2024 14:34:22 +0300 Subject: [PATCH 2/2] Fix lint Signed-off-by: amalgamm --- pkg/releaser/releaser.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index f66f604d..687074df 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -308,6 +308,9 @@ func (r *Releaser) CreateReleases() error { defer r.git.RemoveWorktree("", worktree) // nolint: errcheck packages, err := r.getListOfPackages(r.config.PackagePath) + if err != nil { + return err + } if len(packages) == 0 { return errors.Errorf("no charts found at %s", r.config.PackagePath)