Adding is_tagged to outputs

Sets a flag when the current commit that the action is being run on has a tag matching the version format
This commit is contained in:
Emil Kantis 2023-02-27 22:32:29 +01:00
parent 9e89a29a4a
commit e27fda7711
No known key found for this signature in database
GPG key ID: 5053C7ECBEC9A5E9
17 changed files with 85 additions and 29 deletions

View file

@ -13,6 +13,7 @@ export class VersionResult {
* @param formattedVersion - The formatted semantic version
* @param versionTag - The string to be used as a Git tag
* @param changed - True if the version was changed, otherwise false
* @param isTagged - True if the commit had a tag that matched the `versionTag` format
* @param authors - Authors formatted according to the format mode (e.g. JSON, CSV, YAML, etc.)
* @param currentCommit - The current commit hash
* @param previousCommit - The previous commit hash
@ -27,6 +28,7 @@ export class VersionResult {
public formattedVersion: string,
public versionTag: string,
public changed: boolean,
public isTagged: boolean,
public authors: string,
public currentCommit: string,
public previousCommit: string,

View file

@ -15,7 +15,7 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
const userFormatter = configurationProvider.GetUserFormatter();
if (await currentCommitResolver.IsEmptyRepoAsync()) {
const versionInfo = new VersionInformation(0, 0, 0, 0, VersionType.None, [], false);
const versionInfo = new VersionInformation(0, 0, 0, 0, VersionType.None, [], false, false);
return new VersionResult(
versionInfo.major,
versionInfo.minor,
@ -25,6 +25,7 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
versionFormatter.Format(versionInfo),
tagFormmater.Format(versionInfo),
versionInfo.changed,
versionInfo.isTagged,
userFormatter.Format('author', []),
'',
'',
@ -37,11 +38,12 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
const commitSet = await commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
const classification = await versionClassifier.ClassifyAsync(lastRelease, commitSet);
const { isTagged } = lastRelease;
const { major, minor, patch, increment, type, changed } = classification;
// At this point all necessary data has been pulled from the database, create
// version information to be used by the formatters
let versionInfo = new VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed);
let versionInfo = new VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed, isTagged);
// Group all the authors together, count the number of commits per author
const allAuthors = versionInfo.commits
@ -65,6 +67,7 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
versionFormatter.Format(versionInfo),
tagFormmater.Format(versionInfo),
versionInfo.changed,
versionInfo.isTagged,
userFormatter.Format('author', authors),
currentCommit,
lastRelease.hash,

View file

@ -866,4 +866,30 @@ test('Pre-release mode updates major version if major version is not 0', async (
repo.exec('git tag 2.0.0');
repo.makeCommit('Fifth Commit (MAJOR)');
expect(( await repo.runAction()).formattedVersion).toBe('3.0.0');
}, 15000);
test('Tagged commit is flagged as release', async () => {
const repo = createTestRepo({ tagPrefix: 'v', versionFormat: "${major}.${minor}.${patch}-prerelease.${increment}", enablePrereleaseMode: true });
repo.makeCommit('Initial Commit');
repo.exec('git tag v1.0.0');
var result = await repo.runAction();
expect(result.formattedVersion).toBe('1.0.0-prerelease.0');
expect(result.isTagged).toBe(true);
repo.makeCommit('Second Commit');
result = await repo.runAction();
expect(result.formattedVersion).toBe('1.0.1-prerelease.0')
expect(result.isTagged).toBe(false);
repo.makeCommit('Third Commit (MINOR)');
result = await repo.runAction();
expect(result.formattedVersion).toBe('1.1.0-prerelease.0');
expect(result.isTagged).toBe(false);
repo.makeCommit('Fourth Commit (MINOR)');
repo.exec('git tag v1.1.0')
result = await repo.runAction();
expect(result.formattedVersion).toBe('1.1.0-prerelease.1');
expect(result.isTagged).toBe(true);
}, 15000);

View file

@ -6,7 +6,7 @@ import * as core from '@actions/core';
import { VersionType } from './providers/VersionType';
function setOutput(versionResult: VersionResult) {
const { major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion } = versionResult;
const { major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, isTagged, authors, currentCommit, previousCommit, previousVersion } = versionResult;
const repository = process.env.GITHUB_REPOSITORY;
@ -26,6 +26,7 @@ function setOutput(versionResult: VersionResult) {
core.setOutput("increment", increment.toString());
core.setOutput("version_type", VersionType[versionType].toLowerCase());
core.setOutput("changed", changed.toString());
core.setOutput("is_tagged", isTagged.toString());
core.setOutput("version_tag", versionTag);
core.setOutput("authors", authors);
core.setOutput("previous_commit", previousCommit);

View file

@ -23,6 +23,7 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
)).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const isTagged = currentTag !== '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
@ -63,13 +64,13 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
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
return new ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch);
return new ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch, isTagged);
}
// parse the version tag
const [major, minor, patch] = tagFormatter.Parse(tag);
const root = await cmd('git', `merge-base`, tag, current);
return new ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch);
return new ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch, isTagged);
}
}

View file

@ -9,7 +9,7 @@ test('Regular expressions can be used as minor tag direct', async () => {
const classifier = new DefaultVersionClassifier({ ...new ActionConfig(), ...{ tagPrefix: '', minorPattern: '/S[a-z]+Value/' }});
const releaseInfo =new ReleaseInformation(0,0,1,"",null,null,null);
const releaseInfo =new ReleaseInformation(0,0,1,"",null,null,null,false);
const commitSet = new CommitInfoSet(false, [
new CommitInfo("", "Second Commit SomeValue", "", "","", new Date(), "", "", new Date(), []),
new CommitInfo("", "Initial Commit", "", "","", new Date(), "", "", new Date(), []),

View file

@ -9,6 +9,7 @@ export class ReleaseInformation {
* @param currentMajor - the major version number from the current commit
* @param currentMinor - the minor version number from the current commit
* @param currentPatch - the patch version number from the current commit
* @param isTagged - whether the current commit is tagged with a version
*/
constructor(
public major: number,
@ -17,5 +18,6 @@ export class ReleaseInformation {
public hash: string,
public currentMajor: number | null,
public currentMinor: number | null,
public currentPatch: number | null,) { }
public currentPatch: number | null,
public isTagged: boolean,) { }
}

View file

@ -15,6 +15,7 @@ export class VersionInformation {
* @param type - The type of change the current range represents
* @param commits - The list of commits for this version
* @param changed - True if the version has changed, false otherwise
* @param isTagged - True if the current commit is a version-tagged commit
*/
constructor(
public major: number,
@ -23,5 +24,6 @@ export class VersionInformation {
public increment: number,
public type: VersionType,
public commits: CommitInfo[],
public changed: boolean) { }
public changed: boolean,
public isTagged: boolean) { }
}