mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 04:58:17 +00:00
Merge pull request #65 from colas31/supportFlags
Feat: support flags when using regexp
This commit is contained in:
commit
b505a7cf06
11 changed files with 52 additions and 10 deletions
|
|
@ -20,10 +20,18 @@ inputs:
|
|||
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
|
||||
default: "(MAJOR)"
|
||||
major_regexp_flags:
|
||||
description: "A string which indicates the flags used by the `major_pattern` regular expression. Supported flags: idgs"
|
||||
required: false
|
||||
default: ""
|
||||
minor_pattern:
|
||||
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
|
||||
default: "(MINOR)"
|
||||
minor_regexp_flags:
|
||||
description: "A string which indicates the flags used by the `minor_pattern` regular expression. Supported flags: idgs"
|
||||
required: false
|
||||
default: ""
|
||||
version_format:
|
||||
description: "Pattern to use when formatting output version"
|
||||
required: true
|
||||
|
|
|
|||
2
dist/index.js
vendored
2
dist/index.js
vendored
|
|
@ -407,6 +407,8 @@ function run() {
|
|||
useBranches: core.getInput('use_branches') === 'true',
|
||||
majorPattern: core.getInput('major_pattern'),
|
||||
minorPattern: core.getInput('minor_pattern'),
|
||||
majorFlags: core.getInput('major_flags'),
|
||||
minorFlags: core.getInput('minor_flags'),
|
||||
versionFormat: core.getInput('version_format'),
|
||||
changePath: core.getInput('change_path'),
|
||||
namespace: core.getInput('namespace'),
|
||||
|
|
|
|||
|
|
@ -12,8 +12,12 @@ class ActionConfig {
|
|||
this.useBranches = false;
|
||||
/** 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. */
|
||||
this.majorPattern = "(MAJOR)";
|
||||
/** A string which indicates the flags used by the `majorPattern` regular expression. */
|
||||
this.majorFlags = "(MAJOR)";
|
||||
/** 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. */
|
||||
this.minorPattern = "(MINOR)";
|
||||
/** A string which indicates the flags used by the `minorPattern` regular expression. */
|
||||
this.minorFlags = "(MINOR)";
|
||||
/** Pattern to use when formatting output version */
|
||||
this.versionFormat = '${major}.${minor}.${patch}';
|
||||
/** Path to check for changes. If any changes are detected in the path the 'changed' output will true. Enter multiple paths separated by spaces. */
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ function run() {
|
|||
useBranches: core.getInput('use_branches') === 'true',
|
||||
majorPattern: core.getInput('major_pattern'),
|
||||
minorPattern: core.getInput('minor_pattern'),
|
||||
majorFlags: core.getInput('major_regexp_flags'),
|
||||
minorFlags: core.getInput('minor_regexp_flags'),
|
||||
versionFormat: core.getInput('version_format'),
|
||||
changePath: core.getInput('change_path'),
|
||||
namespace: core.getInput('namespace'),
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ const VersionType_1 = require("./VersionType");
|
|||
class DefaultVersionClassifier {
|
||||
constructor(config) {
|
||||
const searchBody = config.searchCommitBody;
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, searchBody);
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
|
||||
}
|
||||
parsePattern(pattern, searchBody) {
|
||||
parsePattern(pattern, flags, searchBody) {
|
||||
if (pattern.startsWith('/') && pattern.endsWith('/')) {
|
||||
var regex = new RegExp(pattern.slice(1, -1));
|
||||
var regex = new RegExp(pattern.slice(1, -1), flags);
|
||||
return searchBody ?
|
||||
(commit) => regex.test(commit.subject) || regex.test(commit.body) :
|
||||
(commit) => regex.test(commit.subject);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write '**/*.ts'",
|
||||
"format-check": "prettier --check '**/*.ts'",
|
||||
"format": "prettier --write **/**.ts",
|
||||
"format-check": "prettier --check **/**.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"package": "ncc build --source-map --license licenses.txt",
|
||||
"test": "jest --config ./jest.config.js",
|
||||
|
|
|
|||
|
|
@ -86,8 +86,12 @@ it will be given the new version if the build were to be retriggered, for exampl
|
|||
# A string which, if present in a git commit, indicates that a change represents a
|
||||
# major (breaking) change, supports regular expressions wrapped with '/'
|
||||
major_pattern: "(MAJOR)"
|
||||
# A string which indicates the flags used by the `major_pattern` regular expression. Supported flags: idgs
|
||||
major_regexp_flags: ""
|
||||
# Same as above except indicating a minor change, supports regular expressions wrapped with '/'
|
||||
minor_pattern: "(MINOR)"
|
||||
# A string which indicates the flags used by the `minor_pattern` regular expression. Supported flags: idgs
|
||||
minor_regexp_flags: ""
|
||||
# A string to determine the format of the version output
|
||||
format: "${major}.${minor}.${patch}-prerelease${increment}"
|
||||
# Optional path to check for changes. If any changes are detected in the path the
|
||||
|
|
|
|||
|
|
@ -8,8 +8,12 @@ export class ActionConfig {
|
|||
public useBranches: boolean = false;
|
||||
/** 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. */
|
||||
public majorPattern: string = "(MAJOR)";
|
||||
/** A string which indicates the flags used by the `majorPattern` regular expression. */
|
||||
public majorFlags: string = "";
|
||||
/** 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. */
|
||||
public minorPattern: string = "(MINOR)";
|
||||
/** A string which indicates the flags used by the `minorPattern` regular expression. */
|
||||
public minorFlags: string = "";
|
||||
/** Pattern to use when formatting output version */
|
||||
public versionFormat: string = '${major}.${minor}.${patch}';
|
||||
/** Path to check for changes. If any changes are detected in the path the 'changed' output will true. Enter multiple paths separated by spaces. */
|
||||
|
|
|
|||
|
|
@ -472,6 +472,22 @@ test('Regular expressions can be used as minor tag', async () => {
|
|||
expect((await repo.runAction()).formattedVersion).toBe('0.1.0+0');
|
||||
}, 15000);
|
||||
|
||||
test('Regular expressions and flags can be used as major tag', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: '', majorPattern: '/s[a-z]+value/', majorFlags: 'i' }); // 0.0.1
|
||||
|
||||
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
||||
repo.makeCommit('Second Commit SomeValue'); // 1.0.0+0
|
||||
expect((await repo.runAction()).formattedVersion).toBe('1.0.0+0');
|
||||
}, 15000);
|
||||
|
||||
test('Regular expressions and flags can be used as minor tag', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: '', minorPattern: '/s[a-z]+value/', minorFlags: 'i' }); // 0.0.1
|
||||
|
||||
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
||||
repo.makeCommit('Second Commit SomeValue'); // 0.0.1+1
|
||||
expect((await repo.runAction()).formattedVersion).toBe('0.1.0+0');
|
||||
}, 15000);
|
||||
|
||||
test('Tag prefix can include forward slash', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: 'version/' }); // 0.0.0
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ export async function run() {
|
|||
useBranches: core.getInput('use_branches') === 'true',
|
||||
majorPattern: core.getInput('major_pattern'),
|
||||
minorPattern: core.getInput('minor_pattern'),
|
||||
majorFlags: core.getInput('major_regexp_flags'),
|
||||
minorFlags: core.getInput('minor_regexp_flags'),
|
||||
versionFormat: core.getInput('version_format'),
|
||||
changePath: core.getInput('change_path'),
|
||||
namespace: core.getInput('namespace'),
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ export class DefaultVersionClassifier implements VersionClassifier {
|
|||
|
||||
constructor(config: ActionConfig) {
|
||||
const searchBody = config.searchCommitBody;
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, searchBody);
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
|
||||
}
|
||||
|
||||
protected parsePattern(pattern: string, searchBody: boolean): (pattern: CommitInfo) => boolean {
|
||||
protected parsePattern(pattern: string, flags: string, searchBody: boolean): (pattern: CommitInfo) => boolean {
|
||||
if (pattern.startsWith('/') && pattern.endsWith('/')) {
|
||||
var regex = new RegExp(pattern.slice(1, -1));
|
||||
var regex = new RegExp(pattern.slice(1, -1), flags);
|
||||
return searchBody ?
|
||||
(commit: CommitInfo) => regex.test(commit.subject) || regex.test(commit.body) :
|
||||
(commit: CommitInfo) => regex.test(commit.subject);
|
||||
|
|
|
|||
Loading…
Reference in a new issue