Skip to content

Commit

Permalink
Add version type as output
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHatch committed Oct 2, 2022
1 parent b505a7c commit e1e99bd
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 33 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 19 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/ActionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
4 changes: 3 additions & 1 deletion lib/VersionResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lib/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
4 changes: 3 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lib/providers/VersionType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}));
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/VersionResult.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UserInfo } from "./providers/UserInfo";
import { VersionType } from "./providers/VersionType";

/** Represents the total output for the action */
export class VersionResult {
Expand All @@ -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
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/providers/VersionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

0 comments on commit e1e99bd

Please sign in to comment.