mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 13:08:17 +00:00
Support and default to HEAD ref for branch (MAJOR)
This commit is contained in:
parent
2909e6bd51
commit
ac2e147b35
4 changed files with 32 additions and 4 deletions
|
|
@ -5,9 +5,9 @@ branding:
|
|||
color: "blue"
|
||||
inputs:
|
||||
branch:
|
||||
description: "The branch name"
|
||||
description: "Set to specify a specific branch, default is the current HEAD"
|
||||
required: true
|
||||
default: "master"
|
||||
default: "HEAD"
|
||||
tag_prefix:
|
||||
description: "The prefix to use to identify tags"
|
||||
required: false
|
||||
|
|
|
|||
10
dist/index.js
vendored
10
dist/index.js
vendored
|
|
@ -1072,6 +1072,10 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
|
|||
tag = `${tagPrefix}${major}`;
|
||||
}
|
||||
|
||||
if (namespace !== '') {
|
||||
tag += `-${namespace}`
|
||||
}
|
||||
|
||||
const repository = process.env.GITHUB_REPOSITORY;
|
||||
|
||||
if (!changed) {
|
||||
|
|
@ -1130,11 +1134,15 @@ async function run() {
|
|||
const remoteExists = remote !== '';
|
||||
const remotePrefix = remoteExists ? 'origin/' : '';
|
||||
|
||||
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
||||
let branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
||||
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
||||
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
||||
const changePath = core.getInput('change_path') || '';
|
||||
|
||||
if (branch === 'HEAD') {
|
||||
branch = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
}
|
||||
|
||||
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||
|
|
|
|||
6
index.js
6
index.js
|
|
@ -113,11 +113,15 @@ async function run() {
|
|||
const remoteExists = remote !== '';
|
||||
const remotePrefix = remoteExists ? 'origin/' : '';
|
||||
|
||||
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
||||
let branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
||||
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
||||
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
||||
const changePath = core.getInput('change_path') || '';
|
||||
|
||||
if (branch === 'HEAD') {
|
||||
branch = (await cmd('git', 'rev-parse', 'HEAD')).trim();
|
||||
}
|
||||
|
||||
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,22 @@ test('Repository with commits shows increment', () => {
|
|||
repo.clean();
|
||||
});
|
||||
|
||||
test('Repository show commit for checked out commit', () => {
|
||||
const repo = createTestRepo({ branch: 'HEAD' }); // 0.0.0+0
|
||||
|
||||
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
||||
repo.makeCommit(`Second Commit`); // 0.0.1+1
|
||||
let result = repo.runAction();
|
||||
expect(result).toMatch('Version is 0.0.1+1');
|
||||
|
||||
repo.exec(`git checkout HEAD~1`); // 0.0.1+1
|
||||
result = repo.runAction();
|
||||
expect(result).toMatch('Version is 0.0.1+0');
|
||||
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
||||
test('Tagging does not break version', () => {
|
||||
const repo = createTestRepo(); // 0.0.0+0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue