fix: create CHANGELOG.md if it does not exist

This commit is contained in:
Julian Tölle 2024-11-15 18:00:55 +01:00
parent e9b3ba8ea2
commit 77ba3023c4
2 changed files with 11 additions and 5 deletions

View file

@ -19,6 +19,7 @@ import (
const ( const (
remoteName = "origin" remoteName = "origin"
newFilePermissions = 0o644
) )
type Commit struct { type Commit struct {
@ -97,13 +98,18 @@ func (r *Repository) Checkout(_ context.Context, branch string) error {
return nil return nil
} }
func (r *Repository) UpdateFile(_ context.Context, path string, updaters []updater.Updater) error { func (r *Repository) UpdateFile(_ context.Context, path string, create bool, updaters []updater.Updater) error {
worktree, err := r.r.Worktree() worktree, err := r.r.Worktree()
if err != nil { if err != nil {
return err return err
} }
file, err := worktree.Filesystem.OpenFile(path, os.O_RDWR, 0) fileFlags := os.O_RDWR
if create {
fileFlags |= os.O_CREATE
}
file, err := worktree.Filesystem.OpenFile(path, fileFlags, newFilePermissions)
if err != nil { if err != nil {
return err return err
} }

View file

@ -253,14 +253,14 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
// Info for updaters // Info for updaters
info := updater.ReleaseInfo{Version: nextVersion, ChangelogEntry: changelogEntry} info := updater.ReleaseInfo{Version: nextVersion, ChangelogEntry: changelogEntry}
err = repo.UpdateFile(ctx, updater.ChangelogFile, updater.WithInfo(info, updater.Changelog)) err = repo.UpdateFile(ctx, updater.ChangelogFile, true, updater.WithInfo(info, updater.Changelog))
if err != nil { if err != nil {
return fmt.Errorf("failed to update changelog file: %w", err) return fmt.Errorf("failed to update changelog file: %w", err)
} }
for _, path := range rp.extraFiles { for _, path := range rp.extraFiles {
// TODO: Check for missing files // TODO: Check for missing files
err = repo.UpdateFile(ctx, path, updater.WithInfo(info, rp.updaters...)) err = repo.UpdateFile(ctx, path, false, updater.WithInfo(info, rp.updaters...))
if err != nil { if err != nil {
return fmt.Errorf("failed to run file updater: %w", err) return fmt.Errorf("failed to run file updater: %w", err)
} }