feat: update version references in any files

This commit is contained in:
Julian Tölle 2024-08-18 00:15:10 +02:00
parent 7b84b3cdcc
commit f753fbc32d
4 changed files with 107 additions and 18 deletions

View file

@ -1,12 +1,36 @@
package rp
import (
"context"
"github.com/go-git/go-git/v5"
"regexp"
"strings"
)
func RunUpdater(ctx context.Context, version string, worktree *git.Worktree) error {
// TODO: Implement updater for Go,Python,ExtraFilesMarkers
return nil
const (
InlineUpdateMarker = "x-releaser-pleaser-version"
)
var (
SemVerRegex = regexp.MustCompile(`(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(-(?<preRelease>[\w.]+))?(\+(?<build>[-\w.]+))?`)
)
type Updater interface {
UpdateContent(content, version string) string
}
type GenericUpdater struct{}
func (u *GenericUpdater) UpdateContent(content, version string) string {
// TODO: use buffered input/output
output := strings.Builder{}
output.Grow(len(content))
for _, line := range strings.Split(content, "\n") {
if strings.Contains(line, InlineUpdateMarker) {
line = SemVerRegex.ReplaceAllLiteralString(line, version)
}
output.WriteString(line)
output.WriteByte('\n')
}
return output.String()
}