input tag in commit message detection
This commit is contained in:
parent
261e9bdd0e
commit
b8b23f67d5
|
@ -1,34 +1,34 @@
|
||||||
name: "Bump Version"
|
name: 'Bump Version'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "master"
|
- 'master'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
bump-version:
|
bump-version:
|
||||||
name: "Bump Version on master"
|
name: 'Bump Version on master'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout source code"
|
- name: 'Checkout source code'
|
||||||
uses: "actions/checkout@v2"
|
uses: 'actions/checkout@v2'
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
- name: "cat package.json"
|
- name: 'cat package.json'
|
||||||
run: cat ./package.json
|
run: cat ./package.json
|
||||||
- name: "Setup Node.js"
|
- name: 'Setup Node.js'
|
||||||
uses: "actions/setup-node@v1"
|
uses: 'actions/setup-node@v1'
|
||||||
with:
|
with:
|
||||||
node-version: 12
|
node-version: 12
|
||||||
- name: "Automated Version Bump"
|
- name: 'Automated Version Bump'
|
||||||
id: version-bump
|
id: version-bump
|
||||||
uses: "phips28/gh-action-bump-version@master"
|
uses: 'phips28/gh-action-bump-version@test/tagPrefix'
|
||||||
with:
|
with:
|
||||||
tag-prefix: 'v'
|
tag-prefix: 'v'
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: "cat package.json"
|
- name: 'cat package.json'
|
||||||
run: cat ./package.json
|
run: cat ./package.json
|
||||||
- name: 'Output Step'
|
- name: 'Output Step'
|
||||||
env:
|
env:
|
||||||
|
|
9
index.js
9
index.js
|
@ -16,15 +16,16 @@ Toolkit.run(async (tools) => {
|
||||||
console.log("Couldn't find any commits in this event, incrementing patch version...");
|
console.log("Couldn't find any commits in this event, incrementing patch version...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tagPrefix = process.env['INPUT_TAG-PREFIX'] || '';
|
||||||
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 = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}';
|
const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}';
|
||||||
console.log('messages:', messages);
|
console.log('messages:', messages);
|
||||||
const commitMessageRegex = new RegExp(commitMessage.replace(/{{version}}/g, 'v\\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;
|
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 because we found a previous bump!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ Toolkit.run(async (tools) => {
|
||||||
await tools.runInWorkspace('npm', ['version', '--allow-same-version=true', '--git-tag-version=false', current]);
|
await tools.runInWorkspace('npm', ['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().replace(/^v/, '');
|
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim().replace(/^v/, '');
|
||||||
newVersion = `${process.env['INPUT_TAG-PREFIX']}${newVersion}`;
|
newVersion = `${tagPrefix}${newVersion}`;
|
||||||
await tools.runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, 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
|
||||||
|
@ -124,7 +125,7 @@ Toolkit.run(async (tools) => {
|
||||||
await tools.runInWorkspace('npm', ['version', '--allow-same-version=true', '--git-tag-version=false', current]);
|
await tools.runInWorkspace('npm', ['version', '--allow-same-version=true', '--git-tag-version=false', current]);
|
||||||
console.log('current:', current, '/', 'version:', version);
|
console.log('current:', current, '/', 'version:', version);
|
||||||
newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim().replace(/^v/, '');
|
newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim().replace(/^v/, '');
|
||||||
newVersion = `${process.env['INPUT_TAG-PREFIX']}${newVersion}`;
|
newVersion = `${tagPrefix}${newVersion}`;
|
||||||
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"
|
||||||
|
|
Loading…
Reference in New Issue