diff --git a/action.yml b/action.yml index 1530a81..9d422c3 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/dist/index.js b/dist/index.js index 7c35a7c..9f889ce 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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'), diff --git a/lib/ActionConfig.js b/lib/ActionConfig.js index ecefae7..2babbf8 100644 --- a/lib/ActionConfig.js +++ b/lib/ActionConfig.js @@ -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. */ diff --git a/lib/main.js b/lib/main.js index 779421e..675d6fa 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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'), diff --git a/lib/providers/DefaultVersionClassifier.js b/lib/providers/DefaultVersionClassifier.js index 27e2460..32d00d8 100644 --- a/lib/providers/DefaultVersionClassifier.js +++ b/lib/providers/DefaultVersionClassifier.js @@ -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); diff --git a/package.json b/package.json index 71d330e..52a20fa 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/readme.md b/readme.md index fbb3fbe..29084eb 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/src/ActionConfig.ts b/src/ActionConfig.ts index 0dbefcd..980d3f2 100644 --- a/src/ActionConfig.ts +++ b/src/ActionConfig.ts @@ -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. */ diff --git a/src/main.test.ts b/src/main.test.ts index 0cc029e..36e5fb1 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -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 diff --git a/src/main.ts b/src/main.ts index 1ad981a..4f1bdba 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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'), diff --git a/src/providers/DefaultVersionClassifier.ts b/src/providers/DefaultVersionClassifier.ts index 66a8136..1ab3d39 100644 --- a/src/providers/DefaultVersionClassifier.ts +++ b/src/providers/DefaultVersionClassifier.ts @@ -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);