Merge pull request #74 from mattanglin/feature/custom-commit-messages
Custom commit message option
This commit is contained in:
commit
39eaeb11e7
10
README.md
10
README.md
|
@ -86,3 +86,13 @@ Make sure you use the `actions/checkout@v2` action!
|
||||||
with:
|
with:
|
||||||
target-branch: 'master'
|
target-branch: 'master'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**commit-message:** Set a custom commit message for version bump commit. Useful for skipping additional workflows run on push. Example:
|
||||||
|
```yaml
|
||||||
|
- name: 'Automated Version Bump'
|
||||||
|
uses: 'phips28/gh-action-bump-version@master'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
commit-message: 'CI: bumps version to {{version}} [skip ci]'
|
||||||
|
```
|
|
@ -39,6 +39,10 @@ inputs:
|
||||||
description: 'Set a default version bump to use'
|
description: 'Set a default version bump to use'
|
||||||
default: 'patch'
|
default: 'patch'
|
||||||
required: false
|
required: false
|
||||||
|
commit-message:
|
||||||
|
description: 'Set a custom commit message for version bump commit'
|
||||||
|
default: ''
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
newTag:
|
newTag:
|
||||||
description: 'The newly created tag'
|
description: 'The newly created tag'
|
||||||
|
|
10
index.js
10
index.js
|
@ -18,9 +18,11 @@ Toolkit.run(async tools => {
|
||||||
|
|
||||||
const 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 = 'version bump to'
|
const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}'
|
||||||
console.log('messages:', messages)
|
console.log('messages:', messages)
|
||||||
const isVersionBump = messages.map(message => message.toLowerCase().includes(commitMessage)).includes(true)
|
const commitMessageRegex = new RegExp(commitMessage.replace(/{{version}}/g, 'v\d\.\d\.\d'), 'ig');
|
||||||
|
const isVersionBump = messages.find(message => commitMessageRegex.test(message)) !== undefined
|
||||||
|
|
||||||
if (isVersionBump) {
|
if (isVersionBump) {
|
||||||
tools.exit.success('No action necessary!')
|
tools.exit.success('No action necessary!')
|
||||||
return
|
return
|
||||||
|
@ -89,7 +91,7 @@ Toolkit.run(async tools => {
|
||||||
['version', '--allow-same-version=true', '--git-tag-version=false', current])
|
['version', '--allow-same-version=true', '--git-tag-version=false', current])
|
||||||
console.log('current:', current, '/', 'version:', version)
|
console.log('current:', current, '/', 'version:', version)
|
||||||
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim()
|
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim()
|
||||||
await tools.runInWorkspace('git', ['commit', '-a', '-m', `ci: ${commitMessage} ${newVersion}`])
|
await tools.runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)])
|
||||||
|
|
||||||
// now go to the actual branch to perform the same versioning
|
// now go to the actual branch to perform the same versioning
|
||||||
if (isPullRequest) {
|
if (isPullRequest) {
|
||||||
|
@ -106,7 +108,7 @@ Toolkit.run(async tools => {
|
||||||
console.log(`::set-output name=newTag::${newVersion}`)
|
console.log(`::set-output name=newTag::${newVersion}`)
|
||||||
try {
|
try {
|
||||||
// to support "actions/checkout@v1"
|
// to support "actions/checkout@v1"
|
||||||
await tools.runInWorkspace('git', ['commit', '-a', '-m', `ci: ${commitMessage} ${newVersion}`])
|
await tools.runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)])
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('git commit failed because you are using "actions/checkout@v2"; ' +
|
console.warn('git commit failed because you are using "actions/checkout@v2"; ' +
|
||||||
'but that doesnt matter because you dont need that git commit, thats only for "actions/checkout@v1"')
|
'but that doesnt matter because you dont need that git commit, thats only for "actions/checkout@v1"')
|
||||||
|
|
Loading…
Reference in New Issue