mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 04:58:17 +00:00
Merge pull request #13 from PaulHatch/feature/bump-commit
Add support to bump the version on each commit (MINOR)
This commit is contained in:
commit
0c009e37e1
5 changed files with 85 additions and 1 deletions
|
|
@ -34,6 +34,10 @@ inputs:
|
|||
description: "If false, only full versions, i.e. 'v1.0.0', will be supported as tags. If true, tags will support truncated minor and patch versions such as 'v1' (default)."
|
||||
required: true
|
||||
default: "true"
|
||||
bump_each_commit:
|
||||
description: "If true, every commit will be treated as a bump to the version."
|
||||
required: true
|
||||
default: "false"
|
||||
outputs:
|
||||
major:
|
||||
description: "Current major number"
|
||||
|
|
|
|||
19
dist/index.js
vendored
19
dist/index.js
vendored
|
|
@ -1026,6 +1026,7 @@ const eol = '\n';
|
|||
const tagPrefix = core.getInput('tag_prefix') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
const shortTags = core.getInput('short_tags') === 'true';
|
||||
const bumpEachCommit = core.getInput('bump_each_commit') === 'true';
|
||||
|
||||
const cmd = async (command, ...args) => {
|
||||
let output = '', errors = '';
|
||||
|
|
@ -1199,6 +1200,24 @@ async function run() {
|
|||
.split(eol)
|
||||
.reverse();
|
||||
|
||||
if (bumpEachCommit) {
|
||||
core.info(history)
|
||||
history.forEach(line => {
|
||||
if (line.includes(majorPattern)) {
|
||||
major += 1;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
} else if (line.includes(minorPattern)) {
|
||||
minor += 1;
|
||||
patch = 0;
|
||||
} else {
|
||||
patch += 1;
|
||||
}
|
||||
});
|
||||
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
||||
return;
|
||||
}
|
||||
|
||||
// Discover the change time from the history log by finding the oldest log
|
||||
// that could set the version.
|
||||
|
||||
|
|
|
|||
19
index.js
19
index.js
|
|
@ -5,6 +5,7 @@ const eol = '\n';
|
|||
const tagPrefix = core.getInput('tag_prefix') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
const shortTags = core.getInput('short_tags') === 'true';
|
||||
const bumpEachCommit = core.getInput('bump_each_commit') === 'true';
|
||||
|
||||
const cmd = async (command, ...args) => {
|
||||
let output = '', errors = '';
|
||||
|
|
@ -178,6 +179,24 @@ async function run() {
|
|||
.split(eol)
|
||||
.reverse();
|
||||
|
||||
if (bumpEachCommit) {
|
||||
core.info(history)
|
||||
history.forEach(line => {
|
||||
if (line.includes(majorPattern)) {
|
||||
major += 1;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
} else if (line.includes(minorPattern)) {
|
||||
minor += 1;
|
||||
patch = 0;
|
||||
} else {
|
||||
patch += 1;
|
||||
}
|
||||
});
|
||||
setOutput(major, minor, patch, increment, changed, branch, namespace);
|
||||
return;
|
||||
}
|
||||
|
||||
// Discover the change time from the history log by finding the oldest log
|
||||
// that could set the version.
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ const defaultInputs = {
|
|||
major_pattern: "(MAJOR)",
|
||||
minor_pattern: "(MINOR)",
|
||||
format: "${major}.${minor}.${patch}",
|
||||
short_tags: true
|
||||
short_tags: true,
|
||||
bump_each_commit: false
|
||||
};
|
||||
|
||||
// Creates a randomly named git repository and returns a function to execute commands in it
|
||||
|
|
@ -461,5 +462,44 @@ test('Short tag can be switched off', () => {
|
|||
|
||||
expect(result).toMatch('Version is 0.0.1+2');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
||||
test('Bump each commit works', () => {
|
||||
const repo = createTestRepo({ tag_prefix: '', bump_each_commit: true }); // 0.0.0
|
||||
|
||||
expect(repo.runAction()).toMatch('Version is 0.0.0+0');
|
||||
repo.makeCommit('Initial Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 0.0.1+0');
|
||||
repo.makeCommit('Second Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 0.0.2+0');
|
||||
repo.makeCommit('Third Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 0.0.3+0');
|
||||
repo.makeCommit('Fourth Commit (MINOR)');
|
||||
expect(repo.runAction()).toMatch('Version is 0.1.0+0');
|
||||
repo.makeCommit('Fifth Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 0.1.1+0');
|
||||
repo.makeCommit('Sixth Commit (MAJOR)');
|
||||
expect(repo.runAction()).toMatch('Version is 1.0.0+0');
|
||||
repo.makeCommit('Seventh Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 1.0.1+0');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
||||
test('Bump each commit picks up tags', () => {
|
||||
const repo = createTestRepo({ tag_prefix: '', bump_each_commit: true }); // 0.0.0
|
||||
|
||||
expect(repo.runAction()).toMatch('Version is 0.0.0+0');
|
||||
repo.makeCommit('Initial Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 0.0.1+0');
|
||||
repo.makeCommit('Second Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 0.0.2+0');
|
||||
repo.makeCommit('Third Commit');
|
||||
repo.exec('git tag 3.0.0');
|
||||
expect(repo.runAction()).toMatch('Version is 3.0.0+0');
|
||||
repo.makeCommit('Fourth Commit');
|
||||
expect(repo.runAction()).toMatch('Version is 3.0.1+0');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
|
@ -85,6 +85,8 @@ it will be given the new version if the build were to be retriggered, for exampl
|
|||
# Indicate whether short tags like 'v1' should be supported. If false only full
|
||||
# tags like 'v1.0.0' will be recognized.
|
||||
short_tags: true
|
||||
# If this is set to true, *every* commit will be treated as a new version.
|
||||
bump_each_commit: false
|
||||
```
|
||||
|
||||
## Using Multiple Versions in the Same Repository
|
||||
|
|
|
|||
Loading…
Reference in a new issue