From c4c54e048ac0173a1b802a694af16894a81a7c7c Mon Sep 17 00:00:00 2001 From: gmaggiodev Date: Tue, 6 Oct 2020 17:19:47 +0200 Subject: [PATCH 1/5] added prerelease support --- README.md | 1 + index.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a30c69..c91aa19 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Make sure you use the `actions/checkout@v2` action! 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"`. + * If a commit message contains the word "prerelease" then the pre-release version will be increased (for example 1.6.0-alpha.1 -> 1.6.0-alpha.2) * All other changes will increment the patch version. * Push the bumped npm version in package.json back into the repo. * Push a tag for the new version back into the repo. diff --git a/index.js b/index.js index e558a44..5afd556 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ Toolkit.run(async tools => { const event = tools.context.payload if (!event.commits) { - console.log('Couldn\'t find any commits in this event, incrementing patch version...') + console.log('Couldn\'t find any commits in this event, incrementing patch/prerelease version...') } const messages = event.commits ? event.commits.map(commit => commit.message + '\n' + commit.body) : [] @@ -34,6 +34,8 @@ Toolkit.run(async tools => { version = 'major' } else if (messages.some(message => minorWords.some(word => message.includes(word)))) { version = 'minor' + } else if (messages.some(message => message.includes('prerelease'))) { + version = 'prerelease' } try { From fcbd2a1268d93774f603db68307b0224f669a014 Mon Sep 17 00:00:00 2001 From: gmaggiodev Date: Tue, 6 Oct 2020 17:50:52 +0200 Subject: [PATCH 2/5] support for preId --- index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5afd556..b369c37 100644 --- a/index.js +++ b/index.js @@ -28,14 +28,28 @@ Toolkit.run(async tools => { const majorWords = process.env['INPUT_MAJOR-WORDING'].split(',') const minorWords = process.env['INPUT_MINOR-WORDING'].split(',') + const prereleaseWords = ['preprelease', 'alpha', 'beta', 'rc'] + let version = 'patch' + let preid = null; + let foundWords = []; + if (messages.some( message => /^([a-zA-Z]+)(\(.+\))?(\!)\:/.test(message) || majorWords.some(word => message.includes(word)))) { version = 'major' } else if (messages.some(message => minorWords.some(word => message.includes(word)))) { version = 'minor' - } else if (messages.some(message => message.includes('prerelease'))) { - version = 'prerelease' + } else if (messages.some(message => prereleaseWords.some(word => { + if (message.includes(word)) { + foundWords.push(word); + return true; + } else { + return false; + } + } + ))) { + version = 'prerelease'; + console.log(foundWords); } try { From e18d844842d6cc0557c6a402e5f925b210f5c5d7 Mon Sep 17 00:00:00 2001 From: gmaggiodev Date: Tue, 6 Oct 2020 18:10:02 +0200 Subject: [PATCH 3/5] support for preId --- README.md | 2 +- index.js | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c91aa19..23f58e2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Make sure you use the `actions/checkout@v2` action! 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"`. - * If a commit message contains the word "prerelease" then the pre-release version will be increased (for example 1.6.0-alpha.1 -> 1.6.0-alpha.2) + * If a commit message contains the word "pre-alpha" or "pre-beta" or "pre-rc" then the pre-release version will be increased (for example specifying pre-alpha: 1.6.0-alpha.1 -> 1.6.0-alpha.2 or, specifying pre-beta: 1.6.0-alpha.1 -> 1.6.0-beta.0) * All other changes will increment the patch version. * Push the bumped npm version in package.json back into the repo. * Push a tag for the new version back into the repo. diff --git a/index.js b/index.js index b369c37..abc2a2b 100644 --- a/index.js +++ b/index.js @@ -28,28 +28,27 @@ Toolkit.run(async tools => { const majorWords = process.env['INPUT_MAJOR-WORDING'].split(',') const minorWords = process.env['INPUT_MINOR-WORDING'].split(',') - const prereleaseWords = ['preprelease', 'alpha', 'beta', 'rc'] + const preReleaseWords = ['pre-alpha', 'pre-beta', 'pre-rc'] let version = 'patch' - let preid = null; - let foundWords = []; - + let foundWord = null; + if (messages.some( message => /^([a-zA-Z]+)(\(.+\))?(\!)\:/.test(message) || majorWords.some(word => message.includes(word)))) { version = 'major' } else if (messages.some(message => minorWords.some(word => message.includes(word)))) { version = 'minor' - } else if (messages.some(message => prereleaseWords.some(word => { + } else if (messages.some(message => preReleaseWords.some(word => { if (message.includes(word)) { - foundWords.push(word); + foundWord = word; return true; } else { return false; } } ))) { - version = 'prerelease'; - console.log(foundWords); + let preid = foundWord.split("-")[1]; + version = `prerelease --preid=${preid}`; } try { From 07e8645be0e3de51bca981a76fc8a7de16aed725 Mon Sep 17 00:00:00 2001 From: gmaggiodev Date: Tue, 6 Oct 2020 18:26:53 +0200 Subject: [PATCH 4/5] support for preId --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index abc2a2b..e1331da 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ Toolkit.run(async tools => { const event = tools.context.payload if (!event.commits) { - console.log('Couldn\'t find any commits in this event, incrementing patch/prerelease version...') + 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) : [] From 741165fce41d894afc3e5f4e58044084e76fbc56 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 6 Oct 2020 21:50:00 +0200 Subject: [PATCH 5/5] use const instead of let --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e1331da..3053e37 100644 --- a/index.js +++ b/index.js @@ -47,7 +47,7 @@ Toolkit.run(async tools => { } } ))) { - let preid = foundWord.split("-")[1]; + const preid = foundWord.split("-")[1]; version = `prerelease --preid=${preid}`; }