Skip to content

Commit

Permalink
Merge pull request #94 from Kantis/master
Browse files Browse the repository at this point in the history
Adding is_tagged to outputs
  • Loading branch information
PaulHatch committed Mar 14, 2023
2 parents 9e89a29 + 37aa192 commit 6a1b048
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 39 deletions.
29 changes: 19 additions & 10 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: 3 additions & 1 deletion lib/VersionResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class VersionResult {
* @param formattedVersion - The formatted semantic version
* @param versionTag - The string to be used as a Git tag
* @param changed - True if the version was changed, otherwise false
* @param isTagged - True if the commit had a tag that matched the `versionTag` format
* @param authors - Authors formatted according to the format mode (e.g. JSON, CSV, YAML, etc.)
* @param currentCommit - The current commit hash
* @param previousCommit - The previous commit hash
* @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.minor = minor;
this.patch = patch;
Expand All @@ -27,6 +28,7 @@ class VersionResult {
this.formattedVersion = formattedVersion;
this.versionTag = versionTag;
this.changed = changed;
this.isTagged = isTagged;
this.authors = authors;
this.currentCommit = currentCommit;
this.previousCommit = previousCommit;
Expand Down
9 changes: 5 additions & 4 deletions lib/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ function runAction(configurationProvider) {
const tagFormmater = configurationProvider.GetTagFormatter();
const userFormatter = configurationProvider.GetUserFormatter();
if (yield currentCommitResolver.IsEmptyRepoAsync()) {
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 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, versionInfo.isTagged, userFormatter.Format('author', []), '', '', '0.0.0');
}
const currentCommit = yield currentCommitResolver.ResolveAsync();
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater);
const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet);
const { isTagged } = lastRelease;
const { major, minor, patch, increment, type, changed } = classification;
// At this point all necessary data has been pulled from the database, create
// version information to be used by the formatters
let versionInfo = new VersionInformation_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
const allAuthors = versionInfo.commits
.reduce((acc, commit) => {
Expand All @@ -46,7 +47,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, 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;
3 changes: 2 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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, 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;
if (!changed) {
core.info('No changes detected for this commit');
Expand All @@ -54,6 +54,7 @@ function setOutput(versionResult) {
core.setOutput("increment", increment.toString());
core.setOutput("version_type", VersionType_1.VersionType[versionType].toLowerCase());
core.setOutput("changed", changed.toString());
core.setOutput("is_tagged", isTagged.toString());
core.setOutput("version_tag", versionTag);
core.setOutput("authors", authors);
core.setOutput("previous_commit", previousCommit);
Expand Down
5 changes: 3 additions & 2 deletions lib/providers/DefaultLastReleaseResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class DefaultLastReleaseResolver {
const releasePattern = tagFormatter.GetPattern();
let currentTag = (yield (0, CommandRunner_1.cmd)(`git tag --points-at ${current} ${releasePattern}`)).trim();
currentTag = tagFormatter.IsValid(currentTag) ? currentTag : '';
const isTagged = currentTag !== '';
const [currentMajor, currentMinor, currentPatch] = !!currentTag ? tagFormatter.Parse(currentTag) : [null, null, null];
let tag = '';
try {
Expand Down Expand Up @@ -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.');
}
// 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
const [major, minor, patch] = tagFormatter.Parse(tag);
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);
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/providers/ReleaseInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ class ReleaseInformation {
* @param currentMajor - the major version number from the current commit
* @param currentMinor - the minor version number from the current commit
* @param currentPatch - the patch version number from the current commit
* @param isTagged - whether the current commit is tagged with a version
*/
constructor(major, minor, patch, hash, currentMajor, currentMinor, currentPatch) {
constructor(major, minor, patch, hash, currentMajor, currentMinor, currentPatch, isTagged) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.hash = hash;
this.currentMajor = currentMajor;
this.currentMinor = currentMinor;
this.currentPatch = currentPatch;
this.isTagged = isTagged;
}
}
exports.ReleaseInformation = ReleaseInformation;
4 changes: 3 additions & 1 deletion lib/providers/VersionInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ class VersionInformation {
* @param type - The type of change the current range represents
* @param commits - The list of commits for this version
* @param changed - True if the version has changed, false otherwise
* @param isTagged - True if the current commit is a version-tagged commit
*/
constructor(major, minor, patch, increment, type, commits, changed) {
constructor(major, minor, patch, increment, type, commits, changed, isTagged) {
this.major = major;
this.minor = minor;
this.patch = patch;
this.increment = increment;
this.type = type;
this.commits = commits;
this.changed = changed;
this.isTagged = isTagged;
}
}
exports.VersionInformation = VersionInformation;
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_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)
- *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.
- *current_commit* is the current commit hash.
- *previous_commit* is the previous commit hash.
Expand Down
2 changes: 2 additions & 0 deletions src/VersionResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class VersionResult {
* @param formattedVersion - The formatted semantic version
* @param versionTag - The string to be used as a Git tag
* @param changed - True if the version was changed, otherwise false
* @param isTagged - True if the commit had a tag that matched the `versionTag` format
* @param authors - Authors formatted according to the format mode (e.g. JSON, CSV, YAML, etc.)
* @param currentCommit - The current commit hash
* @param previousCommit - The previous commit hash
Expand All @@ -27,6 +28,7 @@ export class VersionResult {
public formattedVersion: string,
public versionTag: string,
public changed: boolean,
public isTagged: boolean,
public authors: string,
public currentCommit: string,
public previousCommit: string,
Expand Down
Loading

0 comments on commit 6a1b048

Please sign in to comment.