From 51850bb2b9ca7906069ed82da6946044ae56fbcb Mon Sep 17 00:00:00 2001 From: Sherif Alaa Date: Sat, 3 Sep 2022 00:55:28 +0200 Subject: [PATCH 1/3] add input for overriding version type --- README.md | 10 ++++++++++ action.yml | 4 ++++ index.js | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) 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..64f2c0e 100644 --- a/action.yml +++ b/action.yml @@ -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..ea802c4 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)), ) From b050c5233564d0e2d3376265edbf04c41715e39c Mon Sep 17 00:00:00 2001 From: Sherif Alaa Date: Sat, 3 Sep 2022 01:03:21 +0200 Subject: [PATCH 2/3] fix condition typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ea802c4..a90981d 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ const workspace = process.env.GITHUB_WORKSPACE; } const allowedTypes = ['major', 'minor', 'patch', 'rc'] - if (process.env['INPUT_VERSION-TYPE'] && allowedTypes.includes(process.env['INPUT_VERSION-TYPE'])) { + if (process.env['INPUT_VERSION-TYPE'] && !allowedTypes.includes(process.env['INPUT_VERSION-TYPE'])) { exitFailure('Invalid version type'); return; } From f837a62007f17c5fb573698e3ab147892573e1c6 Mon Sep 17 00:00:00 2001 From: Sherif Ismael Date: Sat, 3 Sep 2022 01:16:51 +0200 Subject: [PATCH 3/3] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 64f2c0e..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