From 5e364234b7406b20e55bf0f1ade7450ca577a408 Mon Sep 17 00:00:00 2001 From: Nieky Allen Date: Thu, 13 Jan 2022 14:25:09 -0600 Subject: [PATCH] extend functionality with bump-policy --- README.md | 17 +++++++++++++++++ index.js | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f30e607..83a2b3b 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,23 @@ Set a custom commit message for version bump commit. Useful for skipping additio commit-message: 'CI: bumps version to {{version}} [skip ci]' ``` +#### **bump-policy:** +Set version bump ignore policy. Useful for pull requests between branches with version bumps. Options are as follows: + +* `'all'` (default): checks all commit messages and skips bump if any previous bumps found +* `'ignore'`: always bump regardless of whether bumps included in commit messages +* `'last-commit'`: bump if last commit was not version bump + +Example: +```yaml +- name: 'Automated Version Bump' + uses: 'phips28/gh-action-bump-version@master' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + bump-policy: 'ignore' +``` + #### [DEPRECATED] **push:** **DEPRECATED** Set false you want to avoid pushing the new version tag/package.json. Example: ```yaml diff --git a/index.js b/index.js index 98205a3..d45da8e 100644 --- a/index.js +++ b/index.js @@ -25,8 +25,21 @@ const workspace = process.env.GITHUB_WORKSPACE; const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}'; console.log('commit messages:', messages); + + const bumpPolicy = process.env['INPUT_BUMP-POLICY'] || 'all'; const commitMessageRegex = new RegExp(commitMessage.replace(/{{version}}/g, `${tagPrefix}\\d+\\.\\d+\\.\\d+`), 'ig'); - const isVersionBump = messages.find((message) => commitMessageRegex.test(message)) !== undefined; + + let isVersionBump = false; + + if (bumpPolicy === 'all') { + isVersionBump = messages.find((message) => commitMessageRegex.test(message)) !== undefined; + } else if (bumpPolicy === 'last-commit') { + isVersionBump = messages.length > 0 && commitMessageRegex.test(messages[messages.length - 1]); + } else if (bumpPolicy === 'ignore') { + console.log('Ignoring any version bumps in commits...'); + } else { + console.warn(`Unknown bump policy: ${bumpPolicy}`); + } if (isVersionBump) { exitSuccess('No action necessary because we found a previous bump!');