mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 13:08:17 +00:00
Use describe to determine last tag (MAJOR)
This commit is contained in:
parent
9ec6213936
commit
eea73a6694
3 changed files with 58 additions and 21 deletions
30
dist/index.js
vendored
30
dist/index.js
vendored
|
|
@ -661,6 +661,7 @@ const setOutput = (major, minor, patch, increment) => {
|
|||
.replace('${increment}', increment);
|
||||
|
||||
core.info(`Version is ${major}.${minor}.${patch}+${increment}`);
|
||||
core.info(`To create a release for this `)
|
||||
core.setOutput("version", version);
|
||||
core.setOutput("major", major.toString());
|
||||
core.setOutput("minor", minor.toString());
|
||||
|
|
@ -679,7 +680,7 @@ async function run() {
|
|||
const majorPattern = core.getInput('major_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 lastCommitAll = (await cmd('git', 'rev-list', '-n1', '--all')).trim();
|
||||
|
|
@ -690,19 +691,28 @@ async function run() {
|
|||
return;
|
||||
}
|
||||
|
||||
let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
//let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
|
||||
let tag = (await cmd(
|
||||
'git',
|
||||
`for-each-ref`,
|
||||
`--format='%(refname:short)'`,
|
||||
`--sort=-committerdate`,
|
||||
`--no-contains`, commit,
|
||||
releasePattern
|
||||
)).split(eol)[0].trim().replace(/'/g, "");
|
||||
let tag = '';
|
||||
try {
|
||||
tag = (await cmd(
|
||||
'git',
|
||||
`describe`,
|
||||
`--tags`,
|
||||
`--abbrev=0`,
|
||||
`--match=${releasePattern}`,
|
||||
`${branch}~1`
|
||||
)).trim();
|
||||
}
|
||||
catch (err) {
|
||||
tag = '';
|
||||
}
|
||||
|
||||
let root;
|
||||
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
|
||||
root = '';
|
||||
} else {
|
||||
|
|
|
|||
27
index.js
27
index.js
|
|
@ -25,6 +25,7 @@ const setOutput = (major, minor, patch, increment) => {
|
|||
.replace('${increment}', increment);
|
||||
|
||||
core.info(`Version is ${major}.${minor}.${patch}+${increment}`);
|
||||
core.info(`To create a release for this `)
|
||||
core.setOutput("version", version);
|
||||
core.setOutput("major", major.toString());
|
||||
core.setOutput("minor", minor.toString());
|
||||
|
|
@ -43,7 +44,7 @@ async function run() {
|
|||
const majorPattern = core.getInput('major_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 lastCommitAll = (await cmd('git', 'rev-list', '-n1', '--all')).trim();
|
||||
|
|
@ -54,16 +55,22 @@ async function run() {
|
|||
return;
|
||||
}
|
||||
|
||||
let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
//let commit = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
|
||||
let tag = (await cmd(
|
||||
'git',
|
||||
`for-each-ref`,
|
||||
`--format='%(refname:short)'`,
|
||||
`--sort=-committerdate`,
|
||||
`--no-contains`, commit,
|
||||
releasePattern
|
||||
)).split(eol)[0].trim().replace(/'/g, "");
|
||||
let tag = '';
|
||||
try {
|
||||
tag = (await cmd(
|
||||
'git',
|
||||
`describe`,
|
||||
`--tags`,
|
||||
`--abbrev=0`,
|
||||
`--match=${releasePattern}`,
|
||||
`${branch}~1`
|
||||
)).trim();
|
||||
}
|
||||
catch (err) {
|
||||
tag = '';
|
||||
}
|
||||
|
||||
let root;
|
||||
if (tag === '') {
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ test('Version pulled from last release branch', () => {
|
|||
repo.clean();
|
||||
});
|
||||
|
||||
|
||||
/* Removed for now
|
||||
test('Tags on branches are used', () => {
|
||||
|
||||
// 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();
|
||||
});
|
||||
*/
|
||||
|
||||
test('Merged tags do not affect version', () => {
|
||||
|
||||
|
|
@ -265,3 +266,22 @@ test('Version prefixes are not required/can be empty', () => {
|
|||
|
||||
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();
|
||||
});
|
||||
Loading…
Reference in a new issue