Merge pull request #94 from Kantis/master

Adding is_tagged to outputs
This commit is contained in:
Paul Hatcherian 2023-03-13 15:22:17 -10:00 committed by GitHub
commit 6a1b048e03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 98 additions and 39 deletions

29
dist/index.js vendored
View file

@ -133,12 +133,13 @@ class VersionResult {
* @param formattedVersion - The formatted semantic version * @param formattedVersion - The formatted semantic version
* @param versionTag - The string to be used as a Git tag * @param versionTag - The string to be used as a Git tag
* @param changed - True if the version was changed, otherwise false * @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 authors - Authors formatted according to the format mode (e.g. JSON, CSV, YAML, etc.)
* @param currentCommit - The current commit hash * @param currentCommit - The current commit hash
* @param previousCommit - The previous commit hash * @param previousCommit - The previous commit hash
* @param previousVersion - The previous version * @param previousVersion - The previous version
*/ */
constructor(major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion) { constructor(major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, isTagged, authors, currentCommit, previousCommit, previousVersion) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -147,6 +148,7 @@ class VersionResult {
this.formattedVersion = formattedVersion; this.formattedVersion = formattedVersion;
this.versionTag = versionTag; this.versionTag = versionTag;
this.changed = changed; this.changed = changed;
this.isTagged = isTagged;
this.authors = authors; this.authors = authors;
this.currentCommit = currentCommit; this.currentCommit = currentCommit;
this.previousCommit = previousCommit; this.previousCommit = previousCommit;
@ -188,17 +190,18 @@ function runAction(configurationProvider) {
const tagFormmater = configurationProvider.GetTagFormatter(); const tagFormmater = configurationProvider.GetTagFormatter();
const userFormatter = configurationProvider.GetUserFormatter(); const userFormatter = configurationProvider.GetUserFormatter();
if (yield currentCommitResolver.IsEmptyRepoAsync()) { if (yield currentCommitResolver.IsEmptyRepoAsync()) {
const versionInfo = new VersionInformation_1.VersionInformation(0, 0, 0, 0, VersionType_1.VersionType.None, [], false); const versionInfo = new VersionInformation_1.VersionInformation(0, 0, 0, 0, VersionType_1.VersionType.None, [], false, false);
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', []), '', '', '0.0.0'); return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format('author', []), '', '', '0.0.0');
} }
const currentCommit = yield currentCommitResolver.ResolveAsync(); const currentCommit = yield currentCommitResolver.ResolveAsync();
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater); const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater);
const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit); const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet); const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet);
const { isTagged } = lastRelease;
const { major, minor, patch, increment, type, changed } = classification; const { major, minor, patch, increment, type, changed } = classification;
// At this point all necessary data has been pulled from the database, create // At this point all necessary data has been pulled from the database, create
// version information to be used by the formatters // version information to be used by the formatters
let versionInfo = new VersionInformation_1.VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed); let versionInfo = new VersionInformation_1.VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed, isTagged);
// Group all the authors together, count the number of commits per author // Group all the authors together, count the number of commits per author
const allAuthors = versionInfo.commits const allAuthors = versionInfo.commits
.reduce((acc, commit) => { .reduce((acc, commit) => {
@ -210,7 +213,7 @@ function runAction(configurationProvider) {
const authors = Object.values(allAuthors) const authors = Object.values(allAuthors)
.map((u) => new UserInfo_1.UserInfo(u.n, u.e, u.c)) .map((u) => new UserInfo_1.UserInfo(u.n, u.e, u.c))
.sort((a, b) => b.commits - a.commits); .sort((a, b) => b.commits - a.commits);
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`); return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format('author', authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`);
}); });
} }
exports.runAction = runAction; exports.runAction = runAction;
@ -391,7 +394,7 @@ const ConfigurationProvider_1 = __nccwpck_require__(2614);
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const VersionType_1 = __nccwpck_require__(895); const VersionType_1 = __nccwpck_require__(895);
function setOutput(versionResult) { function setOutput(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; const repository = process.env.GITHUB_REPOSITORY;
if (!changed) { if (!changed) {
core.info('No changes detected for this commit'); core.info('No changes detected for this commit');
@ -407,6 +410,7 @@ function setOutput(versionResult) {
core.setOutput("increment", increment.toString()); core.setOutput("increment", increment.toString());
core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase()); core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase());
core.setOutput("changed", changed.toString()); core.setOutput("changed", changed.toString());
core.setOutput("is_tagged", isTagged.toString());
core.setOutput("version_tag", versionTag); core.setOutput("version_tag", versionTag);
core.setOutput("authors", authors); core.setOutput("authors", authors);
core.setOutput("previous_commit", previousCommit); core.setOutput("previous_commit", previousCommit);
@ -748,6 +752,7 @@ class DefaultLastReleaseResolver {
const releasePattern = tagFormatter.GetPattern(); const releasePattern = tagFormatter.GetPattern();
let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim(); let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : ''; currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const isTagged = currentTag !== '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null]; const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
let tag = ''; let tag = '';
try { try {
@ -782,12 +787,12 @@ class DefaultLastReleaseResolver {
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
return new ReleaseInformation_1.ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch); return new ReleaseInformation_1.ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch, isTagged);
} }
// parse the version tag // parse the version tag
const [major, minor, patch] = tagFormatter.Parse(tag); const [major, minor, patch] = tagFormatter.Parse(tag);
const root = yield (0, CommandRunner_1.cmd)('git', `merge-base`, tag, current); const root = yield (0, CommandRunner_1.cmd)('git', `merge-base`, tag, current);
return new ReleaseInformation_1.ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch); return new ReleaseInformation_1.ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch, isTagged);
}); });
} }
} }
@ -926,8 +931,9 @@ class ReleaseInformation {
* @param currentMajor - the major version number from the current commit * @param currentMajor - the major version number from the current commit
* @param currentMinor - the minor 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 currentPatch - the patch version number from the current commit
* @param isTagged - whether the current commit is tagged with a version
*/ */
constructor(major, minor, patch, hash, currentMajor, currentMinor, currentPatch) { constructor(major, minor, patch, hash, currentMajor, currentMinor, currentPatch, isTagged) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -935,6 +941,7 @@ class ReleaseInformation {
this.currentMajor = currentMajor; this.currentMajor = currentMajor;
this.currentMinor = currentMinor; this.currentMinor = currentMinor;
this.currentPatch = currentPatch; this.currentPatch = currentPatch;
this.isTagged = isTagged;
} }
} }
exports.ReleaseInformation = ReleaseInformation; exports.ReleaseInformation = ReleaseInformation;
@ -1021,8 +1028,9 @@ class VersionInformation {
* @param type - The type of change the current range represents * @param type - The type of change the current range represents
* @param commits - The list of commits for this version * @param commits - The list of commits for this version
* @param changed - True if the version has changed, false otherwise * @param changed - True if the version has changed, false otherwise
* @param isTagged - True if the current commit is a version-tagged commit
*/ */
constructor(major, minor, patch, increment, type, commits, changed) { constructor(major, minor, patch, increment, type, commits, changed, isTagged) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -1030,6 +1038,7 @@ class VersionInformation {
this.type = type; this.type = type;
this.commits = commits; this.commits = commits;
this.changed = changed; this.changed = changed;
this.isTagged = isTagged;
} }
} }
exports.VersionInformation = VersionInformation; exports.VersionInformation = VersionInformation;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -13,12 +13,13 @@ class VersionResult {
* @param formattedVersion - The formatted semantic version * @param formattedVersion - The formatted semantic version
* @param versionTag - The string to be used as a Git tag * @param versionTag - The string to be used as a Git tag
* @param changed - True if the version was changed, otherwise false * @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 authors - Authors formatted according to the format mode (e.g. JSON, CSV, YAML, etc.)
* @param currentCommit - The current commit hash * @param currentCommit - The current commit hash
* @param previousCommit - The previous commit hash * @param previousCommit - The previous commit hash
* @param previousVersion - The previous version * @param previousVersion - The previous version
*/ */
constructor(major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion) { constructor(major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, isTagged, authors, currentCommit, previousCommit, previousVersion) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -27,6 +28,7 @@ class VersionResult {
this.formattedVersion = formattedVersion; this.formattedVersion = formattedVersion;
this.versionTag = versionTag; this.versionTag = versionTag;
this.changed = changed; this.changed = changed;
this.isTagged = isTagged;
this.authors = authors; this.authors = authors;
this.currentCommit = currentCommit; this.currentCommit = currentCommit;
this.previousCommit = previousCommit; this.previousCommit = previousCommit;

View file

@ -24,17 +24,18 @@ function runAction(configurationProvider) {
const tagFormmater = configurationProvider.GetTagFormatter(); const tagFormmater = configurationProvider.GetTagFormatter();
const userFormatter = configurationProvider.GetUserFormatter(); const userFormatter = configurationProvider.GetUserFormatter();
if (yield currentCommitResolver.IsEmptyRepoAsync()) { if (yield currentCommitResolver.IsEmptyRepoAsync()) {
const versionInfo = new VersionInformation_1.VersionInformation(0, 0, 0, 0, VersionType_1.VersionType.None, [], false); const versionInfo = new VersionInformation_1.VersionInformation(0, 0, 0, 0, VersionType_1.VersionType.None, [], false, false);
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', []), '', '', '0.0.0'); return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format('author', []), '', '', '0.0.0');
} }
const currentCommit = yield currentCommitResolver.ResolveAsync(); const currentCommit = yield currentCommitResolver.ResolveAsync();
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater); const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater);
const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit); const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet); const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet);
const { isTagged } = lastRelease;
const { major, minor, patch, increment, type, changed } = classification; const { major, minor, patch, increment, type, changed } = classification;
// At this point all necessary data has been pulled from the database, create // At this point all necessary data has been pulled from the database, create
// version information to be used by the formatters // version information to be used by the formatters
let versionInfo = new VersionInformation_1.VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed); let versionInfo = new VersionInformation_1.VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed, isTagged);
// Group all the authors together, count the number of commits per author // Group all the authors together, count the number of commits per author
const allAuthors = versionInfo.commits const allAuthors = versionInfo.commits
.reduce((acc, commit) => { .reduce((acc, commit) => {
@ -46,7 +47,7 @@ function runAction(configurationProvider) {
const authors = Object.values(allAuthors) const authors = Object.values(allAuthors)
.map((u) => new UserInfo_1.UserInfo(u.n, u.e, u.c)) .map((u) => new UserInfo_1.UserInfo(u.n, u.e, u.c))
.sort((a, b) => b.commits - a.commits); .sort((a, b) => b.commits - a.commits);
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`); return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format('author', authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`);
}); });
} }
exports.runAction = runAction; exports.runAction = runAction;

View file

@ -38,7 +38,7 @@ const ConfigurationProvider_1 = require("./ConfigurationProvider");
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const VersionType_1 = require("./providers/VersionType"); const VersionType_1 = require("./providers/VersionType");
function setOutput(versionResult) { function setOutput(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; const repository = process.env.GITHUB_REPOSITORY;
if (!changed) { if (!changed) {
core.info('No changes detected for this commit'); core.info('No changes detected for this commit');
@ -54,6 +54,7 @@ function setOutput(versionResult) {
core.setOutput("increment", increment.toString()); core.setOutput("increment", increment.toString());
core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase()); core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase());
core.setOutput("changed", changed.toString()); core.setOutput("changed", changed.toString());
core.setOutput("is_tagged", isTagged.toString());
core.setOutput("version_tag", versionTag); core.setOutput("version_tag", versionTag);
core.setOutput("authors", authors); core.setOutput("authors", authors);
core.setOutput("previous_commit", previousCommit); core.setOutput("previous_commit", previousCommit);

View file

@ -46,6 +46,7 @@ class DefaultLastReleaseResolver {
const releasePattern = tagFormatter.GetPattern(); const releasePattern = tagFormatter.GetPattern();
let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim(); let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : ''; currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const isTagged = currentTag !== '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null]; const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
let tag = ''; let tag = '';
try { try {
@ -80,12 +81,12 @@ class DefaultLastReleaseResolver {
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
return new ReleaseInformation_1.ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch); return new ReleaseInformation_1.ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch, isTagged);
} }
// parse the version tag // parse the version tag
const [major, minor, patch] = tagFormatter.Parse(tag); const [major, minor, patch] = tagFormatter.Parse(tag);
const root = yield (0, CommandRunner_1.cmd)('git', `merge-base`, tag, current); const root = yield (0, CommandRunner_1.cmd)('git', `merge-base`, tag, current);
return new ReleaseInformation_1.ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch); return new ReleaseInformation_1.ReleaseInformation(major, minor, patch, root.trim(), currentMajor, currentMinor, currentPatch, isTagged);
}); });
} }
} }

View file

@ -12,8 +12,9 @@ class ReleaseInformation {
* @param currentMajor - the major version number from the current commit * @param currentMajor - the major version number from the current commit
* @param currentMinor - the minor 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 currentPatch - the patch version number from the current commit
* @param isTagged - whether the current commit is tagged with a version
*/ */
constructor(major, minor, patch, hash, currentMajor, currentMinor, currentPatch) { constructor(major, minor, patch, hash, currentMajor, currentMinor, currentPatch, isTagged) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -21,6 +22,7 @@ class ReleaseInformation {
this.currentMajor = currentMajor; this.currentMajor = currentMajor;
this.currentMinor = currentMinor; this.currentMinor = currentMinor;
this.currentPatch = currentPatch; this.currentPatch = currentPatch;
this.isTagged = isTagged;
} }
} }
exports.ReleaseInformation = ReleaseInformation; exports.ReleaseInformation = ReleaseInformation;

View file

@ -15,8 +15,9 @@ class VersionInformation {
* @param type - The type of change the current range represents * @param type - The type of change the current range represents
* @param commits - The list of commits for this version * @param commits - The list of commits for this version
* @param changed - True if the version has changed, false otherwise * @param changed - True if the version has changed, false otherwise
* @param isTagged - True if the current commit is a version-tagged commit
*/ */
constructor(major, minor, patch, increment, type, commits, changed) { constructor(major, minor, patch, increment, type, commits, changed, isTagged) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
@ -24,6 +25,7 @@ class VersionInformation {
this.type = type; this.type = type;
this.commits = commits; this.commits = commits;
this.changed = changed; this.changed = changed;
this.isTagged = isTagged;
} }
} }
exports.VersionInformation = VersionInformation; exports.VersionInformation = VersionInformation;

View file

@ -114,6 +114,7 @@ it will be given the new version if the build were to be retriggered, for exampl
- *version* is a formatted version string created using the format input. This is a convenience value to provide a preformatted representation of the data generated by this action. - *version* is a formatted version string created using the format input. This is a convenience value to provide a preformatted representation of the data generated by this action.
- *version_tag* is a string identifier that would be used to tag the current commit as the "released" version. Typically this would only be used to generate a Git tag name. - *version_tag* is a string identifier that would be used to tag the current commit as the "released" version. Typically this would only be used to generate a Git tag name.
- *changed* indicates whether there was a change since the last version if change_path was specified. If no `change_path` was specified this value will always be true since the entire repo is considered. (It is possible to create a commit with no changes, but the Git cli rejects this by default and this case is not considered here) - *changed* indicates whether there was a change since the last version if change_path was specified. If no `change_path` was specified this value will always be true since the entire repo is considered. (It is possible to create a commit with no changes, but the Git cli rejects this by default and this case is not considered here)
- *is_tagged* indicates whether the current commit has a tag matching `tag_prefix`
- *authors* is a list of authors that have committed to this version, formatted as either csv or json. - *authors* is a list of authors that have committed to this version, formatted as either csv or json.
- *current_commit* is the current commit hash. - *current_commit* is the current commit hash.
- *previous_commit* is the previous commit hash. - *previous_commit* is the previous commit hash.

