extend functionality with bump-policy

This commit is contained in:
Nieky Allen 2022-01-13 14:25:09 -06:00
parent 8d1fb3d7cd
commit 5e364234b7
2 changed files with 31 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]' 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] **push:**
**DEPRECATED** Set false you want to avoid pushing the new version tag/package.json. Example: **DEPRECATED** Set false you want to avoid pushing the new version tag/package.json. Example:
```yaml ```yaml

View File

@ -25,8 +25,21 @@ const workspace = process.env.GITHUB_WORKSPACE;
const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}'; const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}';
console.log('commit messages:', messages); 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 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) { if (isVersionBump) {
exitSuccess('No action necessary because we found a previous bump!'); exitSuccess('No action necessary because we found a previous bump!');