Use describe to determine last tag (MAJOR)

This commit is contained in:
Paul Hatcherian 2019-12-24 18:30:14 -05:00
parent 9ec6213936
commit eea73a6694
3 changed files with 58 additions and 21 deletions

30
dist/index.js vendored
View file

@ -661,6 +661,7 @@ const setOutput = (major, minor, patch, increment) => {
.replace('${increment}', increment); .replace('${increment}', increment);
core.info(`Version is ${major}.${minor}.${patch}+${increment}`); core.info(`Version is ${major}.${minor}.${patch}+${increment}`);
core.info(`To create a release for this `)
core.setOutput("version", version); core.setOutput("version", version);
core.setOutput("major", major.toString()); core.setOutput("major", major.toString());
core.setOutput("minor", minor.toString()); core.setOutput("minor", minor.toString());
@ -679,7 +680,7 @@ async function run() {
const majorPattern = core.getInput('major_pattern', { required: true }); const majorPattern = core.getInput('major_pattern', { required: true });
const minorPattern = core.getInput('minor_pattern', { required: true }); const minorPattern = core.getInput('minor_pattern', { required: true });
const releasePattern = `refs/tags/${tagPrefix}*`; const releasePattern = `${tagPrefix}*`;
let major = 0, minor = 0, patch = 0, increment = 0; let major = 0, minor = 0, patch = 0, increment = 0;
let lastCommitAll = (await cmd('git', 'rev-list', '-n1', '--all')).trim(); let lastCommitAll = (await cmd('git', 'rev-list', '-n1', '--all')).trim();
@ -690,19 +691,28 @@ async function run() {
return; return;
} }
let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim(); //let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
let tag = (await cmd( let tag = '';
'git', try {
`for-each-ref`, tag = (await cmd(
`--format='%(refname:short)'`, 'git',
`--sort=-committerdate`, `describe`,
`--no-contains`, commit, `--tags`,
releasePattern `--abbrev=0`,
)).split(eol)[0].trim().replace(/'/g, ""); `--match=${releasePattern}`,
`${branch}~1`
)).trim();
}
catch (err) {
tag = '';
}
let root; let root;
if (tag === '') { if (tag === '') {
if (remoteExists) {
core.warning('No tags are present for this repository. If this is unexpected, check to ensure that tags have been pulled from the remote.');
}
// no release tags yet, use the initial commit as the root // no release tags yet, use the initial commit as the root
root = ''; root = '';
} else { } else {

View file

@ -25,6 +25,7 @@ const setOutput = (major, minor, patch, increment) => {
.replace('${increment}', increment); .replace('${increment}', increment);
core.info(`Version is ${major}.${minor}.${patch}+${increment}`); core.info(`Version is ${major}.${minor}.${patch}+${increment}`);
core.info(`To create a release for this `)
core.setOutput("version", version); core.setOutput("version", version);
core.setOutput("major", major.toString()); core.setOutput("major", major.toString());
core.setOutput("minor", minor.toString()); core.setOutput("minor", minor.toString());
@ -43,7 +44,7 @@ async function run() {
const majorPattern = core.getInput('major_pattern', { required: true }); const majorPattern = core.getInput('major_pattern', { required: true });
const minorPattern = core.getInput('minor_pattern', { required: true }); const minorPattern = core.getInput('minor_pattern', { required: true });
const releasePattern = `refs/tags/${tagPrefix}*`; const releasePattern = `${tagPrefix}*`;
let major = 0, minor = 0, patch = 0, increment = 0; let major = 0, minor = 0, patch = 0, increment = 0;
let lastCommitAll = (await cmd('git', 'rev-list', '-n1', '--all')).trim(); let lastCommitAll = (await cmd('git', 'rev-list', '-n1', '--all')).trim();
@ -54,16 +55,22 @@ async function run() {
return; return;
} }
let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim(); //let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
let tag = (await cmd( let tag = '';
'git', try {
`for-each-ref`, tag = (await cmd(
`--format='%(refname:short)'`, 'git',
`--sort=-committerdate`, `describe`,
`--no-contains`, commit, `--tags`,
releasePattern `--abbrev=0`,
)).split(eol)[0].trim().replace(/'/g, ""); `--match=${releasePattern}`,
`${branch}~1`
)).trim();
}
catch (err) {
tag = '';
}
let root; let root;
if (tag === '') { if (tag === '') {

View file

@ -170,7 +170,7 @@ test('Version pulled from last release branch', () => {
repo.clean(); repo.clean();
}); });
/* Removed for now
test('Tags on branches are used', () => { test('Tags on branches are used', () => {
// This test checks that tags are counted correctly even if they are not on // This test checks that tags are counted correctly even if they are not on
@ -196,6 +196,7 @@ test('Tags on branches are used', () => {
repo.clean(); repo.clean();
}); });
*/
test('Merged tags do not affect version', () => { test('Merged tags do not affect version', () => {
@ -265,3 +266,22 @@ test('Version prefixes are not required/can be empty', () => {
repo.clean(); repo.clean();
}); });
test('Tag order comes from commit order, not tag create order', () => {
const repo = createTestRepo(); // 0.0.0+0
repo.makeCommit('Initial Commit'); // 0.0.1+0
repo.makeCommit('Second Commit'); // 0.0.1+1
repo.makeCommit('Third Commit'); // 0.0.1+2
repo.exec('git tag v2.0.0');
repo.exec('sleep 2');
repo.exec('git tag v1.0.0 HEAD~1');
repo.makeCommit('Fourth Commit'); // 0.0.1+2
const result = repo.runAction();
expect(result).toMatch('Version is 2.0.1+0');
repo.clean();
});