Add version type as output

This commit is contained in:
Paul Hatcherian 2022-10-02 17:17:28 -04:00
parent b505a7cf06
commit e1e99bd214
13 changed files with 51 additions and 33 deletions

View file

@ -63,6 +63,8 @@ outputs:
description: "Current patch number" description: "Current patch number"
increment: increment:
description: "An additional value indicating the number of commits for the current version" description: "An additional value indicating the number of commits for the current version"
version_type:
description: "Indicates the type of change this version represents vs the previous, e.g. 'major', 'minor', 'patch', or 'none'"
version: version:
description: "The version result, in the format {major}.{minor}.{patch}" description: "The version result, in the format {major}.{minor}.{patch}"
version_tag: version_tag:

34
dist/index.js vendored
View file

@ -129,6 +129,7 @@ class VersionResult {
* @param minor - The minor version number * @param minor - The minor version number
* @param patch - The patch version number * @param patch - The patch version number
* @param increment - The number of commits for this version (usually used to create version suffix) * @param increment - The number of commits for this version (usually used to create version suffix)
* @param versionType - The type of version, e.g. major, minor, patch
* @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
@ -137,11 +138,12 @@ class VersionResult {
* @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, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion) { constructor(major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
this.increment = increment; this.increment = increment;
this.versionType = versionType;
this.formattedVersion = formattedVersion; this.formattedVersion = formattedVersion;
this.versionTag = versionTag; this.versionTag = versionTag;
this.changed = changed; this.changed = changed;
@ -186,8 +188,8 @@ 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()) {
let 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);
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, 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, 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);
@ -208,7 +210,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, 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, userFormatter.Format('author', authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`);
}); });
} }
exports.runAction = runAction; exports.runAction = runAction;
@ -377,8 +379,9 @@ exports.run = void 0;
const action_1 = __nccwpck_require__(9139); const action_1 = __nccwpck_require__(9139);
const ConfigurationProvider_1 = __nccwpck_require__(2614); const ConfigurationProvider_1 = __nccwpck_require__(2614);
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const VersionType_1 = __nccwpck_require__(895);
function setOutput(versionResult) { function setOutput(versionResult) {
const { major, minor, patch, increment, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion } = versionResult; const { major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, 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');
@ -392,6 +395,7 @@ function setOutput(versionResult) {
core.setOutput("minor", minor.toString()); core.setOutput("minor", minor.toString());
core.setOutput("patch", patch.toString()); core.setOutput("patch", patch.toString());
core.setOutput("increment", increment.toString()); core.setOutput("increment", increment.toString());
core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase());
core.setOutput("changed", changed.toString()); core.setOutput("changed", changed.toString());
core.setOutput("version_tag", versionTag); core.setOutput("version_tag", versionTag);
core.setOutput("authors", authors); core.setOutput("authors", authors);
@ -407,8 +411,8 @@ function run() {
useBranches: core.getInput('use_branches') === 'true', useBranches: core.getInput('use_branches') === 'true',
majorPattern: core.getInput('major_pattern'), majorPattern: core.getInput('major_pattern'),
minorPattern: core.getInput('minor_pattern'), minorPattern: core.getInput('minor_pattern'),
majorFlags: core.getInput('major_flags'), majorFlags: core.getInput('major_regexp_flags'),
minorFlags: core.getInput('minor_flags'), minorFlags: core.getInput('minor_regexp_flags'),
versionFormat: core.getInput('version_format'), versionFormat: core.getInput('version_format'),
changePath: core.getInput('change_path'), changePath: core.getInput('change_path'),
namespace: core.getInput('namespace'), namespace: core.getInput('namespace'),
@ -795,12 +799,12 @@ const VersionType_1 = __nccwpck_require__(895);
class DefaultVersionClassifier { class DefaultVersionClassifier {
constructor(config) { constructor(config) {
const searchBody = config.searchCommitBody; const searchBody = config.searchCommitBody;
this.majorPattern = this.parsePattern(config.majorPattern, searchBody); this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
this.minorPattern = this.parsePattern(config.minorPattern, searchBody); this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
} }
parsePattern(pattern, searchBody) { parsePattern(pattern, flags, searchBody) {
if (pattern.startsWith('/') && pattern.endsWith('/')) { if (pattern.startsWith('/') && pattern.endsWith('/')) {
var regex = new RegExp(pattern.slice(1, -1)); var regex = new RegExp(pattern.slice(1, -1), flags);
return searchBody ? return searchBody ?
(commit) => regex.test(commit.subject) || regex.test(commit.body) : (commit) => regex.test(commit.subject) || regex.test(commit.body) :
(commit) => regex.test(commit.subject); (commit) => regex.test(commit.subject);
@ -1012,13 +1016,13 @@ exports.VersionType = void 0;
var VersionType; var VersionType;
(function (VersionType) { (function (VersionType) {
/** Indicates a major version change */ /** Indicates a major version change */
VersionType[VersionType["Major"] = 0] = "Major"; VersionType["Major"] = "Major";
/** Indicates a minor version change */ /** Indicates a minor version change */
VersionType[VersionType["Minor"] = 1] = "Minor"; VersionType["Minor"] = "Minor";
/** Indicates a patch version change */ /** Indicates a patch version change */
VersionType[VersionType["Patch"] = 2] = "Patch"; VersionType["Patch"] = "Patch";
/** Indicates no change--generally this means that the current commit is already tagged with a version */ /** Indicates no change--generally this means that the current commit is already tagged with a version */
VersionType[VersionType["None"] = 3] = "None"; VersionType["None"] = "None";
})(VersionType = exports.VersionType || (exports.VersionType = {})); })(VersionType = exports.VersionType || (exports.VersionType = {}));

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -13,11 +13,11 @@ class ActionConfig {
/** A string which, if present in a git commit, indicates that a change represents a major (breaking) change. Wrap with '/' to match using a regular expression. */ /** A string which, if present in a git commit, indicates that a change represents a major (breaking) change. Wrap with '/' to match using a regular expression. */
this.majorPattern = "(MAJOR)"; this.majorPattern = "(MAJOR)";
/** A string which indicates the flags used by the `majorPattern` regular expression. */ /** A string which indicates the flags used by the `majorPattern` regular expression. */
this.majorFlags = "(MAJOR)"; this.majorFlags = "";
/** A string which, if present in a git commit, indicates that a change represents a minor (feature) change. Wrap with '/' to match using a regular expression. */ /** A string which, if present in a git commit, indicates that a change represents a minor (feature) change. Wrap with '/' to match using a regular expression. */
this.minorPattern = "(MINOR)"; this.minorPattern = "(MINOR)";
/** A string which indicates the flags used by the `minorPattern` regular expression. */ /** A string which indicates the flags used by the `minorPattern` regular expression. */
this.minorFlags = "(MINOR)"; this.minorFlags = "";
/** Pattern to use when formatting output version */ /** Pattern to use when formatting output version */
this.versionFormat = '${major}.${minor}.${patch}'; this.versionFormat = '${major}.${minor}.${patch}';
/** Path to check for changes. If any changes are detected in the path the 'changed' output will true. Enter multiple paths separated by spaces. */ /** Path to check for changes. If any changes are detected in the path the 'changed' output will true. Enter multiple paths separated by spaces. */

View file

@ -9,6 +9,7 @@ class VersionResult {
* @param minor - The minor version number * @param minor - The minor version number
* @param patch - The patch version number * @param patch - The patch version number
* @param increment - The number of commits for this version (usually used to create version suffix) * @param increment - The number of commits for this version (usually used to create version suffix)
* @param versionType - The type of version, e.g. major, minor, patch
* @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
@ -17,11 +18,12 @@ class VersionResult {
* @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, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion) { constructor(major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion) {
this.major = major; this.major = major;
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
this.increment = increment; this.increment = increment;
this.versionType = versionType;
this.formattedVersion = formattedVersion; this.formattedVersion = formattedVersion;
this.versionTag = versionTag; this.versionTag = versionTag;
this.changed = changed; this.changed = changed;

View file

@ -24,8 +24,8 @@ 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()) {
let 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);
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, 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, 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);
@ -46,7 +46,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, 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, userFormatter.Format('author', authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`);
}); });
} }
exports.runAction = runAction; exports.runAction = runAction;

