diff --git a/action.yml b/action.yml index f8a0c32..fcc2ff4 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/dist/index.js b/dist/index.js index e475104..936dc57 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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. diff --git a/index.js b/index.js index 4ece3c0..1a20da4 100644 --- a/index.js +++ b/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. diff --git a/index.test.js b/index.test.js index b0b8ff5..da7161f 100644 --- a/index.test.js +++ b/index.test.js @@ -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(); }); \ No newline at end of file diff --git a/readme.md b/readme.md index 5b7e140..5175555 100644 --- a/readme.md +++ b/readme.md @@ -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