Skip to content

Commit 5f38122

Browse files
cpanatoCopilot
andauthored
fix: create the directory of the pages index path (#665)
--pages-index-path (for example dev/charts/index.yaml) failed with 'no such file or directory' when the directory did not exist yet in the Pages branch. Create it before copying the index. Refs #234 Signed-off-by: Carlos Panato <ctadeu@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ac240b5 commit 5f38122

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎pkg/releaser/releaser.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ func (r *Releaser) UpdateIndexFile() (bool, error) {
202202
return true, nil
203203
}
204204

205+
if err := os.MkdirAll(filepath.Dir(indexYamlPath), 0o755); err != nil {
206+
return false, err
207+
}
208+
205209
if err := copyFile(r.config.IndexPath, indexYamlPath); err != nil {
206210
return false, err
207211
}

‎pkg/releaser/releaser_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,30 @@ type FakeGitHubWithURLEncoding struct {
746746
func (f *FakeGitHubWithURLEncoding) GetRelease(_ context.Context, _ string) (*github.Release, error) {
747747
return f.release, nil
748748
}
749+
750+
func TestReleaser_UpdateIndexFileCreatesPagesIndexDir(t *testing.T) {
751+
// the directory of the pages index path does not exist in the Pages branch yet
752+
fakeGit := new(FakeGit)
753+
fakeGit.On("RemoveWorktree", mock.Anything, mock.Anything).Return(nil)
754+
fakeGit.On("Pull", mock.Anything, mock.Anything).Return(nil)
755+
fakeGit.On("Add", mock.Anything, mock.Anything).Return(nil)
756+
fakeGit.On("Commit", mock.Anything, mock.Anything).Return(nil)
757+
fakeGit.On("Push", mock.Anything, mock.Anything).Return(nil)
758+
fakeGit.On("GetPushURL", mock.Anything, mock.Anything).Return("", nil)
759+
760+
r := &Releaser{
761+
config: &config.Options{
762+
IndexPath: filepath.Join(t.TempDir(), "index.yaml"),
763+
PackagePath: "testdata/release-packages",
764+
PagesIndexPath: "dev/charts/index.yaml",
765+
Push: true,
766+
},
767+
github: new(FakeGitHub),
768+
git: fakeGit,
769+
}
770+
771+
updated, err := r.UpdateIndexFile()
772+
require.NoError(t, err)
773+
assert.True(t, updated)
774+
fakeGit.AssertCalled(t, "Commit", mock.Anything, "Update dev/charts/index.yaml")
775+
}

0 commit comments

Comments
 (0)