Skip to content

Commit

Permalink
Move worktree creation out of loop and add single push on upload action
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Panteleev <ispanteleev@gmail.com>
  • Loading branch information
amalgamm committed Aug 1, 2023
1 parent 4217848 commit 5fd540c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 9 additions & 11 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}

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 5fd540c

Please sign in to comment.