This commit is contained in:
Vagharshak Baghdasaryan 2025-06-10 15:26:39 +02:00
parent 62cc2d5a6e
commit 82d95f26f4
8 changed files with 216 additions and 109 deletions

View file

@ -21,9 +21,9 @@ class ActionConfig {
/** A string which indicates the flags used by the `minorPattern` regular expression. */
this.minorFlags = "";
/** 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. */
this.changePath = '';
this.changePath = "";
/** Use to create a named sub-version. This value will be appended to tags created for this version. */
this.namespace = "";
/** If true, every commit will be treated as a bump to the version. */
@ -39,7 +39,7 @@ class ActionConfig {
/** If enabled, diagnostic information will be added to the action output. */
this.debug = false;
/** Diagnostics to replay */
this.replay = '';
this.replay = "";
}
}
exports.ActionConfig = ActionConfig;

View file

@ -41,15 +41,19 @@ const cmd = (command, ...args) => __awaiter(void 0, void 0, void 0, function* ()
if (debugManager.isReplayMode()) {
return debugManager.replayCommand(command, args);
}
let output = '', errors = '';
let output = "", errors = "";
const options = {
silent: true,
listeners: {
stdout: (data) => { output += data.toString(); },
stderr: (data) => { errors += data.toString(); },
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
errors += data.toString();
},
ignoreReturnCode: true,
silent: true
}
silent: true,
},
};
let caughtError = null;
try {

View file

@ -17,16 +17,24 @@ class ConfigurationProvider {
this.config = config;
DebugManager_1.DebugManager.getInstance().initializeConfig(config);
}
GetCurrentCommitResolver() { return new DefaultCurrentCommitResolver_1.DefaultCurrentCommitResolver(this.config); }
GetLastReleaseResolver() { return new DefaultLastReleaseResolver_1.DefaultLastReleaseResolver(this.config); }
GetCommitsProvider() { return new DefaultCommitsProvider_1.DefaultCommitsProvider(this.config); }
GetCurrentCommitResolver() {
return new DefaultCurrentCommitResolver_1.DefaultCurrentCommitResolver(this.config);
}
GetLastReleaseResolver() {
return new DefaultLastReleaseResolver_1.DefaultLastReleaseResolver(this.config);
}
GetCommitsProvider() {
return new DefaultCommitsProvider_1.DefaultCommitsProvider(this.config);
}
GetVersionClassifier() {
if (this.config.bumpEachCommit) {
return new BumpAlwaysVersionClassifier_1.BumpAlwaysVersionClassifier(this.config);
}
return new DefaultVersionClassifier_1.DefaultVersionClassifier(this.config);
}
GetVersionFormatter() { return new DefaultVersionFormatter_1.DefaultVersionFormatter(this.config); }
GetVersionFormatter() {
return new DefaultVersionFormatter_1.DefaultVersionFormatter(this.config);
}
GetTagFormatter(branchName) {
if (this.config.versionFromBranch) {
return new BranchVersioningTagFormatter_1.BranchVersioningTagFormatter(this.config, branchName);
@ -35,8 +43,10 @@ class ConfigurationProvider {
}
GetUserFormatter() {
switch (this.config.userFormatType) {
case 'json': return new JsonUserFormatter_1.JsonUserFormatter(this.config);
case 'csv': return new CsvUserFormatter_1.CsvUserFormatter(this.config);
case "json":
return new JsonUserFormatter_1.JsonUserFormatter(this.config);
case "csv":
return new CsvUserFormatter_1.CsvUserFormatter(this.config);
default:
throw new Error(`Unknown user format type: ${this.config.userFormatType}, supported types: json, csv`);
}

View file

@ -41,7 +41,6 @@ class DebugManager {
this.replayMode = false;
this.diagnosticInfo = new DiagnosticInfo();
}
;
/** Enables replay mode and loads the diagnostic information from the specified string */
replayFromDiagnostics(diagnostics) {
this.debugEnabled = false;
@ -50,7 +49,7 @@ class DebugManager {
}
/** Returns a JSON string containing the diagnostic information for this run */
getDebugOutput(emptyRepo = false) {
return this.isDebugEnabled() ? JSON.stringify(this.diagnosticInfo) : '';
return this.isDebugEnabled() ? JSON.stringify(this.diagnosticInfo) : "";
}
/** Records a command and its output for diagnostic purposes */
recordCommand(command, args, output, stderr, error) {
@ -62,9 +61,10 @@ class DebugManager {
/** Replays the specified command and returns the output */
replayCommand(command, args) {
if (this.diagnosticInfo === null) {
throw new Error('No diagnostic information available for replay');
throw new Error("No diagnostic information available for replay");
}
const commandResult = this.diagnosticInfo.commands.find(c => c.command === command && JSON.stringify(c.args) === JSON.stringify(args));
const commandResult = this.diagnosticInfo.commands.find((c) => c.command === command &&
JSON.stringify(c.args) === JSON.stringify(args));
if (!commandResult) {
throw new Error(`No result found in diagnostic for command "${command}"`);
}

View file

@ -53,13 +53,20 @@ function runAction(configurationProvider) {
if (yield currentCommitResolver.IsEmptyRepoAsync()) {
core.info("VAGO REPO WAS EMPTY, returning default version information");
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), tagFormatter.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format('author', []), '', '', tagFormatter.Parse(tagFormatter.Format(versionInfo)).join('.'), debugManager.getDebugOutput(true));
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormatter.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format("author", []), "", "", tagFormatter.Parse(tagFormatter.Format(versionInfo)).join("."), debugManager.getDebugOutput(true));
}
core.info("VAGO REPO IS NOT EMPTY, continuing with versioning");
const currentCommit = yield currentCommitResolver.ResolveAsync();
core.info("VAGO CURRENT COMMIT: " + currentCommit);
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormatter);
core.info("VAGO LAST RELEASE: " + lastRelease.hash + " " + lastRelease.major + "." + lastRelease.minor + "." + lastRelease.patch);
core.info("VAGO LAST RELEASE: " +
lastRelease.hash +
" " +
lastRelease.major +
"." +
lastRelease.minor +
"." +
lastRelease.patch);
const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
core.info("VAGO commit set le:" + commitSet.commits.length);
core.info("VAGO commit set changed: " + commitSet.changed.toString());
@ -71,8 +78,7 @@ function runAction(configurationProvider) {
// version information to be used by the formatters
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) => {
const allAuthors = versionInfo.commits.reduce((acc, commit) => {
const key = `${commit.author} <${commit.authorEmail}>`;
acc[key] = acc[key] || { n: commit.author, e: commit.authorEmail, c: 0 };
acc[key].c++;
@ -81,7 +87,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), tagFormatter.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format('author', authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`, debugManager.getDebugOutput());
return new VersionResult_1.VersionResult(versionInfo.major, versionInfo.minor, versionInfo.patch, versionInfo.increment, versionInfo.type, versionFormatter.Format(versionInfo), tagFormatter.Format(versionInfo), versionInfo.changed, versionInfo.isTagged, userFormatter.Format("author", authors), currentCommit, lastRelease.hash, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`, debugManager.getDebugOutput());
});
}
exports.runAction = runAction;

View file

@ -38,15 +38,15 @@ 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, isTagged, authors, currentCommit, previousCommit, previousVersion, debugOutput } = versionResult;
const { major, minor, patch, increment, versionType, formattedVersion, versionTag, changed, isTagged, authors, currentCommit, previousCommit, previousVersion, debugOutput, } = versionResult;
const repository = process.env.GITHUB_REPOSITORY;
if (!changed) {
core.info("VAGOOO1");
core.info('No changes detected for this commit');
core.info("No changes detected for this commit");
}
core.info(`Version is ${formattedVersion}`);
if (repository !== undefined) {
core.info(`To create a release for this version, go to https://github.com/${repository}/releases/new?tag=${versionTag}&target=${currentCommit.split('/').slice(-1)[0]}`);
core.info(`To create a release for this version, go to https://github.com/${repository}/releases/new?tag=${versionTag}&target=${currentCommit.split("/").slice(-1)[0]}`);
}
core.setOutput("version", formattedVersion);
core.setOutput("major", major.toString());
@ -67,51 +67,51 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
core.info("VAGO Starting run action...");
function toBool(value) {
if (!value || value.toLowerCase() === 'false') {
if (!value || value.toLowerCase() === "false") {
return false;
}
else if (value.toLowerCase() === 'true') {
else if (value.toLowerCase() === "true") {
return true;
}
return false;
}
function toStringOrBool(value) {
if (!value || value === 'false') {
if (!value || value === "false") {
return false;
}
if (value === 'true') {
if (value === "true") {
return true;
}
return value;
}
const config = {
branch: core.getInput('branch'),
tagPrefix: core.getInput('tag_prefix'),
useBranches: toBool(core.getInput('use_branches')),
versionFromBranch: toStringOrBool(core.getInput('version_from_branch')),
majorPattern: core.getInput('major_pattern'),
minorPattern: core.getInput('minor_pattern'),
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'),
bumpEachCommit: toBool(core.getInput('bump_each_commit')),
searchCommitBody: toBool(core.getInput('search_commit_body')),
userFormatType: core.getInput('user_format_type'),
enablePrereleaseMode: toBool(core.getInput('enable_prerelease_mode')),
bumpEachCommitPatchPattern: core.getInput('bump_each_commit_patch_pattern'),
debug: toBool(core.getInput('debug')),
replay: ''
branch: core.getInput("branch"),
tagPrefix: core.getInput("tag_prefix"),
useBranches: toBool(core.getInput("use_branches")),
versionFromBranch: toStringOrBool(core.getInput("version_from_branch")),
majorPattern: core.getInput("major_pattern"),
minorPattern: core.getInput("minor_pattern"),
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"),
bumpEachCommit: toBool(core.getInput("bump_each_commit")),
searchCommitBody: toBool(core.getInput("search_commit_body")),
userFormatType: core.getInput("user_format_type"),
enablePrereleaseMode: toBool(core.getInput("enable_prerelease_mode")),
bumpEachCommitPatchPattern: core.getInput("bump_each_commit_patch_pattern"),
debug: toBool(core.getInput("debug")),
replay: "",
};
if (config.useBranches) {
core.warning(`The 'use_branches' input option is deprecated, please see the documentation for more information on how to use branches`);
}
if (config.versionFormat === '' && core.getInput('format') !== '') {
if (config.versionFormat === "" && core.getInput("format") !== "") {
core.warning(`The 'format' input is deprecated, use 'versionFormat' instead`);
config.versionFormat = core.getInput('format');
config.versionFormat = core.getInput("format");
}
if (core.getInput('short_tags') !== '') {
if (core.getInput("short_tags") !== "") {
core.warning(`The 'short_tags' input option is no longer supported`);
}
const configurationProvider = new ConfigurationProvider_1.ConfigurationProvider(config);