diff --git a/cmd/rp/cmd/run.go b/cmd/rp/cmd/run.go index 36ba0cb..867f949 100644 --- a/cmd/rp/cmd/run.go +++ b/cmd/rp/cmd/run.go @@ -31,7 +31,7 @@ func init() { runCmd.PersistentFlags().StringVar(&flagBranch, "branch", "main", "") runCmd.PersistentFlags().StringVar(&flagOwner, "owner", "", "") runCmd.PersistentFlags().StringVar(&flagRepo, "repo", "", "") - runCmd.PersistentFlags().StringVar(&flagRepo, "extra-files", "", "") + runCmd.PersistentFlags().StringVar(&flagExtraFiles, "extra-files", "", "") } func run(cmd *cobra.Command, _ []string) error { diff --git a/releaserpleaser.go b/releaserpleaser.go index 4bf25f9..ba069e8 100644 --- a/releaserpleaser.go +++ b/releaserpleaser.go @@ -277,6 +277,19 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error { updatedContent = updater.UpdateContent(updatedContent, nextVersion) } + err = file.Truncate(0) + if err != nil { + return fmt.Errorf("failed to replace file content: %w", err) + } + _, err = file.Seek(0, 0) + if err != nil { + return fmt.Errorf("failed to replace file content: %w", err) + } + _, err = file.Write([]byte(updatedContent)) + if err != nil { + return fmt.Errorf("failed to replace file content: %w", err) + } + _, err = worktree.Add(extraFile) if err != nil { return fmt.Errorf("failed to add updated file to git worktree: %w", err) diff --git a/updater.go b/updater.go index 432c7f2..f1aab3c 100644 --- a/updater.go +++ b/updater.go @@ -25,10 +25,12 @@ func (u *GenericUpdater) UpdateContent(content, version string) string { output.Grow(len(content)) for _, line := range strings.Split(content, "\n") { if strings.Contains(line, InlineUpdateMarker) { - line = SemVerRegex.ReplaceAllLiteralString(line, version) + // We strip the "v" prefix to avoid adding/removing it from the users input. + line = SemVerRegex.ReplaceAllLiteralString(line, strings.TrimPrefix(version, "v")) } output.WriteString(line) + // TODO: Fix added newline output.WriteByte('\n') }