mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-11 20:27:02 +00:00
feat: update version references in any files
This commit is contained in:
parent
7b84b3cdcc
commit
f753fbc32d
4 changed files with 107 additions and 18 deletions
36
updater.go
36
updater.go
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue