mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 13:08:17 +00:00
Merge pull request #21 from PaulHatch/feature/HeadRef
Support and default to HEAD ref for branch (MAJOR)
This commit is contained in:
commit
1afa8eb537
4 changed files with 35 additions and 15 deletions
|
|
@ -5,9 +5,9 @@ branding:
|
||||||
color: "blue"
|
color: "blue"
|
||||||
inputs:
|
inputs:
|
||||||
branch:
|
branch:
|
||||||
description: "The branch name"
|
description: "Set to specify a specific branch, default is the current HEAD"
|
||||||
required: true
|
required: true
|
||||||
default: "master"
|
default: "HEAD"
|
||||||
tag_prefix:
|
tag_prefix:
|
||||||
description: "The prefix to use to identify tags"
|
description: "The prefix to use to identify tags"
|
||||||
required: false
|
required: false
|
||||||
|
|
|
||||||
16
dist/index.js
vendored
16
dist/index.js
vendored
|
|
@ -1072,6 +1072,10 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
|
||||||
tag = `${tagPrefix}${major}`;
|
tag = `${tagPrefix}${major}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (namespace !== '') {
|
||||||
|
tag += `-${namespace}`
|
||||||
|
}
|
||||||
|
|
||||||
const repository = process.env.GITHUB_REPOSITORY;
|
const repository = process.env.GITHUB_REPOSITORY;
|
||||||
|
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
|
|
@ -1126,15 +1130,15 @@ const createMatchTest = (pattern) => {
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const remote = await cmd('git', 'remote');
|
let branch = core.getInput('branch', { required: true });
|
||||||
const remoteExists = remote !== '';
|
|
||||||
const remotePrefix = remoteExists ? 'origin/' : '';
|
|
||||||
|
|
||||||
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
|
||||||
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
||||||
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
||||||
const changePath = core.getInput('change_path') || '';
|
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 versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||||
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
||||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||||
|
|
@ -1169,7 +1173,7 @@ async function run() {
|
||||||
|
|
||||||
let root;
|
let root;
|
||||||
if (tag === '') {
|
if (tag === '') {
|
||||||
if (remoteExists) {
|
if (await cmd('git', 'remote') !== '') {
|
||||||
core.warning('No tags are present for this repository. If this is unexpected, check to ensure that tags have been pulled from the remote.');
|
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
|
||||||
|
|
|
||||||
12
index.js
12
index.js
|
|
@ -109,15 +109,15 @@ const createMatchTest = (pattern) => {
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const remote = await cmd('git', 'remote');
|
let branch = core.getInput('branch', { required: true });
|
||||||
const remoteExists = remote !== '';
|
|
||||||
const remotePrefix = remoteExists ? 'origin/' : '';
|
|
||||||
|
|
||||||
const branch = `${remotePrefix}${core.getInput('branch', { required: true })}`;
|
|
||||||
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
const majorPattern = createMatchTest(core.getInput('major_pattern', { required: true }));
|
||||||
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
const minorPattern = createMatchTest(core.getInput('minor_pattern', { required: true }));
|
||||||
const changePath = core.getInput('change_path') || '';
|
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 versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||||
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
||||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||||
|
|
@ -152,7 +152,7 @@ async function run() {
|
||||||
|
|
||||||
let root;
|
let root;
|
||||||
if (tag === '') {
|
if (tag === '') {
|
||||||
if (remoteExists) {
|
if (await cmd('git', 'remote') !== '') {
|
||||||
core.warning('No tags are present for this repository. If this is unexpected, check to ensure that tags have been pulled from the remote.');
|
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
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const windows = process.platform === "win32";
|
||||||
|
|
||||||
// Action input variables
|
// Action input variables
|
||||||
const defaultInputs = {
|
const defaultInputs = {
|
||||||
branch: "master",
|
branch: "HEAD",
|
||||||
tag_prefix: "v",
|
tag_prefix: "v",
|
||||||
major_pattern: "(MAJOR)",
|
major_pattern: "(MAJOR)",
|
||||||
minor_pattern: "(MINOR)",
|
minor_pattern: "(MINOR)",
|
||||||
|
|
@ -85,6 +85,22 @@ test('Repository with commits shows increment', () => {
|
||||||
repo.clean();
|
repo.clean();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Repository show commit for checked out commit', () => {
|
||||||
|
const repo = createTestRepo(); // 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', () => {
|
test('Tagging does not break version', () => {
|
||||||
const repo = createTestRepo(); // 0.0.0+0
|
const repo = createTestRepo(); // 0.0.0+0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue