mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-29 13:58:17 +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
|
|
@ -13,11 +13,11 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
default: "v"
|
default: "v"
|
||||||
major_pattern:
|
major_pattern:
|
||||||
description: "A string which, if present in a git commit, indicates that a change represents a major (breaking) change"
|
description: "A string which, if present in a git commit, indicates that a change represents a major (breaking) change. Wrap with '/' to match using a regular expression."
|
||||||
required: true
|
required: true
|
||||||
default: "(MAJOR)"
|
default: "(MAJOR)"
|
||||||
minor_pattern:
|
minor_pattern:
|
||||||
description: "A string which, if present in a git commit, indicates that a change represents a minor (feature) change"
|
description: "A string which, if present in a git commit, indicates that a change represents a minor (feature) change. Wrap with '/' to match using a regular expression."
|
||||||
required: true
|
required: true
|
||||||
default: "(MINOR)"
|
default: "(MINOR)"
|
||||||
format:
|
format:
|
||||||
|
|
|
||||||
23
dist/index.js
vendored
23
dist/index.js
vendored
|
|
@ -1113,6 +1113,17 @@ const parseVersion = (tag) => {
|
||||||
return [major, minor, patch];
|
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() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const remote = await cmd('git', 'remote');
|
const remote = await cmd('git', 'remote');
|
||||||
|
|
@ -1120,8 +1131,8 @@ async function run() {
|
||||||
const remotePrefix = remoteExists ? 'origin/' : '';
|
const remotePrefix = remoteExists ? 'origin/' : '';
|
||||||
|
|
||||||
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
||||||
const majorPattern = core.getInput('major_pattern', { required: true });
|
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
||||||
const minorPattern = core.getInput('minor_pattern', { required: true });
|
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
||||||
const changePath = core.getInput('change_path') || '';
|
const changePath = core.getInput('change_path') || '';
|
||||||
|
|
||||||
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||||
|
|
@ -1199,11 +1210,11 @@ async function run() {
|
||||||
history.forEach(line => {
|
history.forEach(line => {
|
||||||
if (currentTag) {
|
if (currentTag) {
|
||||||
[major, minor, patch] = parseVersion(currentTag);
|
[major, minor, patch] = parseVersion(currentTag);
|
||||||
} else if (line.includes(majorPattern)) {
|
} else if (majorPattern(line)) {
|
||||||
major += 1;
|
major += 1;
|
||||||
minor = 0;
|
minor = 0;
|
||||||
patch = 0;
|
patch = 0;
|
||||||
} else if (line.includes(minorPattern)) {
|
} else if (minorPattern(line)) {
|
||||||
minor += 1;
|
minor += 1;
|
||||||
patch = 0;
|
patch = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1218,8 +1229,8 @@ async function run() {
|
||||||
// Discover the change time from the history log by finding the oldest log
|
// Discover the change time from the history log by finding the oldest log
|
||||||
// that could set the version.
|
// that could set the version.
|
||||||
|
|
||||||
const majorIndex = history.findIndex(x => x.includes(majorPattern));
|
const majorIndex = history.findIndex(x => majorPattern(x));
|
||||||
const minorIndex = history.findIndex(x => x.includes(minorPattern));
|
const minorIndex = history.findIndex(x => minorPattern(x));
|
||||||
|
|
||||||
if (majorIndex !== -1) {
|
if (majorIndex !== -1) {
|
||||||
increment = history.length - (majorIndex + 1);
|
increment = history.length - (majorIndex + 1);
|
||||||
|
|
|
||||||
23
index.js
23
index.js
|
|
@ -92,6 +92,17 @@ const parseVersion = (tag) => {
|
||||||
return [major, minor, patch];
|
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() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const remote = await cmd('git', 'remote');
|
const remote = await cmd('git', 'remote');
|
||||||
|
|
@ -99,8 +110,8 @@ async function run() {
|
||||||
const remotePrefix = remoteExists ? 'origin/' : '';
|
const remotePrefix = remoteExists ? 'origin/' : '';
|
||||||
|
|
||||||
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
||||||
const majorPattern = core.getInput('major_pattern', { required: true });
|
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
||||||
const minorPattern = core.getInput('minor_pattern', { required: true });
|
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
||||||
const changePath = core.getInput('change_path') || '';
|
const changePath = core.getInput('change_path') || '';
|
||||||
|
|
||||||
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||||
|
|
@ -178,11 +189,11 @@ async function run() {
|
||||||
history.forEach(line => {
|
history.forEach(line => {
|
||||||
if (currentTag) {
|
if (currentTag) {
|
||||||
[major, minor, patch] = parseVersion(currentTag);
|
[major, minor, patch] = parseVersion(currentTag);
|
||||||
} else if (line.includes(majorPattern)) {
|
} else if (majorPattern(line)) {
|
||||||
major += 1;
|
major += 1;
|
||||||
minor = 0;
|
minor = 0;
|
||||||
patch = 0;
|
patch = 0;
|
||||||
} else if (line.includes(minorPattern)) {
|
} else if (minorPattern(line)) {
|
||||||
minor += 1;
|
minor += 1;
|
||||||
patch = 0;
|
patch = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -197,8 +208,8 @@ async function run() {
|
||||||
// Discover the change time from the history log by finding the oldest log
|
// Discover the change time from the history log by finding the oldest log
|
||||||
// that could set the version.
|
// that could set the version.
|
||||||
|
|
||||||
const majorIndex = history.findIndex(x => x.includes(majorPattern));
|
const majorIndex = history.findIndex(x => majorPattern(x));
|
||||||
const minorIndex = history.findIndex(x => x.includes(minorPattern));
|
const minorIndex = history.findIndex(x => minorPattern(x));
|
||||||
|
|
||||||
if (majorIndex !== -1) {
|
if (majorIndex !== -1) {
|
||||||
increment = history.length - (majorIndex + 1);
|
increment = history.length - (majorIndex + 1);
|
||||||
|
|
|
||||||
|
|
@ -515,3 +515,23 @@ test('Increment not affected by matching tag', () => {
|
||||||
|
|
||||||
repo.clean();
|
repo.clean();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Regular expressions can be used as major tag', () => {
|
||||||
|
const repo = createTestRepo({ tag_prefix: '', major_pattern: '/S[a-z]+Value/' }); // 0.0.1
|
||||||
|
|
||||||
|
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
||||||
|
repo.makeCommit('Second Commit SomeValue'); // 0.0.1+1
|
||||||
|
expect(repo.runAction()).toMatch('Version is 1.0.0+0');
|
||||||
|
|
||||||
|
repo.clean();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Regular expressions can be used as minor tag', () => {
|
||||||
|
const repo = createTestRepo({ tag_prefix: '', minor_pattern: '/S[a-z]+Value/' }); // 0.0.1
|
||||||
|
|
||||||
|
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
||||||
|
repo.makeCommit('Second Commit SomeValue'); // 0.0.1+1
|
||||||
|
expect(repo.runAction()).toMatch('Version is 0.1.0+0');
|
||||||
|
|
||||||
|
repo.clean();
|
||||||
|
});
|
||||||
|
|
@ -71,9 +71,9 @@ it will be given the new version if the build were to be retriggered, for exampl
|
||||||
# The prefix to use to identify tags
|
# The prefix to use to identify tags
|
||||||
tag_prefix: "v"
|
tag_prefix: "v"
|
||||||
# A string which, if present in a git commit, indicates that a change represents a
|
# A string which, if present in a git commit, indicates that a change represents a
|
||||||
# major (breaking) change
|
# major (breaking) change, supports regular expressions wrapped with '/'
|
||||||
major_pattern: "(MAJOR)"
|
major_pattern: "(MAJOR)"
|
||||||
# Same as above except indicating a minor change
|
# Same as above except indicating a minor change, supports regular expressions wrapped with '/'
|
||||||
minor_pattern: "(MINOR)"
|
minor_pattern: "(MINOR)"
|
||||||
# A string to determine the format of the version output
|
# A string to determine the format of the version output
|
||||||
format: "${major}.${minor}.${patch}-prerelease.${increment}"
|
format: "${major}.${minor}.${patch}-prerelease.${increment}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue