mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-27 00:14:24 +00:00
Support regex as major/minor match patterns
This commit is contained in:
parent
9e192e115f
commit
9475102a4a
5 changed files with 58 additions and 16 deletions
23
dist/index.js
vendored
23
dist/index.js
vendored
|
|
@ -1113,6 +1113,17 @@ const parseVersion = (tag) => {
|
|||
return [major, minor, patch];
|
||||
};
|
||||
|
||||
const createMatchTest = (pattern) => {
|
||||
|
||||
if (pattern.startsWith('/') && pattern.endsWith('/')) {
|
||||
var regex = new RegExp(pattern.slice(1, -1));
|
||||
return (l) => regex.test(l);
|
||||
} else {
|
||||
return (l) => l.includes(pattern);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const remote = await cmd('git', 'remote');
|
||||
|
|
@ -1120,8 +1131,8 @@ async function run() {
|
|||
const remotePrefix = remoteExists ? 'origin/' : '';
|
||||
|
||||
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
||||
const majorPattern = core.getInput('major_pattern', { required: true });
|
||||
const minorPattern = core.getInput('minor_pattern', { required: true });
|
||||
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
||||
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
||||
const changePath = core.getInput('change_path') || '';
|
||||
|
||||
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||
|
|
@ -1199,11 +1210,11 @@ async function run() {
|
|||
history.forEach(line => {
|
||||
if (currentTag) {
|
||||
[major, minor, patch] = parseVersion(currentTag);
|
||||
} else if (line.includes(majorPattern)) {
|
||||
} else if (majorPattern(line)) {
|
||||
major += 1;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
} else if (line.includes(minorPattern)) {
|
||||
} else if (minorPattern(line)) {
|
||||
minor += 1;
|
||||
patch = 0;
|
||||
} else {
|
||||
|
|
@ -1218,8 +1229,8 @@ async function run() {
|
|||
// Discover the change time from the history log by finding the oldest log
|
||||
// that could set the version.
|
||||
|
||||
const majorIndex = history.findIndex(x => x.includes(majorPattern));
|
||||
const minorIndex = history.findIndex(x => x.includes(minorPattern));
|
||||
const majorIndex = history.findIndex(x => majorPattern(x));
|
||||
const minorIndex = history.findIndex(x => minorPattern(x));
|
||||
|
||||
if (majorIndex !== -1) {
|
||||
increment = history.length - (majorIndex + 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue