Skip to content

Commit 26df0e5

Browse files
committed
make autoversion regex match more robust
1 parent 588efc0 commit 26df0e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scripts/release/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,15 @@ func (r *releaseCommand) autoversionFile(ctx context.Context, file, channel, ver
385385
// Utilize the index where the match was found to replace the correct part. The only
386386
// match group is the version.
387387
if match := matchRe.FindStringSubmatchIndex(line); match != nil {
388-
logger.Info(ctx, "updating version number", "line_number", i+1, "match", match, "old_version", line[match[2]:match[3]])
389-
lines[i] = line[:match[2]] + version + line[match[3]:]
388+
vg := matchRe.SubexpIndex("version")
389+
if vg == -1 {
390+
logger.Error(ctx, "version group not found in match", "num_subexp", "match", match, matchRe.NumSubexp(), "subexp_names", matchRe.SubexpNames())
391+
return xerrors.Errorf("bug: version group not found in match")
392+
}
393+
start := match[vg*2]
394+
end := match[vg*2+1]
395+
logger.Info(ctx, "updating version number", "line_number", i+1, "match_start", start, "match_end", end, "old_version", line[start:end])
396+
lines[i] = line[:start] + version + line[end:]
390397
matchRe = nil
391398
break
392399
}

0 commit comments

Comments
 (0)