Skip to content

Commit

Permalink
Merge pull request #65 from Songmu/version-files
Browse files Browse the repository at this point in the history
support to specify multiple version files by comma separated string in conf
  • Loading branch information
Songmu authored Aug 27, 2022
2 parents e91d4bc + 42269bf commit ba66636
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .rcpr
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
[rcpr]
vPrefix = true
releaseBranch = main
versionFile = version.go
versionFile = version.go,action.yml
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
# Often this is a meta-information file such as gemspec, setup.cfg, package.json, etc.
# Sometimes the source code file, such as version.go or Bar.pm, is used.
# If you do not want to use versioning files but only git tags, specify the "-" string here.
# You can specify multiple version files by comma separated strings.
#
# rcpr.vPrefix
# Flag whether or not v-prefix is added to semver when git tagging. (e.g. v1.2.3 if true)
Expand Down
27 changes: 18 additions & 9 deletions rcpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,21 @@ func (rp *rcpr) Run(ctx context.Context) error {
}
nextVer := currVer.GuessNext(labels)

var vfile string
var vfiles []string
if vf := rp.cfg.VersionFile(); vf != nil {
vfile = vf.String()
vfiles = strings.Split(vf.String(), ",")
for i, v := range vfiles {
vfiles[i] = strings.TrimSpace(v)
}
} else {
vfile, err = detectVersionFile(".", currVer)
vfile, err := detectVersionFile(".", currVer)
if err != nil {
return err
}
if err := rp.cfg.SetVersionFile(vfile); err != nil {
return err
}
vfiles = []string{vfile}
}

if com := rp.cfg.Command(); com != nil {
Expand All @@ -209,9 +213,11 @@ func (rp *rcpr) Run(ctx context.Context) error {
rp.c.cmdE(prog, progArgs...)
}

if vfile != "" {
if err := bumpVersionFile(vfile, currVer, nextVer); err != nil {
return err
if vfiles[0] != "" {
for _, vfile := range vfiles {
if err := bumpVersionFile(vfile, currVer, nextVer); err != nil {
return err
}
}
}
rp.c.GitE("add", "-f", rp.cfg.conf) // ignore any errors
Expand Down Expand Up @@ -271,10 +277,13 @@ func (rp *rcpr) Run(ctx context.Context) error {
// Reread the configuration file (.rcpr) as it may have been rewritten during the cherry-pick process.
rp.cfg.Reload()
if rp.cfg.VersionFile() != nil {
vfile = rp.cfg.VersionFile().String()
vfiles = strings.Split(rp.cfg.VersionFile().String(), ",")
for i, v := range vfiles {
vfiles[i] = strings.TrimSpace(v)
}
}
if vfile != "" {
nVer, _ := retrieveVersionFromFile(vfile, nextVer.vPrefix)
if vfiles[0] != "" {
nVer, _ := retrieveVersionFromFile(vfiles[0], nextVer.vPrefix)
if nVer != nil && nVer.Naked() != nextVer.Naked() {
nextVer = nVer
}
Expand Down

0 comments on commit ba66636

Please sign in to comment.