Merge pull request #176 from sherifalaa55/master

Add option to manually override the version type
This commit is contained in:
Phil 2022-09-04 18:30:13 +02:00 committed by GitHub
commit 8ed7678d9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

View File

@ -50,6 +50,16 @@ Customize the messages that trigger the version bump. It must be a string, case
# defaulting to a patch bump. # defaulting to a patch bump.
rc-wording: 'RELEASE,alpha' rc-wording: 'RELEASE,alpha'
``` ```
#### **version-type:**
Override the version type taken from the commit message. Usefull when manually running workflow via workflow_dispatch
```yaml
- name: 'Automated Version Bump'
uses: 'phips28/gh-action-bump-version@master'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version-type: 'minor'
```
#### **default:** #### **default:**
Set a default version bump to use (optional - defaults to patch). Example: Set a default version bump to use (optional - defaults to patch). Example:
```yaml ```yaml

View File

@ -1,4 +1,4 @@
name: Automated Version Bump name: Automated Version Bump with version-type
description: Automated version bump for npm packages. description: Automated version bump for npm packages.
runs: runs:
using: node12 using: node12
@ -11,6 +11,10 @@ inputs:
description: 'Prefix that is used for the git tag' description: 'Prefix that is used for the git tag'
default: '' default: ''
required: false required: false
version-type:
description: 'Overrides version type from commit message'
default: ''
required: false
minor-wording: minor-wording:
description: 'Words list that trigger a minor version bump' description: 'Words list that trigger a minor version bump'
default: 'feat,minor' default: 'feat,minor'

View File

@ -16,10 +16,17 @@ const workspace = process.env.GITHUB_WORKSPACE;
const pkg = getPackageJson(); const pkg = getPackageJson();
const event = process.env.GITHUB_EVENT_PATH ? require(process.env.GITHUB_EVENT_PATH) : {}; const event = process.env.GITHUB_EVENT_PATH ? require(process.env.GITHUB_EVENT_PATH) : {};
if (!event.commits) { if (!event.commits && !process.env['INPUT_VERSION-TYPE']) {
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 version...");
} }
const allowedTypes = ['major', 'minor', 'patch', 'rc']
if (process.env['INPUT_VERSION-TYPE'] && !allowedTypes.includes(process.env['INPUT_VERSION-TYPE'])) {
exitFailure('Invalid version type');
return;
}
const versionType = process.env['INPUT_VERSION-TYPE'];
const tagPrefix = process.env['INPUT_TAG-PREFIX'] || ''; const tagPrefix = process.env['INPUT_TAG-PREFIX'] || '';
console.log('tagPrefix:', tagPrefix); console.log('tagPrefix:', tagPrefix);
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) : [];
@ -62,8 +69,12 @@ const workspace = process.env.GITHUB_WORKSPACE;
// get the pre-release prefix specified in action // get the pre-release prefix specified in action
let preid = process.env.INPUT_PREID; let preid = process.env.INPUT_PREID;
// case if version-type found
if (versionType) {
version = versionType;
}
// case: if wording for MAJOR found // case: if wording for MAJOR found
if ( else 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)),
) )