Merge pull request #146 from dallen4/master

Feature: bump-policy option
This commit is contained in:
Phil 2022-01-13 22:19:34 +01:00 committed by GitHub
commit d3fe5cc750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -58,6 +58,10 @@ inputs:
description: 'Set a custom commit message for version bump commit'
default: ''
required: false
bump-policy:
description: 'Set version bump ignore policy'
default: 'all'
required: false
push:
description: '[DEPRECATED] Set to false to skip pushing the new tag'
default: 'true'

View File

@ -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!');