mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 13:08:17 +00:00
Add version type as output
This commit is contained in:
parent
b505a7cf06
commit
e1e99bd214
13 changed files with 51 additions and 33 deletions
|
|
@ -63,6 +63,8 @@ outputs:
|
|||
description: "Current patch number"
|
||||
increment:
|
||||
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:
|
||||
description: "The version result, in the format {major}.{minor}.{patch}"
|
||||
version_tag:
|
||||
|
|
|
|||
34
dist/index.js
vendored
34
dist/index.js
vendored
|
|
@ -129,6 +129,7 @@ class VersionResult {
|
|||
* @param minor - The minor version number
|
||||
* @param patch - The patch version number
|
||||
* @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 versionTag - The string to be used as a Git tag
|
||||
* @param changed - True if the version was changed, otherwise false
|
||||
|
|
@ -137,11 +138,12 @@ class VersionResult {
|
|||
* @param previousCommit - The previous commit hash
|
||||
* @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.minor = minor;
|
||||
this.patch = patch;
|
||||
this.increment = increment;
|
||||
this.versionType = versionType;
|
||||
this.formattedVersion = formattedVersion;
|
||||
this.versionTag = versionTag;
|
||||
this.changed = changed;
|
||||
|
|
@ -186,8 +188,8 @@ function runAction(configurationProvider) {
|
|||
const tagFormmater = configurationProvider.GetTagFormatter();
|
||||
const userFormatter = configurationProvider.GetUserFormatter();
|
||||
if (yield currentCommitResolver.IsEmptyRepoAsync()) {
|
||||
let 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');
|
||||
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, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', []), '', '', '0.0.0');
|
||||
}
|
||||
const currentCommit = yield currentCommitResolver.ResolveAsync();
|
||||
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater);
|
||||
|
|
@ -208,7 +210,7 @@ function runAction(configurationProvider) {
|
|||
const authors = Object.values(allAuthors)
|
||||
.map((u) => new UserInfo_1.UserInfo(u.n, u.e, u.c))
|
||||
.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;
|
||||
|
|
@ -377,8 +379,9 @@ exports.run = void 0;
|
|||
const action_1 = __nccwpck_require__(9139);
|
||||
const ConfigurationProvider_1 = __nccwpck_require__(2614);
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const VersionType_1 = __nccwpck_require__(895);
|
||||
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;
|
||||
if (!changed) {
|
||||
core.info('No changes detected for this commit');
|
||||
|
|
@ -392,6 +395,7 @@ function setOutput(versionResult) {
|
|||
core.setOutput("minor", minor.toString());
|
||||
core.setOutput("patch", patch.toString());
|
||||
core.setOutput("increment", increment.toString());
|
||||
core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase());
|
||||
core.setOutput("changed", changed.toString());
|
||||
core.setOutput("version_tag", versionTag);
|
||||
core.setOutput("authors", authors);
|
||||
|
|
@ -407,8 +411,8 @@ function run() {
|
|||
useBranches: core.getInput('use_branches') === 'true',
|
||||
majorPattern: core.getInput('major_pattern'),
|
||||
minorPattern: core.getInput('minor_pattern'),
|
||||
majorFlags: core.getInput('major_flags'),
|
||||
minorFlags: core.getInput('minor_flags'),
|
||||
majorFlags: core.getInput('major_regexp_flags'),
|
||||
minorFlags: core.getInput('minor_regexp_flags'),
|
||||
versionFormat: core.getInput('version_format'),
|
||||
changePath: core.getInput('change_path'),
|
||||
namespace: core.getInput('namespace'),
|
||||
|
|
@ -795,12 +799,12 @@ const VersionType_1 = __nccwpck_require__(895);
|
|||
class DefaultVersionClassifier {
|
||||
constructor(config) {
|
||||
const searchBody = config.searchCommitBody;
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, searchBody);
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
|
||||
}
|
||||
parsePattern(pattern, searchBody) {
|
||||
parsePattern(pattern, flags, searchBody) {
|
||||
if (pattern.startsWith('/') && pattern.endsWith('/')) {
|
||||
var regex = new RegExp(pattern.slice(1, -1));
|
||||
var regex = new RegExp(pattern.slice(1, -1), flags);
|
||||
return searchBody ?
|
||||
(commit) => regex.test(commit.subject) || regex.test(commit.body) :
|
||||
(commit) => regex.test(commit.subject);
|
||||
|
|
@ -1012,13 +1016,13 @@ exports.VersionType = void 0;
|
|||
var VersionType;
|
||||
(function (VersionType) {
|
||||
/** Indicates a major version change */
|
||||
VersionType[VersionType["Major"] = 0] = "Major";
|
||||
VersionType["Major"] = "Major";
|
||||
/** Indicates a minor version change */
|
||||
VersionType[VersionType["Minor"] = 1] = "Minor";
|
||||
VersionType["Minor"] = "Minor";
|
||||
/** 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 */
|
||||
VersionType[VersionType["None"] = 3] = "None";
|
||||
VersionType["None"] = "None";
|
||||
})(VersionType = exports.VersionType || (exports.VersionType = {}));
|
||||
|
||||
|
||||
|
|
|
|||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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. */
|
||||
this.majorPattern = "(MAJOR)";
|
||||
/** 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. */
|
||||
this.minorPattern = "(MINOR)";
|
||||
/** A string which indicates the flags used by the `minorPattern` regular expression. */
|
||||
this.minorFlags = "(MINOR)";
|
||||
this.minorFlags = "";
|
||||
/** Pattern to use when formatting output version */
|
||||
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. */
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class VersionResult {
|
|||
* @param minor - The minor version number
|
||||
* @param patch - The patch version number
|
||||
* @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 versionTag - The string to be used as a Git tag
|
||||
* @param changed - True if the version was changed, otherwise false
|
||||
|
|
@ -17,11 +18,12 @@ class VersionResult {
|
|||
* @param previousCommit - The previous commit hash
|
||||
* @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.minor = minor;
|
||||
this.patch = patch;
|
||||
this.increment = increment;
|
||||
this.versionType = versionType;
|
||||
this.formattedVersion = formattedVersion;
|
||||
this.versionTag = versionTag;
|
||||
this.changed = changed;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ function runAction(configurationProvider) {
|
|||
const tagFormmater = configurationProvider.GetTagFormatter();
|
||||
const userFormatter = configurationProvider.GetUserFormatter();
|
||||
if (yield currentCommitResolver.IsEmptyRepoAsync()) {
|
||||
let 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');
|
||||
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, versionInfo.type, versionFormatter.Format(versionInfo), tagFormmater.Format(versionInfo), versionInfo.changed, userFormatter.Format('author', []), '', '', '0.0.0');
|
||||
}
|
||||
const currentCommit = yield currentCommitResolver.ResolveAsync();
|
||||
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater);
|
||||
|
|
@ -46,7 +46,7 @@ function runAction(configurationProvider) {
|
|||
const authors = Object.values(allAuthors)
|
||||
.map((u) => new UserInfo_1.UserInfo(u.n, u.e, u.c))
|
||||
.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;
|
||||
|
|
|
|||
|
|
@ -36,8 +36,9 @@ exports.run = void 0;
|
|||
const action_1 = require("./action");
|
||||
const ConfigurationProvider_1 = require("./ConfigurationProvider");
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const VersionType_1 = require("./providers/VersionType");
|
||||
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;
|
||||
if (!changed) {
|
||||
core.info('No changes detected for this commit');
|
||||
|
|
@ -51,6 +52,7 @@ function setOutput(versionResult) {
|
|||
core.setOutput("minor", minor.toString());
|
||||
core.setOutput("patch", patch.toString());
|
||||
core.setOutput("increment", increment.toString());
|
||||
core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase());
|
||||
core.setOutput("changed", changed.toString());
|
||||
core.setOutput("version_tag", versionTag);
|
||||
core.setOutput("authors", authors);
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ exports.VersionType = void 0;
|
|||
var VersionType;
|
||||
(function (VersionType) {
|
||||
/** Indicates a major version change */
|
||||
VersionType[VersionType["Major"] = 0] = "Major";
|
||||
VersionType["Major"] = "Major";
|
||||
/** Indicates a minor version change */
|
||||
VersionType[VersionType["Minor"] = 1] = "Minor";
|
||||
VersionType["Minor"] = "Minor";
|
||||
/** 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 */
|
||||
VersionType[VersionType["None"] = 3] = "None";
|
||||
VersionType["None"] = "None";
|
||||
})(VersionType = exports.VersionType || (exports.VersionType = {}));
|
||||
|
|
|
|||
|
|
@ -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
|
||||
- *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_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)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { UserInfo } from "./providers/UserInfo";
|
||||
import { VersionType } from "./providers/VersionType";
|
||||
|
||||
/** Represents the total output for the action */
|
||||
export class VersionResult {
|
||||
|
|
@ -8,6 +9,7 @@ export class VersionResult {
|
|||
* @param minor - The minor version number
|
||||
* @param patch - The patch version number
|
||||
* @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 versionTag - The string to be used as a Git tag
|
||||
* @param changed - True if the version was changed, otherwise false
|
||||
|
|
@ -21,6 +23,7 @@ export class VersionResult {
|
|||
public minor: number,
|
||||
public patch: number,
|
||||
public increment: number,
|
||||
public versionType: VersionType,
|
||||
public formattedVersion: string,
|
||||
public versionTag: string,
|
||||
public changed: boolean,
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
|
|||
const userFormatter = configurationProvider.GetUserFormatter();
|
||||
|
||||
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(
|
||||
versionInfo.major,
|
||||
versionInfo.minor,
|
||||
versionInfo.patch,
|
||||
versionInfo.increment,
|
||||
versionInfo.type,
|
||||
versionFormatter.Format(versionInfo),
|
||||
tagFormmater.Format(versionInfo),
|
||||
versionInfo.changed,
|
||||
|
|
@ -60,6 +61,7 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
|
|||
versionInfo.minor,
|
||||
versionInfo.patch,
|
||||
versionInfo.increment,
|
||||
versionInfo.type,
|
||||
versionFormatter.Format(versionInfo),
|
||||
tagFormmater.Format(versionInfo),
|
||||
versionInfo.changed,
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ import { ActionConfig } from './ActionConfig';
|
|||
import { ConfigurationProvider } from './ConfigurationProvider';
|
||||
import { VersionResult } from './VersionResult';
|
||||
import * as core from '@actions/core';
|
||||
import { VersionType } from './providers/VersionType';
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ function setOutput(versionResult: VersionResult) {
|
|||
core.setOutput("minor", minor.toString());
|
||||
core.setOutput("patch", patch.toString());
|
||||
core.setOutput("increment", increment.toString());
|
||||
core.setOutput("version_type", VersionType[versionType].toLowerCase());
|
||||
core.setOutput("changed", changed.toString());
|
||||
core.setOutput("version_tag", versionTag);
|
||||
core.setOutput("authors", authors);
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
/** Indicates the type of change a particular version change represents */
|
||||
export enum VersionType {
|
||||
/** Indicates a major version change */
|
||||
Major,
|
||||
Major = 'Major',
|
||||
/** Indicates a minor version change */
|
||||
Minor,
|
||||
Minor = 'Minor',
|
||||
/** Indicates a patch version change */
|
||||
Patch,
|
||||
Patch = 'Patch',
|
||||
/** Indicates no change--generally this means that the current commit is already tagged with a version */
|
||||
None
|
||||
None = 'None'
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue