This commit is contained in:
Vagharshak Baghdasaryan 2025-06-10 15:20:16 +02:00
parent 3d087053c5
commit 62cc2d5a6e
12 changed files with 1488 additions and 1008 deletions

2
dist/index.js vendored
View file

@ -619,7 +619,7 @@ 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; const repository = process.env.GITHUB_REPOSITORY;
if (!changed) { if (!changed) {
core.info("VAGOOO") core.info("VAGOOO2")
core.info('No changes detected for this commit'); core.info('No changes detected for this commit');
} }
core.info(`Version is ${formattedVersion}`); core.info(`Version is ${formattedVersion}`);

View file

@ -1,4 +1,27 @@
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
@ -15,8 +38,10 @@ const VersionType_1 = require("./providers/VersionType");
const UserInfo_1 = require("./providers/UserInfo"); const UserInfo_1 = require("./providers/UserInfo");
const VersionInformation_1 = require("./providers/VersionInformation"); const VersionInformation_1 = require("./providers/VersionInformation");
const DebugManager_1 = require("./DebugManager"); const DebugManager_1 = require("./DebugManager");
const core = __importStar(require("@actions/core"));
function runAction(configurationProvider) { function runAction(configurationProvider) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info("VAGO STARTING runAction");
const currentCommitResolver = configurationProvider.GetCurrentCommitResolver(); const currentCommitResolver = configurationProvider.GetCurrentCommitResolver();
const lastReleaseResolver = configurationProvider.GetLastReleaseResolver(); const lastReleaseResolver = configurationProvider.GetLastReleaseResolver();
const commitsProvider = configurationProvider.GetCommitsProvider(); const commitsProvider = configurationProvider.GetCommitsProvider();
@ -26,13 +51,20 @@ function runAction(configurationProvider) {
const userFormatter = configurationProvider.GetUserFormatter(); const userFormatter = configurationProvider.GetUserFormatter();
const debugManager = DebugManager_1.DebugManager.getInstance(); const debugManager = DebugManager_1.DebugManager.getInstance();
if (yield currentCommitResolver.IsEmptyRepoAsync()) { 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); 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(); const currentCommit = yield currentCommitResolver.ResolveAsync();
core.info("VAGO CURRENT COMMIT: " + currentCommit);
const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormatter); const lastRelease = yield lastReleaseResolver.ResolveAsync(currentCommit, tagFormatter);
core.info("VAGO LAST RELEASE: " + lastRelease.hash + " " + lastRelease.major + "." + lastRelease.minor + "." + lastRelease.patch);
const commitSet = yield commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit); 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());
const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet); const classification = yield versionClassifier.ClassifyAsync(lastRelease, commitSet);
core.info("VAGO classification: " + JSON.stringify(classification));
const { isTagged } = lastRelease; const { isTagged } = lastRelease;
const { major, minor, patch, increment, type, changed } = classification; const { major, minor, patch, increment, type, changed } = classification;
// At this point all necessary data has been pulled from the database, create // At this point all necessary data has been pulled from the database, create

View file