View file

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

View file

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

View file

@ -33,7 +33,10 @@ const createTestRepo = (repoDefaultConfig?: Partial<ActionConfig>) => {
run(`touch ${path !== '' ? path.trim() + '/' : ''}test${i++}`); run(`touch ${path !== '' ? path.trim() + '/' : ''}test${i++}`);
} }
run(`git add --all`); run(`git add --all`);
run(`git commit -m "${msg}"`); run(`git -c commit.gpgsign=false commit -m "${msg}"`);
},
merge: (branch: string) => {
run(`git -c commit.gpgsign=false merge ${branch}`);
}, },
runAction: async (inputs?: Partial<ActionConfig>) => { runAction: async (inputs?: Partial<ActionConfig>) => {
let config = new ActionConfig(); let config = new ActionConfig();
@ -229,7 +232,7 @@ test('Merged tags do not affect version', async () => {
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.makeCommit('Fifth Commit'); // 0.0.2.0 repo.makeCommit('Fifth Commit'); // 0.0.2.0
repo.exec('git tag v0.0.2'); repo.exec('git tag v0.0.2');
repo.exec('git merge release/0.0.1'); repo.merge('release/0.0.1');
const result = await repo.runAction(); const result = await repo.runAction();
expect(result.formattedVersion).toBe('0.0.3+1'); expect(result.formattedVersion).toBe('0.0.3+1');
@ -524,7 +527,7 @@ test('Tags immediately before merge are detected', async () => {
repo.exec('git tag v2.0.0'); repo.exec('git tag v2.0.0');
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.makeCommit('Commit 5'); repo.makeCommit('Commit 5');
repo.exec('git merge feature/branch'); repo.merge('feature/branch');
const result = await repo.runAction(); const result = await repo.runAction();
expect(result.versionTag).toBe('v2.0.1'); expect(result.versionTag).toBe('v2.0.1');
@ -543,7 +546,7 @@ test('Correct tag is detected on merged branches', async () => {
repo.makeCommit('Commit 4'); repo.makeCommit('Commit 4');
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.makeCommit('Commit 5'); repo.makeCommit('Commit 5');
repo.exec('git merge feature/branch'); repo.merge('feature/branch');
const result = await repo.runAction(); const result = await repo.runAction();
expect(result.versionTag).toBe('v2.0.1'); expect(result.versionTag).toBe('v2.0.1');
@ -558,14 +561,14 @@ test('Correct tag is detected on multiple branches', async () => {
repo.exec('git tag v1.0.0'); repo.exec('git tag v1.0.0');
repo.makeCommit('Commit 2'); repo.makeCommit('Commit 2');
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.exec('git merge feature/branch1'); repo.merge('feature/branch1');
repo.exec('git checkout -b feature/branch2'); repo.exec('git checkout -b feature/branch2');
repo.makeCommit('Commit 3'); repo.makeCommit('Commit 3');
repo.exec('git tag v2.0.0'); repo.exec('git tag v2.0.0');
repo.makeCommit('Commit 4'); repo.makeCommit('Commit 4');
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.makeCommit('Commit 5'); repo.makeCommit('Commit 5');
repo.exec('git merge feature/branch2'); repo.merge('feature/branch2');
const result = await repo.runAction(); const result = await repo.runAction();
expect(result.versionTag).toBe('v2.0.1'); expect(result.versionTag).toBe('v2.0.1');
@ -580,14 +583,14 @@ test('Correct tag is detected when versions pass 10s place', async () => {
repo.exec('git tag v10.15.0'); repo.exec('git tag v10.15.0');
repo.makeCommit('Commit 2'); repo.makeCommit('Commit 2');
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.exec('git merge feature/branch1'); repo.merge('feature/branch1');
repo.exec('git checkout -b feature/branch2'); repo.exec('git checkout -b feature/branch2');
repo.makeCommit('Commit 3'); repo.makeCommit('Commit 3');
repo.exec('git tag v10.7.0'); repo.exec('git tag v10.7.0');
repo.makeCommit('Commit 4'); repo.makeCommit('Commit 4');
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.makeCommit('Commit 5'); repo.makeCommit('Commit 5');
repo.exec('git merge feature/branch2'); repo.merge('feature/branch2');
const result = await repo.runAction(); const result = await repo.runAction();
expect(result.versionTag).toBe('v10.15.1'); expect(result.versionTag).toBe('v10.15.1');
@ -619,7 +622,7 @@ test('Can use branches instead of tags', async () => {
repo.exec('git checkout -b release/1.0.0'); repo.exec('git checkout -b release/1.0.0');
repo.makeCommit('Commit 2'); repo.makeCommit('Commit 2');
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.exec('git merge release/1.0.0'); repo.merge('release/1.0.0');
repo.makeCommit('Commit 3'); repo.makeCommit('Commit 3');
const result = await repo.runAction(); const result = await repo.runAction();
@ -646,7 +649,7 @@ test('Correct previous version is returned when using branches', async () => {
repo.exec('git checkout -b release/2.0.1'); repo.exec('git checkout -b release/2.0.1');
repo.makeCommit(`Second Commit`); repo.makeCommit(`Second Commit`);
repo.exec('git checkout master'); repo.exec('git checkout master');
repo.exec('git merge release/2.0.1'); repo.merge('release/2.0.1');
repo.makeCommit(`Third Commit`); repo.makeCommit(`Third Commit`);
const result = await repo.runAction(); const result = await repo.runAction();
@ -866,4 +869,30 @@ test('Pre-release mode updates major version if major version is not 0', async (
repo.exec('git tag 2.0.0'); repo.exec('git tag 2.0.0');
repo.makeCommit('Fifth Commit (MAJOR)'); repo.makeCommit('Fifth Commit (MAJOR)');
expect(( await repo.runAction()).formattedVersion).toBe('3.0.0'); 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); }, 15000);

View file

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

View file

@ -23,6 +23,7 @@ export class DefaultLastReleaseResolver implements LastReleaseResolver {
)).trim(); )).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : ''; currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const isTagged = currentTag !== '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null]; 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.'); 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
return new ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch); return new ReleaseInformation(0, 0, 0, '', currentMajor, currentMinor, currentPatch, isTagged);
} }
// parse the version tag // parse the version tag
const [major, minor, patch] = tagFormatter.Parse(tag); const [major, minor, patch] = tagFormatter.Parse(tag);
const root = await cmd('git', `merge-base`, tag, current); 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 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, [ const commitSet = new CommitInfoSet(false, [
new CommitInfo("", "Second Commit SomeValue", "", "","", new Date(), "", "", new Date(), []), new CommitInfo("", "Second Commit SomeValue", "", "","", new Date(), "", "", new Date(), []),
new CommitInfo("", "Initial Commit", "", "","", 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 currentMajor - the major version number from the current commit
* @param currentMinor - the minor 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 currentPatch - the patch version number from the current commit
* @param isTagged - whether the current commit is tagged with a version
*/ */
constructor( constructor(
public major: number, public major: number,
@ -17,5 +18,6 @@ export class ReleaseInformation {
public hash: string, public hash: string,
public currentMajor: number | null, public currentMajor: number | null,
public currentMinor: 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 type - The type of change the current range represents
* @param commits - The list of commits for this version * @param commits - The list of commits for this version
* @param changed - True if the version has changed, false otherwise * @param changed - True if the version has changed, false otherwise
* @param isTagged - True if the current commit is a version-tagged commit
*/ */
constructor( constructor(
public major: number, public major: number,
@ -23,5 +24,6 @@ export class VersionInformation {
public increment: number, public increment: number,
public type: VersionType, public type: VersionType,
public commits: CommitInfo[], public commits: CommitInfo[],
public changed: boolean) { } public changed: boolean,
public isTagged: boolean) { }
} }