View file

@ -36,8 +36,9 @@ exports.run = void 0;
const action_1 = require("./action"); const action_1 = require("./action");
const ConfigurationProvider_1 = require("./ConfigurationProvider"); const ConfigurationProvider_1 = require("./ConfigurationProvider");
const core = __importStar(require("@actions/core")); const core = __importStar(require("@actions/core"));
const VersionType_1 = require("./providers/VersionType");
function setOutput(versionResult) { function setOutput(versionResult) {
const { major, minor, patch, increment, formattedVersion, versionTag, changed, authors, currentCommit, previousCommit, previousVersion } = versionResult; const { major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, 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');
@ -51,6 +52,7 @@ function setOutput(versionResult) {
core.setOutput("minor", minor.toString()); core.setOutput("minor", minor.toString());
core.setOutput("patch", patch.toString()); core.setOutput("patch", patch.toString());
core.setOutput("increment", increment.toString()); core.setOutput("increment", increment.toString());
core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase());
core.setOutput("changed", changed.toString()); core.setOutput("changed", changed.toString());
core.setOutput("version_tag", versionTag); core.setOutput("version_tag", versionTag);
core.setOutput("authors", authors); core.setOutput("authors", authors);

View file

@ -5,11 +5,11 @@ exports.VersionType = void 0;
var VersionType; var VersionType;
(function (VersionType) { (function (VersionType) {
/** Indicates a major version change */ /** Indicates a major version change */
VersionType[VersionType["Major"] = 0] = "Major"; VersionType["Major"] = "Major";
/** Indicates a minor version change */ /** Indicates a minor version change */
VersionType[VersionType["Minor"] = 1] = "Minor"; VersionType["Minor"] = "Minor";
/** Indicates a patch version change */ /** Indicates a patch version change */
VersionType[VersionType["Patch"] = 2] = "Patch"; VersionType["Patch"] = "Patch";
/** Indicates no change--generally this means that the current commit is already tagged with a version */ /** Indicates no change--generally this means that the current commit is already tagged with a version */
VersionType[VersionType["None"] = 3] = "None"; VersionType["None"] = "None";
})(VersionType = exports.VersionType || (exports.VersionType = {})); })(VersionType = exports.VersionType || (exports.VersionType = {}));

View file

@ -111,6 +111,7 @@ it will be given the new version if the build were to be retriggered, for exampl
- *major*, *minor*, and *patch* provide the version numbers that have been determined for this commit - *major*, *minor*, and *patch* provide the version numbers that have been determined for this commit
- *increment* is an additional value indicating the number of commits for the current version, starting at zero. This can be used as part of a pre-release label. - *increment* is an additional value indicating the number of commits for the current version, starting at zero. This can be used as part of a pre-release label.
- *version_type* is the type of version change the new version represents, e.g. `major`, `minor`, `patch`, or `none`.
- *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)

View file

@ -1,4 +1,5 @@
import { UserInfo } from "./providers/UserInfo"; import { UserInfo } from "./providers/UserInfo";
import { VersionType } from "./providers/VersionType";
/** Represents the total output for the action */ /** Represents the total output for the action */
export class VersionResult { export class VersionResult {
@ -8,6 +9,7 @@ export class VersionResult {
* @param minor - The minor version number * @param minor - The minor version number
* @param patch - The patch version number * @param patch - The patch version number
* @param increment - The number of commits for this version (usually used to create version suffix) * @param increment - The number of commits for this version (usually used to create version suffix)
* @param versionType - The type of version, e.g. major, minor, patch
* @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
@ -21,6 +23,7 @@ export class VersionResult {
public minor: number, public minor: number,
public patch: number, public patch: number,
public increment: number, public increment: number,
public versionType: VersionType,
public formattedVersion: string, public formattedVersion: string,
public versionTag: string, public versionTag: string,
public changed: boolean, public changed: boolean,

View file

@ -15,12 +15,13 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
const userFormatter = configurationProvider.GetUserFormatter(); const userFormatter = configurationProvider.GetUserFormatter();
if (await currentCommitResolver.IsEmptyRepoAsync()) { if (await currentCommitResolver.IsEmptyRepoAsync()) {
let versionInfo = new VersionInformation(0, 0, 0, 0, VersionType.None, [], false); const versionInfo = new VersionInformation(0, 0, 0, 0, VersionType.None, [], false);
return new VersionResult( return new VersionResult(
versionInfo.major, versionInfo.major,
versionInfo.minor, versionInfo.minor,
versionInfo.patch, versionInfo.patch,
versionInfo.increment, versionInfo.increment,
versionInfo.type,
versionFormatter.Format(versionInfo), versionFormatter.Format(versionInfo),
tagFormmater.Format(versionInfo), tagFormmater.Format(versionInfo),
versionInfo.changed, versionInfo.changed,
@ -60,6 +61,7 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
versionInfo.minor, versionInfo.minor,
versionInfo.patch, versionInfo.patch,
versionInfo.increment, versionInfo.increment,
versionInfo.type,
versionFormatter.Format(versionInfo), versionFormatter.Format(versionInfo),
tagFormmater.Format(versionInfo), tagFormmater.Format(versionInfo),
versionInfo.changed, versionInfo.changed,

View file

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

View file

@ -2,11 +2,11 @@
/** Indicates the type of change a particular version change represents */ /** Indicates the type of change a particular version change represents */
export enum VersionType { export enum VersionType {
/** Indicates a major version change */ /** Indicates a major version change */
Major, Major = 'Major',
/** Indicates a minor version change */ /** Indicates a minor version change */
Minor, Minor = 'Minor',
/** Indicates a patch version change */ /** Indicates a patch version change */
Patch, Patch = 'Patch',
/** Indicates no change--generally this means that the current commit is already tagged with a version */ /** Indicates no change--generally this means that the current commit is already tagged with a version */
None None = 'None'
} }