diff --git a/README.md b/README.md index 83a2b3b..df895ac 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,16 @@ Customize the messages that trigger the version bump. It must be a string, case # defaulting to a patch bump. 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:** Set a default version bump to use (optional - defaults to patch). Example: ```yaml diff --git a/action.yml b/action.yml index 8a7e58d..df21b39 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: Automated Version Bump +name: Automated Version Bump with version-type description: Automated version bump for npm packages. runs: using: node12 @@ -11,6 +11,10 @@ inputs: description: 'Prefix that is used for the git tag' default: '' required: false + version-type: + description: 'Overrides version type from commit message' + default: '' + required: false minor-wording: description: 'Words list that trigger a minor version bump' default: 'feat,minor' diff --git a/index.js b/index.js index d18a664..a90981d 100644 --- a/index.js +++ b/index.js @@ -16,10 +16,17 @@ const workspace = process.env.GITHUB_WORKSPACE; const pkg = getPackageJson(); 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..."); } + 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'] || ''; console.log('tagPrefix:', tagPrefix); 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 let preid = process.env.INPUT_PREID; + // case if version-type found + if (versionType) { + version = versionType; + } // case: if wording for MAJOR found - if ( + else if ( messages.some( (message) => /^([a-zA-Z]+)(\(.+\))?(\!)\:/.test(message) || majorWords.some((word) => message.includes(word)), )