@ -41,6 +41,7 @@ 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; const repository = process.env.GITHUB_REPOSITORY;
if (!changed) { 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}`); core.info(`Version is ${formattedVersion}`);
@ -64,6 +65,7 @@ function setOutput(versionResult) {
} }
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info("VAGO Starting run action...");
function toBool(value) { function toBool(value) {
if (!value || value.toLowerCase() === 'false') { if (!value || value.toLowerCase() === 'false') {
return false; return false;
@ -113,7 +115,9 @@ function run() {
core.warning(`The 'short_tags' input option is no longer supported`); core.warning(`The 'short_tags' input option is no longer supported`);
} }
const configurationProvider = new ConfigurationProvider_1.ConfigurationProvider(config); const configurationProvider = new ConfigurationProvider_1.ConfigurationProvider(config);
core.info("VAGO start await runAction(configurationProvider)");
const result = yield (0, action_1.runAction)(configurationProvider); const result = yield (0, action_1.runAction)(configurationProvider);
core.info("VAGO before setOutput(result)");
setOutput(result); setOutput(result);
}); });
} }

View file

@ -1,4 +1,27 @@
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
@ -12,6 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultVersionClassifier = void 0; exports.DefaultVersionClassifier = void 0;
const VersionClassification_1 = require("./VersionClassification"); const VersionClassification_1 = require("./VersionClassification");
const VersionType_1 = require("./VersionType"); const VersionType_1 = require("./VersionType");
const core = __importStar(require("@actions/core"));
class DefaultVersionClassifier { class DefaultVersionClassifier {
constructor(config) { constructor(config) {
const searchBody = config.searchCommitBody; const searchBody = config.searchCommitBody;
@ -85,9 +109,13 @@ class DefaultVersionClassifier {
} }
ClassifyAsync(lastRelease, commitSet) { ClassifyAsync(lastRelease, commitSet) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info("VAGO DefaultVersionClassifier.ClassifyAsync called");
const { type, increment, changed } = this.resolveCommitType(commitSet); const { type, increment, changed } = this.resolveCommitType(commitSet);
core.info("VAGO DefaultVersionClassifier.ClassifyAsync: type: " + VersionType_1.VersionType[type] + ", increment: " + increment + ", changed: " + changed);
const { major, minor, patch } = this.getNextVersion(lastRelease, type); const { major, minor, patch } = this.getNextVersion(lastRelease, type);
core.info("VAGOO DefaultVersionClassifier.ClassifyAsync: major: " + major + ", minor: " + minor + ", patch: " + patch);
if (lastRelease.currentPatch !== null) { if (lastRelease.currentPatch !== null) {
core.info("VAGO DefaultVersionClassifier.ClassifyAsync: lastRelease.currentPatch is not null, using it to determine version classification");
// If the current commit is tagged, we must use that version. Here we check if the version we have resolved from the // If the current commit is tagged, we must use that version. Here we check if the version we have resolved from the
// previous commits is the same as the current version. If it is, we will use the increment value, otherwise we reset // previous commits is the same as the current version. If it is, we will use the increment value, otherwise we reset
// to zero. For example: // to zero. For example:
@ -97,6 +125,10 @@ class DefaultVersionClassifier {
// - commit 4 - v2.0.1+0 // - commit 4 - v2.0.1+0
const versionsMatch = lastRelease.currentMajor === major && lastRelease.currentMinor === minor && lastRelease.currentPatch === patch; const versionsMatch = lastRelease.currentMajor === major && lastRelease.currentMinor === minor && lastRelease.currentPatch === patch;
const currentIncrement = versionsMatch ? increment : 0; const currentIncrement = versionsMatch ? increment : 0;
core.info("VAGO DefaultVersionClassifier.ClassifyAsync: versionsMatch: " + versionsMatch + ", currentIncrement: " + currentIncrement);
core.info("VAGO DefaultVersionClassifier.ClassifyAsync: lastRelease.currentMajor: " + lastRelease.currentMajor);
core.info("VAGO DefaultVersionClassifier.ClassifyAsync: lastRelease.currentMinor: " + lastRelease.currentMinor);
core.info("VAGO DefaultVersionClassifier.ClassifyAsync: lastRelease.currentPatch: " + lastRelease.currentPatch);
return new VersionClassification_1.VersionClassification(VersionType_1.VersionType.None, currentIncrement, false, lastRelease.currentMajor, lastRelease.currentMinor, lastRelease.currentPatch); return new VersionClassification_1.VersionClassification(VersionType_1.VersionType.None, currentIncrement, false, lastRelease.currentMajor, lastRelease.currentMinor, lastRelease.currentPatch);
} }
return new VersionClassification_1.VersionClassification(type, increment, changed, major, minor, patch); return new VersionClassification_1.VersionClassification(type, increment, changed, major, minor, patch);

View file

@ -17,9 +17,9 @@ export class ActionConfig {
/** A string which indicates the flags used by the `minorPattern` regular expression. */ /** A string which indicates the flags used by the `minorPattern` regular expression. */
public minorFlags: string = ""; public minorFlags: string = "";
/** Pattern to use when formatting output version */ /** Pattern to use when formatting output version */
public versionFormat: string = '${major}.${minor}.${patch}'; public versionFormat: string = "${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. */
public changePath: string = ''; public changePath: string = "";
/** Use to create a named sub-version. This value will be appended to tags created for this version. */ /** Use to create a named sub-version. This value will be appended to tags created for this version. */
public namespace: string = ""; public namespace: string = "";
/** If true, every commit will be treated as a bump to the version. */ /** If true, every commit will be treated as a bump to the version. */
@ -35,5 +35,5 @@ export class ActionConfig {
/** If enabled, diagnostic information will be added to the action output. */ /** If enabled, diagnostic information will be added to the action output. */
public debug: boolean = false; public debug: boolean = false;
/** Diagnostics to replay */ /** Diagnostics to replay */
public replay: string = ''; public replay: string = "";
} }

View file

@ -1,24 +1,28 @@
// Using require instead of import to support integration testing // Using require instead of import to support integration testing
import * as exec from '@actions/exec'; import * as exec from "@actions/exec";
import { DebugManager } from './DebugManager'; import { DebugManager } from "./DebugManager";
export const cmd = async (command: string, ...args: any): Promise<string> => { export const cmd = async (command: string, ...args: any): Promise<string> => {
const debugManager = DebugManager.getInstance(); const debugManager = DebugManager.getInstance();
if (debugManager.isReplayMode()) { if (debugManager.isReplayMode()) {
return debugManager.replayCommand(command, args); return debugManager.replayCommand(command, args);
} }
let output = '', errors = ''; let output = "",
errors = "";
const options = { const options = {
silent: true, silent: true,
listeners: { listeners: {
stdout: (data: any) => { output += data.toString(); }, stdout: (data: any) => {
stderr: (data: any) => { errors += data.toString(); }, output += data.toString();
},
stderr: (data: any) => {
errors += data.toString();
},
ignoreReturnCode: true, ignoreReturnCode: true,
silent: true silent: true,
} },
}; };
let caughtError: any = null; let caughtError: any = null;

View file

@ -1,25 +1,24 @@
import { CsvUserFormatter } from './formatting/CsvUserFormatter' import { CsvUserFormatter } from "./formatting/CsvUserFormatter";
import { BranchVersioningTagFormatter } from './formatting/BranchVersioningTagFormatter' import { BranchVersioningTagFormatter } from "./formatting/BranchVersioningTagFormatter";
import { DefaultTagFormatter } from './formatting/DefaultTagFormatter' import { DefaultTagFormatter } from "./formatting/DefaultTagFormatter";
import { DefaultVersionFormatter } from './formatting/DefaultVersionFormatter' import { DefaultVersionFormatter } from "./formatting/DefaultVersionFormatter";
import { JsonUserFormatter } from './formatting/JsonUserFormatter' import { JsonUserFormatter } from "./formatting/JsonUserFormatter";
import { TagFormatter } from './formatting/TagFormatter' import { TagFormatter } from "./formatting/TagFormatter";
import { UserFormatter } from './formatting/UserFormatter' import { UserFormatter } from "./formatting/UserFormatter";
import { VersionFormatter } from './formatting/VersionFormatter' import { VersionFormatter } from "./formatting/VersionFormatter";
import { CommitsProvider } from './providers/CommitsProvider' import { CommitsProvider } from "./providers/CommitsProvider";
import { CurrentCommitResolver } from './providers/CurrentCommitResolver' import { CurrentCommitResolver } from "./providers/CurrentCommitResolver";
import { DefaultCommitsProvider } from './providers/DefaultCommitsProvider' import { DefaultCommitsProvider } from "./providers/DefaultCommitsProvider";
import { DefaultCurrentCommitResolver } from './providers/DefaultCurrentCommitResolver' import { DefaultCurrentCommitResolver } from "./providers/DefaultCurrentCommitResolver";
import { DefaultVersionClassifier } from './providers/DefaultVersionClassifier' import { DefaultVersionClassifier } from "./providers/DefaultVersionClassifier";
import { LastReleaseResolver } from './providers/LastReleaseResolver' import { LastReleaseResolver } from "./providers/LastReleaseResolver";
import { DefaultLastReleaseResolver } from './providers/DefaultLastReleaseResolver' import { DefaultLastReleaseResolver } from "./providers/DefaultLastReleaseResolver";
import { VersionClassifier } from './providers/VersionClassifier' import { VersionClassifier } from "./providers/VersionClassifier";
import { BumpAlwaysVersionClassifier } from './providers/BumpAlwaysVersionClassifier' import { BumpAlwaysVersionClassifier } from "./providers/BumpAlwaysVersionClassifier";
import { ActionConfig } from './ActionConfig'; import { ActionConfig } from "./ActionConfig";
import { DebugManager } from './DebugManager'; import { DebugManager } from "./DebugManager";
export class ConfigurationProvider { export class ConfigurationProvider {
constructor(config: ActionConfig) { constructor(config: ActionConfig) {
this.config = config; this.config = config;
DebugManager.getInstance().initializeConfig(config); DebugManager.getInstance().initializeConfig(config);
@ -27,11 +26,17 @@ export class ConfigurationProvider {
private config: ActionConfig; private config: ActionConfig;
public GetCurrentCommitResolver(): CurrentCommitResolver { return new DefaultCurrentCommitResolver(this.config); } public GetCurrentCommitResolver(): CurrentCommitResolver {
return new DefaultCurrentCommitResolver(this.config);
}
public GetLastReleaseResolver(): LastReleaseResolver { return new DefaultLastReleaseResolver(this.config); } public GetLastReleaseResolver(): LastReleaseResolver {
return new DefaultLastReleaseResolver(this.config);
}
public GetCommitsProvider(): CommitsProvider { return new DefaultCommitsProvider(this.config); } public GetCommitsProvider(): CommitsProvider {
return new DefaultCommitsProvider(this.config);
}
public GetVersionClassifier(): VersionClassifier { public GetVersionClassifier(): VersionClassifier {
if (this.config.bumpEachCommit) { if (this.config.bumpEachCommit) {
@ -40,7 +45,9 @@ export class ConfigurationProvider {
return new DefaultVersionClassifier(this.config); return new DefaultVersionClassifier(this.config);
} }
public GetVersionFormatter(): VersionFormatter { return new DefaultVersionFormatter(this.config); } public GetVersionFormatter(): VersionFormatter {
return new DefaultVersionFormatter(this.config);
}
public GetTagFormatter(branchName: string): TagFormatter { public GetTagFormatter(branchName: string): TagFormatter {
if (this.config.versionFromBranch) { if (this.config.versionFromBranch) {
@ -51,10 +58,14 @@ export class ConfigurationProvider {
public GetUserFormatter(): UserFormatter { public GetUserFormatter(): UserFormatter {
switch (this.config.userFormatType) { switch (this.config.userFormatType) {
case 'json': return new JsonUserFormatter(this.config); case "json":
case 'csv': return new CsvUserFormatter(this.config); return new JsonUserFormatter(this.config);
case "csv":
return new CsvUserFormatter(this.config);
default: default:
throw new Error(`Unknown user format type: ${this.config.userFormatType}, supported types: json, csv`); throw new Error(
`Unknown user format type: ${this.config.userFormatType}, supported types: json, csv`,
);
} }
} }
} }

View file

@ -1,9 +1,8 @@
import { ActionConfig } from "./ActionConfig"; import { ActionConfig } from "./ActionConfig";
/** Utility class for managing debug mode and diagnostic information */ /** Utility class for managing debug mode and diagnostic information */
export class DebugManager { export class DebugManager {
private constructor() { } private constructor() {}
private static instance: DebugManager; private static instance: DebugManager;
/** Returns the singleton instance of the DebugManager */ /** Returns the singleton instance of the DebugManager */
@ -19,7 +18,6 @@ export class DebugManager {
DebugManager.instance = new DebugManager(); DebugManager.instance = new DebugManager();
} }
private debugEnabled: boolean = false; private debugEnabled: boolean = false;
private replayMode: boolean = false; private replayMode: boolean = false;
private diagnosticInfo: DiagnosticInfo | null = null; private diagnosticInfo: DiagnosticInfo | null = null;
@ -42,28 +40,33 @@ export class DebugManager {
} }
} }
/** Enables or disables debug mode, also clears any existing diagnostics info */ /** Enables or disables debug mode, also clears any existing diagnostics info */
public setDebugEnabled(enableDebug: boolean = true): void { public setDebugEnabled(enableDebug: boolean = true): void {
this.debugEnabled = enableDebug; this.debugEnabled = enableDebug;
this.replayMode = false; this.replayMode = false;
this.diagnosticInfo = new DiagnosticInfo(); this.diagnosticInfo = new DiagnosticInfo();
}; }
/** Enables replay mode and loads the diagnostic information from the specified string */ /** Enables replay mode and loads the diagnostic information from the specified string */
public replayFromDiagnostics(diagnostics: string): void { public replayFromDiagnostics(diagnostics: string): void {
this.debugEnabled = false this.debugEnabled = false;
this.replayMode = true; this.replayMode = true;
this.diagnosticInfo = JSON.parse(diagnostics); this.diagnosticInfo = JSON.parse(diagnostics);
} }
/** Returns a JSON string containing the diagnostic information for this run */ /** Returns a JSON string containing the diagnostic information for this run */
public getDebugOutput(emptyRepo: boolean = false): string { public getDebugOutput(emptyRepo: boolean = false): string {
return this.isDebugEnabled() ? JSON.stringify(this.diagnosticInfo) : ''; return this.isDebugEnabled() ? JSON.stringify(this.diagnosticInfo) : "";
} }
/** Records a command and its output for diagnostic purposes */ /** Records a command and its output for diagnostic purposes */
public recordCommand(command: string, args: any[], output: string, stderr: string, error: any): void { public recordCommand(
command: string,
args: any[],
output: string,
stderr: string,
error: any,
): void {
if (this.isDebugEnabled()) { if (this.isDebugEnabled()) {
this.diagnosticInfo?.recordCommand(command, args, output, stderr, error); this.diagnosticInfo?.recordCommand(command, args, output, stderr, error);
} }
@ -72,10 +75,14 @@ export class DebugManager {
/** Replays the specified command and returns the output */ /** Replays the specified command and returns the output */
public replayCommand(command: string, args: any[]): string { public replayCommand(command: string, args: any[]): string {
if (this.diagnosticInfo === null) { 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) { if (!commandResult) {
throw new Error(`No result found in diagnostic for command "${command}"`); throw new Error(`No result found in diagnostic for command "${command}"`);
} }
@ -96,7 +103,13 @@ class CommandResult {
public output: string; public output: string;
public stderr: string; public stderr: string;
public error: any; public error: any;
public constructor(command: string, args: any[], output: string, stderr: string, error: any) { public constructor(
command: string,
args: any[],
output: string,
stderr: string,
error: any,
) {
this.command = command; this.command = command;
this.args = args; this.args = args;
this.output = output; this.output = output;
@ -109,7 +122,13 @@ class CommandResult {
class DiagnosticInfo { class DiagnosticInfo {
public commands: CommandResult[] = []; public commands: CommandResult[] = [];
public empty: boolean = false; public empty: boolean = false;
public recordCommand(command: string, args: any[], output: string, stderr: string, error: any): void { public recordCommand(
command: string,
args: any[],
output: string,
stderr: string,
error: any,
): void {
this.commands.push(new CommandResult(command, args, output, stderr, error)); this.commands.push(new CommandResult(command, args, output, stderr, error));
} }
} }

View file

@ -34,5 +34,6 @@ export class VersionResult {
public currentCommit: string, public currentCommit: string,
public previousCommit: string, public previousCommit: string,
public previousVersion: string, public previousVersion: string,
public debugOutput: string) { } public debugOutput: string,
) {}
} }

View file

@ -1,27 +1,39 @@
import { ConfigurationProvider } from './ConfigurationProvider'; import { ConfigurationProvider } from "./ConfigurationProvider";
import { VersionResult } from './VersionResult'; import { VersionResult } from "./VersionResult";
import { VersionType } from './providers/VersionType'; import { VersionType } from "./providers/VersionType";
import { UserInfo } from './providers/UserInfo'; import { UserInfo } from "./providers/UserInfo";
import { VersionInformation } from './providers/VersionInformation'; import { VersionInformation } from "./providers/VersionInformation";
import { DebugManager } from './DebugManager'; import { DebugManager } from "./DebugManager";
import * as core from '@actions/core'; import * as core from "@actions/core";
export async function runAction(configurationProvider: ConfigurationProvider): Promise<VersionResult> { export async function runAction(
configurationProvider: ConfigurationProvider,
): Promise<VersionResult> {
core.info("VAGO STARTING runAction"); core.info("VAGO STARTING runAction");
const currentCommitResolver = configurationProvider.GetCurrentCommitResolver(); const currentCommitResolver =
configurationProvider.GetCurrentCommitResolver();
const lastReleaseResolver = configurationProvider.GetLastReleaseResolver(); const lastReleaseResolver = configurationProvider.GetLastReleaseResolver();
const commitsProvider = configurationProvider.GetCommitsProvider(); const commitsProvider = configurationProvider.GetCommitsProvider();
const versionClassifier = configurationProvider.GetVersionClassifier(); const versionClassifier = configurationProvider.GetVersionClassifier();
const versionFormatter = configurationProvider.GetVersionFormatter(); const versionFormatter = configurationProvider.GetVersionFormatter();
const tagFormatter = configurationProvider.GetTagFormatter(await currentCommitResolver.ResolveBranchNameAsync()); const tagFormatter = configurationProvider.GetTagFormatter(
await currentCommitResolver.ResolveBranchNameAsync(),
);
const userFormatter = configurationProvider.GetUserFormatter(); const userFormatter = configurationProvider.GetUserFormatter();
const debugManager = DebugManager.getInstance(); const debugManager = DebugManager.getInstance();
if (await currentCommitResolver.IsEmptyRepoAsync()) { if (await currentCommitResolver.IsEmptyRepoAsync()) {
core.info("VAGO REPO WAS EMPTY, returning default version information"); core.info("VAGO REPO WAS EMPTY, returning default version information");
const versionInfo = new VersionInformation(0, 0, 0, 0, VersionType.None, [], false, false); const versionInfo = new VersionInformation(
0,
0,
0,
0,
VersionType.None,
[],
false,
false,
);
return new VersionResult( return new VersionResult(
versionInfo.major, versionInfo.major,
versionInfo.minor, versionInfo.minor,
@ -32,23 +44,41 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
tagFormatter.Format(versionInfo), tagFormatter.Format(versionInfo),
versionInfo.changed, versionInfo.changed,
versionInfo.isTagged, versionInfo.isTagged,
userFormatter.Format('author', []), userFormatter.Format("author", []),
'', "",
'', "",
tagFormatter.Parse(tagFormatter.Format(versionInfo)).join('.'), tagFormatter.Parse(tagFormatter.Format(versionInfo)).join("."),
debugManager.getDebugOutput(true) debugManager.getDebugOutput(true),
); );
} }
core.info("VAGO REPO IS NOT EMPTY, continuing with versioning"); core.info("VAGO REPO IS NOT EMPTY, continuing with versioning");
const currentCommit = await currentCommitResolver.ResolveAsync(); const currentCommit = await currentCommitResolver.ResolveAsync();
core.info("VAGO CURRENT COMMIT: " + currentCommit); core.info("VAGO CURRENT COMMIT: " + currentCommit);
const lastRelease = await lastReleaseResolver.ResolveAsync(currentCommit, tagFormatter); const lastRelease = await lastReleaseResolver.ResolveAsync(
core.info("VAGO LAST RELEASE: " + lastRelease.hash + " " + lastRelease.major + "." + lastRelease.minor + "." + lastRelease.patch); currentCommit,
const commitSet = await commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit); tagFormatter,
core.info("VAGO commit set le:" + commitSet.commits.length) );
core.info(
"VAGO LAST RELEASE: " +
lastRelease.hash +
" " +
lastRelease.major +
"." +
lastRelease.minor +
"." +
lastRelease.patch,
);
const commitSet = await commitsProvider.GetCommitsAsync(
lastRelease.hash,
currentCommit,
);
core.info("VAGO commit set le:" + commitSet.commits.length);
core.info("VAGO commit set changed: " + commitSet.changed.toString()); core.info("VAGO commit set changed: " + commitSet.changed.toString());
const classification = await versionClassifier.ClassifyAsync(lastRelease, commitSet); const classification = await versionClassifier.ClassifyAsync(
lastRelease,
commitSet,
);
core.info("VAGO classification: " + JSON.stringify(classification)); core.info("VAGO classification: " + JSON.stringify(classification));
const { isTagged } = lastRelease; const { isTagged } = lastRelease;
@ -56,11 +86,19 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
// At this point all necessary data has been pulled from the database, create // At this point all necessary data has been pulled from the database, create
// version information to be used by the formatters // version information to be used by the formatters
let versionInfo = new VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed, isTagged); let versionInfo = new VersionInformation(
major,
minor,
patch,
increment,
type,
commitSet.commits,
changed,
isTagged,
);
// Group all the authors together, count the number of commits per author // Group all the authors together, count the number of commits per author
const allAuthors = versionInfo.commits const allAuthors = versionInfo.commits.reduce((acc: any, commit) => {
.reduce((acc: any, commit) => {
const key = `${commit.author} <${commit.authorEmail}>`; const key = `${commit.author} <${commit.authorEmail}>`;
acc[key] = acc[key] || { n: commit.author, e: commit.authorEmail, c: 0 }; acc[key] = acc[key] || { n: commit.author, e: commit.authorEmail, c: 0 };
acc[key].c++; acc[key].c++;
@ -81,10 +119,10 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
tagFormatter.Format(versionInfo), tagFormatter.Format(versionInfo),
versionInfo.changed, versionInfo.changed,
versionInfo.isTagged, versionInfo.isTagged,
userFormatter.Format('author', authors), userFormatter.Format("author", authors),
currentCommit, currentCommit,
lastRelease.hash, lastRelease.hash,
`${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`, `${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`,
debugManager.getDebugOutput() debugManager.getDebugOutput(),
); );
} }

File diff suppressed because it is too large Load diff

View file

@ -1,23 +1,40 @@
import { runAction } from './action'; import { runAction } from "./action";
import { ActionConfig } from './ActionConfig'; 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'; import { VersionType } from "./providers/VersionType";
function setOutput(versionResult: VersionResult) { function setOutput(versionResult: 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; const repository = process.env.GITHUB_REPOSITORY;
if (!changed) { if (!changed) {
core.info("VAGOOO1") core.info("VAGOOO1");
core.info('No changes detected for this commit'); core.info("No changes detected for this commit");
} }
core.info(`Version is ${formattedVersion}`); core.info(`Version is ${formattedVersion}`);
if (repository !== undefined) { 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("version", formattedVersion);
@ -37,57 +54,60 @@ function setOutput(versionResult: VersionResult) {
} }
export async function run() { export async function run() {
core.info("VAGO Starting run action..."); core.info("VAGO Starting run action...");
function toBool(value: string): boolean { function toBool(value: string): boolean {
if (!value || value.toLowerCase() === 'false') { if (!value || value.toLowerCase() === "false") {
return false; return false;
} else if (value.toLowerCase() === 'true') { } else if (value.toLowerCase() === "true") {
return true; return true;
} }
return false; return false;
} }
function toStringOrBool(value: string): string | boolean { function toStringOrBool(value: string): string | boolean {
if (!value || value === 'false') { if (!value || value === "false") {
return false; return false;
} }
if (value === 'true') { if (value === "true") {
return true; return true;
} }
return value; return value;
} }
const config: ActionConfig = { const config: ActionConfig = {
branch: core.getInput('branch'), branch: core.getInput("branch"),
tagPrefix: core.getInput('tag_prefix'), tagPrefix: core.getInput("tag_prefix"),
useBranches: toBool(core.getInput('use_branches')), useBranches: toBool(core.getInput("use_branches")),
versionFromBranch: toStringOrBool(core.getInput('version_from_branch')), versionFromBranch: toStringOrBool(core.getInput("version_from_branch")),
majorPattern: core.getInput('major_pattern'), majorPattern: core.getInput("major_pattern"),
minorPattern: core.getInput('minor_pattern'), minorPattern: core.getInput("minor_pattern"),
majorFlags: core.getInput('major_regexp_flags'), majorFlags: core.getInput("major_regexp_flags"),
minorFlags: core.getInput('minor_regexp_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"),
bumpEachCommit: toBool(core.getInput('bump_each_commit')), bumpEachCommit: toBool(core.getInput("bump_each_commit")),
searchCommitBody: toBool(core.getInput('search_commit_body')), searchCommitBody: toBool(core.getInput("search_commit_body")),
userFormatType: core.getInput('user_format_type'), userFormatType: core.getInput("user_format_type"),
enablePrereleaseMode: toBool(core.getInput('enable_prerelease_mode')), enablePrereleaseMode: toBool(core.getInput("enable_prerelease_mode")),
bumpEachCommitPatchPattern: core.getInput('bump_each_commit_patch_pattern'), bumpEachCommitPatchPattern: core.getInput("bump_each_commit_patch_pattern"),
debug: toBool(core.getInput('debug')), debug: toBool(core.getInput("debug")),
replay: '' replay: "",
}; };
if (config.useBranches) { if (config.useBranches) {
core.warning(`The 'use_branches' input option is deprecated, please see the documentation for more information on how to use branches`); 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`); core.warning(
config.versionFormat = core.getInput('format'); `The 'format' input is deprecated, use 'versionFormat' instead`,
);
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`); core.warning(`The 'short_tags' input option is no longer supported`);
} }