Merge pull request #106 from cmario92/master

Fixes to include all options - MAJOR, MINOR, PATCH, PRE-RELEASE
This commit is contained in:
Phil 2021-07-02 10:16:28 +02:00 committed by GitHub
commit 491b98fece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 13 deletions

View File

@ -20,7 +20,7 @@ Toolkit.run(async (tools) => {
const messages = event.commits ? event.commits.map((commit) => commit.message + '\n' + commit.body) : []; const messages = event.commits ? event.commits.map((commit) => commit.message + '\n' + commit.body) : [];
const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}'; const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}';
console.log('messages:', messages); console.log('commit messages:', messages);
const commitMessageRegex = new RegExp(commitMessage.replace(/{{version}}/g, `${tagPrefix}\\d+\\.\\d+\\.\\d+`), 'ig'); const commitMessageRegex = new RegExp(commitMessage.replace(/{{version}}/g, `${tagPrefix}\\d+\\.\\d+\\.\\d+`), 'ig');
const isVersionBump = messages.find((message) => commitMessageRegex.test(message)) !== undefined; const isVersionBump = messages.find((message) => commitMessageRegex.test(message)) !== undefined;
@ -29,25 +29,39 @@ Toolkit.run(async (tools) => {
return; return;
} }
// input wordings for MAJOR, MINOR, PATCH, PRE-RELEASE
const majorWords = process.env['INPUT_MAJOR-WORDING'].split(','); const majorWords = process.env['INPUT_MAJOR-WORDING'].split(',');
const minorWords = process.env['INPUT_MINOR-WORDING'].split(','); const minorWords = process.env['INPUT_MINOR-WORDING'].split(',');
// patch is by default empty, and '' would always be true in the includes(''), thats why we handle it separately
const patchWords = process.env['INPUT_PATCH-WORDING'] ? process.env['INPUT_PATCH-WORDING'].split(',') : null;
const preReleaseWords = process.env['INPUT_RC-WORDING'].split(','); const preReleaseWords = process.env['INPUT_RC-WORDING'].split(',');
// if patch words aren't specified, any commit message qualifies as a patch console.log('config words:', { majorWords, minorWords, patchWords, preReleaseWords });
const patchWords = process.env['INPUT_PATCH-WORDING'] ? process.env['INPUT_PATCH-WORDING'].split(',') : null;
// get default version bump
let version = process.env.INPUT_DEFAULT; let version = process.env.INPUT_DEFAULT;
let foundWord = null; let foundWord = null;
// get the pre-release prefix specified in action
let preid = process.env.INPUT_PREID; let preid = process.env.INPUT_PREID;
// case: if wording for MAJOR found
if ( if (
messages.some( messages.some(
(message) => /^([a-zA-Z]+)(\(.+\))?(\!)\:/.test(message) || majorWords.some((word) => message.includes(word)), (message) => /^([a-zA-Z]+)(\(.+\))?(\!)\:/.test(message) || majorWords.some((word) => message.includes(word)),
) )
) { ) {
version = 'major'; version = 'major';
} else if (messages.some((message) => minorWords.some((word) => message.includes(word)))) { }
// case: if wording for MINOR found
else if (messages.some((message) => minorWords.some((word) => message.includes(word)))) {
version = 'minor'; version = 'minor';
} else if ( }
// case: if wording for PATCH found
else if (patchWords && messages.some((message) => patchWords.some((word) => message.includes(word)))) {
version = 'patch';
}
// case: if wording for PRE-RELEASE found
else if (
messages.some((message) => messages.some((message) =>
preReleaseWords.some((word) => { preReleaseWords.some((word) => {
if (message.includes(word)) { if (message.includes(word)) {
@ -61,27 +75,37 @@ Toolkit.run(async (tools) => {
) { ) {
preid = foundWord.split('-')[1]; preid = foundWord.split('-')[1];
version = 'prerelease'; version = 'prerelease';
} else if (Array.isArray(patchWords) && patchWords.length) {
if (!messages.some((message) => patchWords.some((word) => message.includes(word)))) {
version = null;
}
} }
// case: if default=prerelease, but rc-wording is also set console.log('version action after first waterfall:', version);
// then unset it and do not run, when no rc words found in message
if (version === 'prerelease' && !messages.some((message) => preReleaseWords.some((word) => message.includes(word)))) { // case: if default=prerelease,
// rc-wording is also set
// and does not include any of rc-wording
// then unset it and do not run
if (
version === 'prerelease' &&
preReleaseWords !== '' &&
!messages.some((message) => preReleaseWords.some((word) => message.includes(word)))
) {
version = null; version = null;
} }
// case: if default=prerelease, but rc-wording is NOT set
if (version === 'prerelease' && preid) { if (version === 'prerelease' && preid) {
version = 'prerelease';
version = `${version} --preid=${preid}`; version = `${version} --preid=${preid}`;
} }
console.log('version action after final decision:', version);
// case: if nothing of the above matches
if (version === null) { if (version === null) {
tools.exit.success('No version keywords found, skipping bump.'); tools.exit.success('No version keywords found, skipping bump.');
return; return;
} }
// GIT logic
try { try {
const current = pkg.version.toString(); const current = pkg.version.toString();
// set git user // set git user

View File

@ -1,6 +1,6 @@
{ {
"name": "gh-action-bump-version", "name": "gh-action-bump-version",
"version": "8.2.20", "version": "8.3.0",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/phips28/gh-action-bump-version.git" "url": "git+https://github.com/phips28/gh-action-bump-version.git"