From cec8375d0ac00e44484ff25e9fab452bb7b5245a Mon Sep 17 00:00:00 2001 From: dnlcrl Date: Fri, 12 May 2023 09:09:57 +0200 Subject: [PATCH 1/6] add check-last-commit-only to check only in last commit --- README.md | 13 +++++++++++++ action.yml | 4 ++++ index.js | 13 +++++++++++++ 3 files changed, 30 insertions(+) diff --git a/README.md b/README.md index 14c2621..4596f3f 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,19 @@ Example: bump-policy: 'ignore' ``` +### **check-only-last-commit** + +Set check-last-commit-only to only read last commit's message (optional). Example: + +```yaml +- name: 'Automated Version Bump' + uses: 'phips28/gh-action-bump-version@master' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + check-last-commit-only: 'true' +``` + #### [DEPRECATED] **push:** **DEPRECATED** Set false you want to avoid pushing the new version tag/package.json. Example: ```yaml diff --git a/action.yml b/action.yml index dee53c2..775160b 100644 --- a/action.yml +++ b/action.yml @@ -70,6 +70,10 @@ inputs: description: 'Set version bump ignore policy' default: 'all' required: false + check-last-commit-only: + description: 'Check only last commit's message' + default: 'false' + required: false push: description: '[DEPRECATED] Set to false to skip pushing the new tag' default: 'true' diff --git a/index.js b/index.js index 6d6cb51..308e1a1 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,19 @@ const pkg = getPackageJson(); const tagSuffix = process.env['INPUT_TAG-SUFFIX'] || ''; console.log('tagPrefix:', tagPrefix); console.log('tagSuffix:', tagSuffix); + + const checkLAstCommitOnly = process.env['INPUT_CHECK-LAST-COMMIT-ONLY'] || 'false'; + + if (checkLAstCommitOnly === 'true') { + console.log('Only checking the last commit...'); + const commit = event.commits ? event.commits[event.commits.length - 1] : null; + const messages = commit ? [commit.message + '\n' + commit.body] : []; + await run(messages, versionType, tagPrefix, tagSuffix, pkg); + } else { + const messages = event.commits ? event.commits.map((commit) => commit.message + '\n' + commit.body) : []; + await run(messages, versionType, tagPrefix, tagSuffix, pkg); + } + 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}}'; From 0e016e8ccb7522397fe5e8f6700572de30de39da Mon Sep 17 00:00:00 2001 From: dnlcrl Date: Fri, 12 May 2023 09:11:12 +0200 Subject: [PATCH 2/6] fix title typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4596f3f..63d2a0a 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ Example: bump-policy: 'ignore' ``` -### **check-only-last-commit** +#### **check-last-commit-only:** Set check-last-commit-only to only read last commit's message (optional). Example: From 394c299ffeced0d7e9e4ac536d75b6cccfa8d7e3 Mon Sep 17 00:00:00 2001 From: dnlcrl Date: Fri, 12 May 2023 09:28:57 +0200 Subject: [PATCH 3/6] fix check --- index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 308e1a1..a330420 100644 --- a/index.js +++ b/index.js @@ -38,18 +38,15 @@ const pkg = getPackageJson(); const checkLAstCommitOnly = process.env['INPUT_CHECK-LAST-COMMIT-ONLY'] || 'false'; + let messages = [] if (checkLAstCommitOnly === 'true') { console.log('Only checking the last commit...'); const commit = event.commits ? event.commits[event.commits.length - 1] : null; - const messages = commit ? [commit.message + '\n' + commit.body] : []; - await run(messages, versionType, tagPrefix, tagSuffix, pkg); + messages = commit ? [commit.message + '\n' + commit.body] : []; } else { - const messages = event.commits ? event.commits.map((commit) => commit.message + '\n' + commit.body) : []; - await run(messages, versionType, tagPrefix, tagSuffix, pkg); + 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}}'; console.log('commit messages:', messages); From fb5e5b85fbb911bb90624473f0d246dc44ce2c94 Mon Sep 17 00:00:00 2001 From: dnlcrl Date: Fri, 12 May 2023 10:08:36 +0200 Subject: [PATCH 4/6] typo fix --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a330420..9001f92 100644 --- a/index.js +++ b/index.js @@ -36,10 +36,10 @@ const pkg = getPackageJson(); console.log('tagPrefix:', tagPrefix); console.log('tagSuffix:', tagSuffix); - const checkLAstCommitOnly = process.env['INPUT_CHECK-LAST-COMMIT-ONLY'] || 'false'; + const checkLastCommitOnly = process.env['INPUT_CHECK-LAST-COMMIT-ONLY'] || 'false'; let messages = [] - if (checkLAstCommitOnly === 'true') { + if (checkLastCommitOnly === 'true') { console.log('Only checking the last commit...'); const commit = event.commits ? event.commits[event.commits.length - 1] : null; messages = commit ? [commit.message + '\n' + commit.body] : []; From affc39eb17c17cff2db62d2c64dd6cb6b6634b1e Mon Sep 17 00:00:00 2001 From: dnlcrl Date: Fri, 12 May 2023 10:12:15 +0200 Subject: [PATCH 5/6] fix yml syntax at line 74, column 42 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 775160b..badf092 100644 --- a/action.yml +++ b/action.yml @@ -71,7 +71,7 @@ inputs: default: 'all' required: false check-last-commit-only: - description: 'Check only last commit's message' + description: 'Check only last commit message' default: 'false' required: false push: From 23b399903333b9a93ef753de4d4b1d36a4ffdfa8 Mon Sep 17 00:00:00 2001 From: dnlcrl Date: Fri, 12 May 2023 11:35:59 +0200 Subject: [PATCH 6/6] add also a check for commits.lengths --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9001f92..7da1cf6 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ const pkg = getPackageJson(); let messages = [] if (checkLastCommitOnly === 'true') { console.log('Only checking the last commit...'); - const commit = event.commits ? event.commits[event.commits.length - 1] : null; + const commit = event.commits && event.commits.lengths > 0 ? event.commits[event.commits.length - 1] : null; messages = commit ? [commit.message + '\n' + commit.body] : []; } else { messages = event.commits ? event.commits.map((commit) => commit.message + '\n' + commit.body) : [];