From f965b1a839559ba3707162600f49f573200c57ac Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Sun, 6 Sep 2020 12:24:19 +0200 Subject: [PATCH] feat: customizable major and minor wording to bump new versions --- README.md | 10 +++++++++- action.yml | 8 ++++++++ index.js | 9 +++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 771811f..f8df1b3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Make sure you use the `actions/checkout@v2` action! ### Workflow * Based on the commit messages, increment the version from the latest release. - * If the string "BREAKING CHANGE" or "major" is found anywhere in any of the commit messages or descriptions the major + * If the string "BREAKING CHANGE", "major" or the Attention pattern `refactor!: drop support for Node 6` is found anywhere in any of the commit messages or descriptions the major version will be incremented. * If a commit message begins with the string "feat" or includes "minor" then the minor version will be increased. This works for most common commit metadata for feature additions: `"feat: new API"` and `"feature: new API"`. @@ -30,6 +30,14 @@ Make sure you use the `actions/checkout@v2` action! with: tag-prefix: '' ``` +**wording:** Customize the messages that trigger the version bump. It must be a string, case sensitive, coma separated (optional). Example: +```yaml +- name: 'Automated Version Bump' + uses: 'phips28/gh-action-bump-version@master' + with: + minor-wording: 'add,Adds,new' + major-wording: 'MAJOR,cut-major' +``` **PACKAGEJSON_DIR:** Param to parse the location of the desired package.json (optional). Example: ```yaml - name: 'Automated Version Bump' diff --git a/action.yml b/action.yml index 4028e0a..bd1e9e1 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,14 @@ inputs: description: 'Prefix that is used for the git tag' default: '' required: false + minor-wording: + description: 'Words list that trigger a minor version bump' + default: 'feat,minor' + required: false + major-wording: + description: 'Words list that trigger a major version bump' + default: 'BREAKING CHANGE,major' + required: false PACKAGEJSON_DIR: description: 'Custom dir to the package' default: '' diff --git a/index.js b/index.js index bebe4ab..d3faa64 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,7 @@ Toolkit.run(async tools => { if (!event.commits) { console.log("Couldn't find any commits in this event, incrementing patch version...") } - + const messages = event.commits ? event.commits.map(commit => commit.message + '\n' + commit.body) : [] const commitMessage = 'version bump to' @@ -25,11 +25,12 @@ Toolkit.run(async tools => { return } + const majorWords = process.env['INPUT_MAJOR-WORDING'].split(',') + const minorWords = process.env['INPUT_MINOR-WORDING'].split(',') let version = 'patch' - if (messages.map(message => /^([a-zA-Z]+)(\(.+\))?(\!)\:/.test(message) || message.includes('BREAKING CHANGE') || message.includes('major')).includes(true)) { + if (messages.some(message => /^([a-zA-Z]+)(\(.+\))?(\!)\:/.test(message) || majorWords.some(word => message.includes(word)))) { version = 'major' - } else if (messages.map( - message => message.toLowerCase().startsWith('feat') || message.toLowerCase().includes('minor')).includes(true)) { + } else if (messages.some(message => minorWords.some(word => message.includes(word)))) { version = 'minor' }