From 0a17a26adc61b0dc97a08546a454081477249e1e Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Fri, 6 Mar 2026 11:04:46 +0000 Subject: [PATCH 1/3] feat(bump): add `pre-release` option to the bump command --- cmf-cli/CliMessages.Designer.cs | 9 ++ cmf-cli/CliMessages.resx | 4 + cmf-cli/Commands/bump/BumpCommand.cs | 26 +++-- .../bump/BumpIoTConfigurationCommand.cs | 23 ++++- .../bump/BumpIoTCustomizationCommand.cs | 28 ++++-- .../PackageType/BusinessPackageTypeHandler.cs | 10 +- .../HelpNgCliPackageTypeHandler.cs | 8 +- .../HtmlNgCliPackageTypeHandler.cs | 8 +- .../PackageType/IoTDataPackageTypeHandler.cs | 10 +- .../IoTDataPackageTypeHandlerV2.cs | 10 +- .../PackageType/IoTPackageTypeHandler.cs | 8 +- .../PackageType/PackageTypeHandler.cs | 8 +- .../PresentationPackageTypeHandler.cs | 10 +- .../PackageType/TestPackageTypeHandler.cs | 10 +- core/Interfaces/IPackageTypeHandler.cs | 4 +- core/Utilities/GenericUtilities.cs | 28 +++--- core/Utilities/IoTUtilities.cs | 30 +++--- docs/src/03-explore/commands/bump.md | 1 + .../commands/bump_iot_configuration.md | 1 + .../commands/bump_iot_customization.md | 1 + tests/Specs/Bump.cs | 94 ++++++++++++++++++- 21 files changed, 238 insertions(+), 93 deletions(-) diff --git a/cmf-cli/CliMessages.Designer.cs b/cmf-cli/CliMessages.Designer.cs index f7e675727..ed9e517e2 100644 --- a/cmf-cli/CliMessages.Designer.cs +++ b/cmf-cli/CliMessages.Designer.cs @@ -132,6 +132,15 @@ internal static string MissingMandatoryProperty { } } + /// + /// Looks up a localized string similar to Mutually exclusive properties: {0}. + /// + internal static string MutuallyExclusiveProperties { + get { + return ResourceManager.GetString("MutuallyExclusiveProperties", resourceCulture); + } + } + /// /// Looks up a localized string similar to This is not a root package. /// diff --git a/cmf-cli/CliMessages.resx b/cmf-cli/CliMessages.resx index 8bfd3ad58..66ad4e9a5 100644 --- a/cmf-cli/CliMessages.resx +++ b/cmf-cli/CliMessages.resx @@ -147,6 +147,10 @@ Missing mandatory property {0} 0 - Property name + + Mutually exclusive properties: {0} + 0 - List of properties + This is not a root package diff --git a/cmf-cli/Commands/bump/BumpCommand.cs b/cmf-cli/Commands/bump/BumpCommand.cs index b03d4f6c1..6dd2b47bb 100644 --- a/cmf-cli/Commands/bump/BumpCommand.cs +++ b/cmf-cli/Commands/bump/BumpCommand.cs @@ -38,13 +38,17 @@ public override void Configure(Command cmd) cmd.AddOption(new Option( aliases: new string[] { "-b", "--buildNr" }, description: "Will add this version next to the version (v-b)")); + + cmd.AddOption(new Option( + aliases: new string[] { "-p", "--preRelease" }, + description: "Will add this version as pre-release version (v-p)")); cmd.AddOption(new Option( aliases: new string[] { "-r", "--root" }, description: "Will bump only versions under a specific root folder (i.e. 1.0.0)")); // Add the handler - cmd.Handler = CommandHandler.Create(Execute); + cmd.Handler = CommandHandler.Create(Execute); } /// @@ -55,20 +59,26 @@ public override void Configure(Command cmd) /// The version for build Nr. /// The root. /// - public void Execute(DirectoryInfo packagePath, string version, string buildNr, string root) + /// + public void Execute(DirectoryInfo packagePath, string version, string buildNr, string preRelease, string root) { using var activity = ExecutionContext.ServiceProvider?.GetService()?.StartExtendedActivity(this.GetType().Name); IFileInfo cmfpackageFile = this.fileSystem.FileInfo.New($"{packagePath}/{CliConstants.CmfPackageFileName}"); - if (string.IsNullOrEmpty(version) && string.IsNullOrEmpty(buildNr)) + if (string.IsNullOrEmpty(version) && (string.IsNullOrEmpty(buildNr) || string.IsNullOrEmpty(preRelease))) + { + throw new CliException(string.Format(CliMessages.MissingMandatoryProperties, "version, buildNr, preRelease")); + } + + if (!string.IsNullOrEmpty(buildNr) && !string.IsNullOrEmpty(preRelease)) { - throw new CliException(string.Format(CliMessages.MissingMandatoryProperties, "version, buildNr")); + throw new CliException(string.Format(CliMessages.MutuallyExclusiveProperties, "buildNr, preRelease")); } // Reading cmfPackage CmfPackage cmfPackage = CmfPackage.Load(cmfpackageFile); - Execute(cmfPackage, version, buildNr, root); + Execute(cmfPackage, version, buildNr, preRelease, root); } /// @@ -79,7 +89,7 @@ public void Execute(DirectoryInfo packagePath, string version, string buildNr, s /// The version for build Nr. /// The root. /// - public void Execute(CmfPackage cmfPackage, string version, string buildNr, string root) + public void Execute(CmfPackage cmfPackage, string version, string buildNr, string preRelease, string root) { IDirectoryInfo packageDirectory = cmfPackage.GetFileInfo().Directory; IPackageTypeHandler packageTypeHandler = PackageTypeFactory.GetPackageTypeHandler(cmfPackage); @@ -90,7 +100,9 @@ public void Execute(CmfPackage cmfPackage, string version, string buildNr, strin { "root", root } }; - packageTypeHandler.Bump(version, buildNr, bumpInformation); + string versionSuffix = !string.IsNullOrEmpty(buildNr) ? buildNr : preRelease; + + packageTypeHandler.Bump(version, versionSuffix, bumpInformation); // will save with new version cmfPackage.SaveCmfPackage(); diff --git a/cmf-cli/Commands/bump/BumpIoTConfigurationCommand.cs b/cmf-cli/Commands/bump/BumpIoTConfigurationCommand.cs index ba02a02df..7d5687b5d 100644 --- a/cmf-cli/Commands/bump/BumpIoTConfigurationCommand.cs +++ b/cmf-cli/Commands/bump/BumpIoTConfigurationCommand.cs @@ -43,6 +43,10 @@ public override void Configure(Command cmd) aliases: new string[] { "-b", "--buildNrVersion" }, description: "Will add this version next to the version (v-b)")); + cmd.AddOption(new Option( + aliases: new string[] { "-p", "--preReleaseVersion" }, + description: "Will add this version as pre-release version (v-p)")); + cmd.AddOption(new Option( aliases: new string[] { "-md", "--masterData" }, getDefaultValue: () => { return false; }, @@ -80,7 +84,7 @@ public override void Configure(Command cmd) description: "Instead of replacing the version will add -$version")); // Add the handler - cmd.Handler = CommandHandler.Create(Execute); + cmd.Handler = CommandHandler.Create(Execute); } /// @@ -88,7 +92,8 @@ public override void Configure(Command cmd) /// /// The package directory. /// The version. - /// + /// + /// /// if set to true [is to bump masterdata]. /// if set to true [is to bump io t]. /// The package names. @@ -97,8 +102,9 @@ public override void Configure(Command cmd) /// Name of the workflow. /// if set to true [is to tag]. /// if set to true [only md customization]. + /// /// - public void Execute(IDirectoryInfo path, string version, string buildNr, bool isToBumpMasterdata, bool isToBumpIoT, string packageNames, string root, string group, string workflowName, bool isToTag, bool onlyMdCustomization) + public void Execute(IDirectoryInfo path, string version, string buildNrVersion, string preReleaseVersion, bool isToBumpMasterdata, bool isToBumpIoT, string packageNames, string root, string group, string workflowName, bool isToTag, bool onlyMdCustomization) { using var activity = ExecutionContext.ServiceProvider?.GetService()?.StartExtendedActivity(this.GetType().Name); @@ -115,6 +121,13 @@ public void Execute(IDirectoryInfo path, string version, string buildNr, bool is automationWorkflowDirectories = automationWorkflowDirectories.Where(awf => awf.Contains(root))?.ToList(); } + if (!string.IsNullOrEmpty(buildNrVersion) && !string.IsNullOrEmpty(preReleaseVersion)) + { + throw new CliException(string.Format(CliMessages.MutuallyExclusiveProperties, "buildNrVersion, preReleaseVersion")); + } + + string versionSuffix = !string.IsNullOrEmpty(buildNrVersion) ? buildNrVersion : preReleaseVersion; + foreach (string automationWorkflowDirectory in automationWorkflowDirectories) { #region Bump AutomationWorkflow @@ -129,7 +142,7 @@ public void Execute(IDirectoryInfo path, string version, string buildNr, bool is groups = groups.Where(gr => gr.Contains(group)).ToList(); } - groups.ForEach(group => IoTUtilities.BumpWorkflowFiles(group, version, buildNr, workflowName, packageNames, this.fileSystem)); + groups.ForEach(group => IoTUtilities.BumpWorkflowFiles(group, version, versionSuffix, workflowName, packageNames, this.fileSystem)); } #endregion Bump AutomationWorkflow @@ -138,7 +151,7 @@ public void Execute(IDirectoryInfo path, string version, string buildNr, bool is if (isToBumpMasterdata) { - IoTUtilities.BumpIoTMasterData(automationWorkflowDirectory, version, buildNr, this.fileSystem, onlyCustomization: onlyMdCustomization); + IoTUtilities.BumpIoTMasterData(automationWorkflowDirectory, version, versionSuffix, this.fileSystem, onlyCustomization: onlyMdCustomization); } #endregion Bump IoT Masterdata diff --git a/cmf-cli/Commands/bump/BumpIoTCustomizationCommand.cs b/cmf-cli/Commands/bump/BumpIoTCustomizationCommand.cs index 797df11ec..931a9b9a3 100644 --- a/cmf-cli/Commands/bump/BumpIoTCustomizationCommand.cs +++ b/cmf-cli/Commands/bump/BumpIoTCustomizationCommand.cs @@ -40,6 +40,10 @@ public override void Configure(Command cmd) aliases: new string[] { "-b", "--buildNrVersion" }, description: "Will add this version next to the version (v-b)")); + cmd.AddOption(new Option( + aliases: new string[] { "-p", "--preReleaseVersion" }, + description: "Will add this version as pre-release version (v-p)")); + cmd.AddOption(new Option( aliases: new string[] { "-pckNames", "--packageNames" }, description: "Packages to be bumped")); @@ -49,7 +53,7 @@ public override void Configure(Command cmd) getDefaultValue: () => { return false; }, description: "Instead of replacing the version will add -$version")); - cmd.Handler = CommandHandler.Create(Execute); + cmd.Handler = CommandHandler.Create(Execute); } /// @@ -57,12 +61,13 @@ public override void Configure(Command cmd) /// /// The package path. /// The version. - /// + /// + /// /// The package names. /// if set to true [is to tag]. /// /// - public void Execute(IDirectoryInfo packagePath, string version, string buildNr, string packageNames, bool isToTag) + public void Execute(IDirectoryInfo packagePath, string version, string buildNrVersion, string preReleaseVersion, string packageNames, bool isToTag) { using var activity = ExecutionContext.ServiceProvider?.GetService()?.StartExtendedActivity(this.GetType().Name); IFileInfo cmfpackageFile = this.fileSystem.FileInfo.New($"{packagePath}/{CliConstants.CmfPackageFileName}"); @@ -72,10 +77,15 @@ public void Execute(IDirectoryInfo packagePath, string version, string buildNr, throw new CliException(string.Format(CliMessages.MissingMandatoryProperty, "version")); } + if (!string.IsNullOrEmpty(buildNrVersion) && !string.IsNullOrEmpty(preReleaseVersion)) + { + throw new CliException(string.Format(CliMessages.MutuallyExclusiveProperties, "buildNrVersion, preReleaseVersion")); + } + // Reading cmfPackage CmfPackage cmfPackage = CmfPackage.Load(cmfpackageFile); - Execute(cmfPackage, version, buildNr, packageNames, isToTag); + Execute(cmfPackage, version, buildNrVersion, preReleaseVersion, packageNames, isToTag); } /// @@ -83,12 +93,14 @@ public void Execute(IDirectoryInfo packagePath, string version, string buildNr, /// /// The CMF package. /// The version. - /// + /// The version for build Nr. + /// The pre-release version. /// The package names. /// if set to true [is to tag]. /// - public void Execute(CmfPackage cmfPackage, string version, string buildNr, string packageNames, bool isToTag) + public void Execute(CmfPackage cmfPackage, string version, string buildNrVersion, string preReleaseVersion, string packageNames, bool isToTag) { + string versionSuffix = !string.IsNullOrEmpty(buildNrVersion) ? buildNrVersion : preReleaseVersion; if (cmfPackage.PackageType != PackageType.IoT) { IDirectoryInfo packageDirectory = cmfPackage.GetFileInfo().Directory; @@ -96,12 +108,12 @@ public void Execute(CmfPackage cmfPackage, string version, string buildNr, strin foreach (var iotPackage in iotPackages) { // IoT -> src -> Package XPTO - IoTUtilities.BumpIoTCustomPackages(iotPackage.GetFileInfo().DirectoryName, version, buildNr, packageNames, this.fileSystem); + IoTUtilities.BumpIoTCustomPackages(iotPackage.GetFileInfo().DirectoryName, version, versionSuffix, packageNames, this.fileSystem); } } else { - IoTUtilities.BumpIoTCustomPackages(cmfPackage.GetFileInfo().DirectoryName, version, buildNr, packageNames, this.fileSystem); + IoTUtilities.BumpIoTCustomPackages(cmfPackage.GetFileInfo().DirectoryName, version, versionSuffix, packageNames, this.fileSystem); } } } diff --git a/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs b/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs index c2c1c3477..a33af1ad2 100644 --- a/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs +++ b/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs @@ -87,11 +87,11 @@ public BusinessPackageTypeHandler(CmfPackage cmfPackage) : base(cmfPackage) /// Bumps the specified CMF package. /// /// The version. - /// The version for build Nr. + /// The version for build Nr. /// The bump information. - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); string[] versionTags = null; if (!string.IsNullOrWhiteSpace(version)) @@ -109,8 +109,8 @@ public override void Bump(string version, string buildNr, Dictionary 0 ? versionTags[0] : metadataVersionInfo[0]; string minor = versionTags != null && versionTags.Length > 1 ? versionTags[1] : metadataVersionInfo[1]; string patch = versionTags != null && versionTags.Length > 2 ? versionTags[2] : metadataVersionInfo[2]; - string build = !string.IsNullOrEmpty(buildNr) ? buildNr : "0"; - string newVersion = string.Format(@"Version(""{0}.{1}.{2}.{3}"")", major, minor, patch, build); + string suffix = !string.IsNullOrEmpty(versionSuffix) ? versionSuffix : "0"; + string newVersion = string.Format(@"Version(""{0}.{1}.{2}.{3}"")", major, minor, patch, suffix); text = Regex.Replace(text, pattern, newVersion, System.Text.RegularExpressions.RegexOptions.IgnoreCase); this.fileSystem.File.WriteAllText(filePath, text); } diff --git a/cmf-cli/Handlers/PackageType/HelpNgCliPackageTypeHandler.cs b/cmf-cli/Handlers/PackageType/HelpNgCliPackageTypeHandler.cs index 3541347aa..4063009d8 100644 --- a/cmf-cli/Handlers/PackageType/HelpNgCliPackageTypeHandler.cs +++ b/cmf-cli/Handlers/PackageType/HelpNgCliPackageTypeHandler.cs @@ -148,11 +148,11 @@ public HelpNgCliPackageTypeHandler(CmfPackage cmfPackage) : base(cmfPackage) /// of each project to the specified version. /// /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); foreach (var project in Workspace.Projects) { @@ -160,7 +160,7 @@ public override void Bump(string version, string buildNr, Dictionary /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); foreach (var project in Workspace.Projects) { @@ -147,7 +147,7 @@ public override void Bump(string version, string buildNr, Dictionary /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); // Get All AutomationWorkflowFiles Folders List automationWorkflowDirectory = this.fileSystem.Directory.GetDirectories(CmfPackage.GetFileInfo().DirectoryName, "AutomationWorkflowFiles", SearchOption.AllDirectories).ToList(); @@ -89,13 +89,13 @@ public override void Bump(string version, string buildNr, Dictionary groups = this.fileSystem.Directory.GetDirectories(automationWorkflowFileGroup, "*").ToList(); - groups.ForEach(group => IoTUtilities.BumpWorkflowFiles(group, version, buildNr, null, packageNames, this.fileSystem)); + groups.ForEach(group => IoTUtilities.BumpWorkflowFiles(group, version, versionSuffix, null, packageNames, this.fileSystem)); #endregion Bump AutomationWorkflow #region Bump IoT Masterdata - IoTUtilities.BumpIoTMasterData(automationWorkflowFileGroup, version, buildNr, this.fileSystem, packageNames, onlyCustomization: true); + IoTUtilities.BumpIoTMasterData(automationWorkflowFileGroup, version, versionSuffix, this.fileSystem, packageNames, onlyCustomization: true); #endregion Bump IoT Masterdata } diff --git a/cmf-cli/Handlers/PackageType/IoTDataPackageTypeHandlerV2.cs b/cmf-cli/Handlers/PackageType/IoTDataPackageTypeHandlerV2.cs index 67663834b..1998d95ff 100644 --- a/cmf-cli/Handlers/PackageType/IoTDataPackageTypeHandlerV2.cs +++ b/cmf-cli/Handlers/PackageType/IoTDataPackageTypeHandlerV2.cs @@ -33,11 +33,11 @@ public IoTDataPackageTypeHandlerV2(CmfPackage cmfPackage) : base(cmfPackage) /// Bumps the specified CMF package. /// /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); // Get All AutomationWorkflowFiles Folders List automationWorkflowDirectory = this.fileSystem.Directory.GetDirectories(CmfPackage.GetFileInfo().DirectoryName, "AutomationWorkflowFiles", SearchOption.AllDirectories).ToList(); @@ -78,13 +78,13 @@ public override void Bump(string version, string buildNr, Dictionary groups = this.fileSystem.Directory.GetDirectories(automationWorkflowFileGroup, "*").ToList(); - groups.ForEach(group => IoTUtilities.BumpWorkflowFiles(group, version, buildNr, null, packageNames, this.fileSystem)); + groups.ForEach(group => IoTUtilities.BumpWorkflowFiles(group, version, versionSuffix, null, packageNames, this.fileSystem)); #endregion Bump AutomationWorkflow #region Bump IoT Masterdata - IoTUtilities.BumpIoTMasterData(automationWorkflowFileGroup, version, buildNr, this.fileSystem, packageNames, onlyCustomization: true); + IoTUtilities.BumpIoTMasterData(automationWorkflowFileGroup, version, versionSuffix, this.fileSystem, packageNames, onlyCustomization: true); #endregion Bump IoT Masterdata } diff --git a/cmf-cli/Handlers/PackageType/IoTPackageTypeHandler.cs b/cmf-cli/Handlers/PackageType/IoTPackageTypeHandler.cs index 093b85954..092b9836b 100644 --- a/cmf-cli/Handlers/PackageType/IoTPackageTypeHandler.cs +++ b/cmf-cli/Handlers/PackageType/IoTPackageTypeHandler.cs @@ -250,12 +250,12 @@ protected override void CopyInstallDependencies(IDirectoryInfo packageOutputDir) /// Bumps the specified CMF package. /// /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. /// - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); if (ExecutionContext.Instance.ProjectConfig.MESVersion.Major < 10) { @@ -283,7 +283,7 @@ public override void Bump(string version, string buildNr, Dictionary src -> Package XPTO - IoTUtilities.BumpIoTCustomPackages(CmfPackage.GetFileInfo().DirectoryName, version, buildNr, packageNames, this.fileSystem); + IoTUtilities.BumpIoTCustomPackages(CmfPackage.GetFileInfo().DirectoryName, version, versionSuffix, packageNames, this.fileSystem); } } diff --git a/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs b/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs index c3b0f1446..e9de41298 100644 --- a/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs +++ b/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs @@ -492,19 +492,19 @@ protected virtual void CopyInstallDependencies(IDirectoryInfo packageOutputDir) /// Bumps the specified version. /// /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public virtual void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public virtual void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { // TODO: create "transaction" to rollback if anything fails // NOTE: Check pack strategy. Collect all packages to bump before bump. var currentVersion = CmfPackage.Version.Split("-")[0]; - var currentBuildNr = CmfPackage.Version.Split("-").Length > 1 ? CmfPackage.Version.Split("-")[1] : null; + var currentVersionSuffix = CmfPackage.Version.Split("-").Length > 1 ? CmfPackage.Version.Split("-")[1] : null; if (!currentVersion.IgnoreCaseEquals(version)) { // TODO :: Uncomment if the cmfpackage.json support build number - // cmfPackage.SetVersion(GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr)); + // cmfPackage.SetVersion(GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix)); CmfPackage.SetVersion(!string.IsNullOrWhiteSpace(version) ? version : CmfPackage.Version); diff --git a/cmf-cli/Handlers/PackageType/PresentationPackageTypeHandler.cs b/cmf-cli/Handlers/PackageType/PresentationPackageTypeHandler.cs index fd2fbf4dd..84dd32bcb 100644 --- a/cmf-cli/Handlers/PackageType/PresentationPackageTypeHandler.cs +++ b/cmf-cli/Handlers/PackageType/PresentationPackageTypeHandler.cs @@ -181,11 +181,11 @@ public PresentationPackageTypeHandler(CmfPackage cmfPackage) : base(cmfPackage) /// Bumps the specified version. /// /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); string parentDirectory = CmfPackage.GetFileInfo().DirectoryName; string[] filesToUpdate = this.fileSystem.Directory.GetFiles(parentDirectory, "package.json", SearchOption.AllDirectories); @@ -203,7 +203,7 @@ public override void Bump(string version, string buildNr, Dictionary /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public override void Bump(string version, string buildNr, Dictionary bumpInformation = null) + public override void Bump(string version, string versionSuffix, Dictionary bumpInformation = null) { - base.Bump(version, buildNr, bumpInformation); + base.Bump(version, versionSuffix, bumpInformation); string[] versionTags = null; if (!string.IsNullOrWhiteSpace(version)) @@ -120,8 +120,8 @@ public override void Bump(string version, string buildNr, Dictionary 0 ? versionTags[0] : metadataVersionInfo[0]; string minor = versionTags != null && versionTags.Length > 1 ? versionTags[1] : metadataVersionInfo[1]; string patch = versionTags != null && versionTags.Length > 2 ? versionTags[2] : metadataVersionInfo[2]; - string build = !string.IsNullOrEmpty(buildNr) ? buildNr : "0"; - string newVersion = string.Format(@"Version(""{0}.{1}.{2}.{3}"")", major, minor, patch, build); + string suffix = !string.IsNullOrEmpty(versionSuffix) ? versionSuffix : "0"; + string newVersion = string.Format(@"Version(""{0}.{1}.{2}.{3}"")", major, minor, patch, suffix); text = Regex.Replace(text, pattern, newVersion, System.Text.RegularExpressions.RegexOptions.IgnoreCase); this.fileSystem.File.WriteAllText(filePath, text); } diff --git a/core/Interfaces/IPackageTypeHandler.cs b/core/Interfaces/IPackageTypeHandler.cs index 44c54debc..583f4da3c 100644 --- a/core/Interfaces/IPackageTypeHandler.cs +++ b/core/Interfaces/IPackageTypeHandler.cs @@ -21,9 +21,9 @@ public interface IPackageTypeHandler /// Bumps the specified version. /// /// The version. - /// The version for build Nr. + /// The version suffix. /// The bump information. - public abstract void Bump(string version, string buildNr, Dictionary bumpInformation = null); + public abstract void Bump(string version, string versionSuffix, Dictionary bumpInformation = null); /// /// Bumps the Base version of the package diff --git a/core/Utilities/GenericUtilities.cs b/core/Utilities/GenericUtilities.cs index 808c0593c..ba9f162b0 100644 --- a/core/Utilities/GenericUtilities.cs +++ b/core/Utilities/GenericUtilities.cs @@ -23,19 +23,19 @@ public static class GenericUtilities /// /// /// - /// + /// /// /// the new version /// - public static string RetrieveNewVersion(string currentVersion, string version, string buildNr) + public static string RetrieveNewVersion(string currentVersion, string version, string versionSuffix) { if (!string.IsNullOrEmpty(version)) { currentVersion = version; } - if (!string.IsNullOrEmpty(buildNr)) + if (!string.IsNullOrEmpty(versionSuffix)) { - currentVersion += "-" + buildNr; + currentVersion += "-" + versionSuffix; } return currentVersion; @@ -46,18 +46,18 @@ public static string RetrieveNewVersion(string currentVersion, string version, s /// /// /// - /// + /// /// /// the new version /// - public static string RetrieveNewPresentationVersion(string currentVersion, string version, string buildNr) + public static string RetrieveNewPresentationVersion(string currentVersion, string version, string versionSuffix) { - GenericUtilities.GetCurrentPresentationVersion(currentVersion, out string originalVersion, out string originalBuildNumber); + GenericUtilities.GetCurrentPresentationVersion(currentVersion, out string originalVersion, out string originalVersionSuffix); string newVersion = !string.IsNullOrEmpty(version) ? version : originalVersion; - if (!string.IsNullOrEmpty(buildNr)) + if (!string.IsNullOrEmpty(versionSuffix)) { - newVersion += "-" + buildNr; + newVersion += "-" + versionSuffix; } return newVersion; @@ -67,15 +67,15 @@ public static string RetrieveNewPresentationVersion(string currentVersion, strin /// Get current version based on string, for /// the format 1.0.0-1234 /// where 1.0.0 will be the version - /// and the 1234 will be the build number + /// and the 1234 will be the version suffix /// /// Source information to be parsed /// Version Number - /// Build Number - public static void GetCurrentPresentationVersion(string source, out string version, out string buildNr) + /// Version Suffix + public static void GetCurrentPresentationVersion(string source, out string version, out string versionSuffix) { version = string.Empty; - buildNr = string.Empty; + versionSuffix = string.Empty; if (!string.IsNullOrWhiteSpace(source)) { @@ -83,7 +83,7 @@ public static void GetCurrentPresentationVersion(string source, out string versi version = sourceInfo[0]; if (sourceInfo.Length > 1) { - buildNr = sourceInfo[1]; + versionSuffix = sourceInfo[1]; } } } diff --git a/core/Utilities/IoTUtilities.cs b/core/Utilities/IoTUtilities.cs index 6047d71d0..5848f8113 100644 --- a/core/Utilities/IoTUtilities.cs +++ b/core/Utilities/IoTUtilities.cs @@ -19,11 +19,11 @@ public static class IoTUtilities /// /// The group. /// The version. - /// The version of the build (v-b). + /// The version suffix. /// Name of the workflow. /// The package names. /// the underlying file system - public static void BumpWorkflowFiles(string group, string version, string buildNr, string workflowName, string packageNames, IFileSystem fileSystem) + public static void BumpWorkflowFiles(string group, string version, string versionSuffix, string workflowName, string packageNames, IFileSystem fileSystem) { List workflowFiles = fileSystem.Directory.GetFiles(group, "*.json").ToList(); @@ -44,7 +44,7 @@ public static void BumpWorkflowFiles(string group, string version, string buildN { string currentVersion = tasks["reference"]["package"]["version"]?.ToString().Split("-")[0]; - tasks["reference"]["package"]["version"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr); + tasks["reference"]["package"]["version"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix); } } @@ -55,7 +55,7 @@ public static void BumpWorkflowFiles(string group, string version, string buildN { string currentVersion = converters["reference"]["package"]["version"]?.ToString().Split("-")[0]; - converters["reference"]["package"]["version"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr); + converters["reference"]["package"]["version"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix); } } @@ -68,11 +68,11 @@ public static void BumpWorkflowFiles(string group, string version, string buildN /// /// The automation workflow file group. /// The version. - /// The version of the build (v-b). + /// The version suffix. /// The package names. /// if set to true [only customization]. /// the underlying file system - public static void BumpIoTMasterData(string automationWorkflowFileGroup, string version, string buildNr, IFileSystem fileSystem, string packageNames = null, bool onlyCustomization = true) + public static void BumpIoTMasterData(string automationWorkflowFileGroup, string version, string versionSuffix, IFileSystem fileSystem, string packageNames = null, bool onlyCustomization = true) { IDirectoryInfo parentDirectory = fileSystem.Directory.GetParent(automationWorkflowFileGroup); List jsonMasterDatas = fileSystem.Directory.GetFiles(parentDirectory.FullName, "*.json").ToList(); @@ -96,7 +96,7 @@ public static void BumpIoTMasterData(string automationWorkflowFileGroup, string if (!String.IsNullOrEmpty(automationProtocols?[i.ToString()]?["Package"]?.ToString()) && packageNames.Contains(packageName)) { - automationProtocols[i.ToString()]["PackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr); + automationProtocols[i.ToString()]["PackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix); } } } @@ -113,7 +113,7 @@ public static void BumpIoTMasterData(string automationWorkflowFileGroup, string if (!String.IsNullOrEmpty(automationProtocols?[i.ToString()]?["Package"]?.ToString()) && packageNames.Contains(packageName)) { - automationProtocols[i.ToString()]["PackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr); + automationProtocols[i.ToString()]["PackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix); } } // Update Automation Manager @@ -123,8 +123,8 @@ public static void BumpIoTMasterData(string automationWorkflowFileGroup, string string currentVersion = automationManagers?[i.ToString()]?["ManagerPackageVersion"]?.ToString()?.Split("-")[0]; if (!String.IsNullOrEmpty(automationManagers?[i.ToString()]?["Package"]?.ToString())) { - automationManagers[i.ToString()]["ManagerPackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr); - automationManagers[i.ToString()]["MonitorPackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr); + automationManagers[i.ToString()]["ManagerPackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix); + automationManagers[i.ToString()]["MonitorPackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix); } } @@ -135,7 +135,7 @@ public static void BumpIoTMasterData(string automationWorkflowFileGroup, string string currentVersion = automationManagers?[i.ToString()]?["ControllerPackageVersion"]?.ToString()?.Split("-")[0]; if (!String.IsNullOrEmpty(automationManagers?[i.ToString()]?["Package"]?.ToString())) { - automationManagers[i.ToString()]["ControllerPackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, buildNr); + automationManagers[i.ToString()]["ControllerPackageVersion"] = GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix); } } } @@ -159,10 +159,10 @@ public static void BumpIoTMasterData(string automationWorkflowFileGroup, string /// /// The package path. /// The version. - /// The version of the build (v-b). + /// The version suffix. /// The package names. /// the underlying file system - public static void BumpIoTCustomPackages(string packagePath, string version, string buildNr, string packageNames, IFileSystem fileSystem) + public static void BumpIoTCustomPackages(string packagePath, string version, string versionSuffix, string packageNames, IFileSystem fileSystem) { string[] iotPackages = fileSystem.Directory.GetDirectories(packagePath + "/src/", "*"); @@ -177,7 +177,7 @@ public static void BumpIoTCustomPackages(string packagePath, string version, str string packageJson = fileSystem.File.ReadAllText(iotPackage + "/package.json"); dynamic packageJsonObject = JsonConvert.DeserializeObject(packageJson); - packageJsonObject["version"] = GenericUtilities.RetrieveNewVersion(packageJsonObject["version"].ToString(), version, buildNr); + packageJsonObject["version"] = GenericUtilities.RetrieveNewVersion(packageJsonObject["version"].ToString(), version, versionSuffix); packageJson = JsonConvert.SerializeObject(packageJsonObject, Formatting.Indented); fileSystem.File.WriteAllText(iotPackage + "/package.json", packageJson); @@ -190,7 +190,7 @@ public static void BumpIoTCustomPackages(string packagePath, string version, str var metadataVersion = Regex.Match(metadata, "version: \\\"(.*?)\\\",", RegexOptions.Singleline)?.Value?.Split("version: \"")[1]?.Split("\",")[0]; - metadata = Regex.Replace(metadata, "version: \\\"(.*?)\\\",", $"version: \"{GenericUtilities.RetrieveNewVersion(metadataVersion, version, buildNr)}\","); + metadata = Regex.Replace(metadata, "version: \\\"(.*?)\\\",", $"version: \"{GenericUtilities.RetrieveNewVersion(metadataVersion, version, versionSuffix)}\","); fileSystem.File.WriteAllText(iotPackage + "/src/metadata.ts", metadata); } diff --git a/docs/src/03-explore/commands/bump.md b/docs/src/03-explore/commands/bump.md index a3c221eb1..9203d916b 100644 --- a/docs/src/03-explore/commands/bump.md +++ b/docs/src/03-explore/commands/bump.md @@ -21,6 +21,7 @@ Name | Description ---- | ----------- `-v, --version ` | Will bump all versions to the version specified `-b, --buildNr ` | Will add this version next to the version (v-b) +`-p, --preRelease ` | Will add this version as pre-release version (v-p) `-r, --root ` | Will bump only versions under a specific root folder (i.e. 1.0.0) `-?, -h, --help` | Show help and usage information diff --git a/docs/src/03-explore/commands/bump_iot_configuration.md b/docs/src/03-explore/commands/bump_iot_configuration.md index 687826756..74b04fb55 100644 --- a/docs/src/03-explore/commands/bump_iot_configuration.md +++ b/docs/src/03-explore/commands/bump_iot_configuration.md @@ -21,6 +21,7 @@ Name | Description ---- | ----------- `-v, --version ` | Will bump all versions to the version specified `-b, --buildNrVersion ` | Will add this version next to the version (v-b) +`-p, --preReleaseVersion ` | Will add this version as pre-release version (v-p) `-md, --masterData` | Will bump IoT MasterData version (only applies to .json) [default: False] `-iot` | Will bump IoT Automation Workflows [default: True] `-pckNames, --packageNames ` | Packages to be bumped diff --git a/docs/src/03-explore/commands/bump_iot_customization.md b/docs/src/03-explore/commands/bump_iot_customization.md index a422d3e12..43cef3ac1 100644 --- a/docs/src/03-explore/commands/bump_iot_customization.md +++ b/docs/src/03-explore/commands/bump_iot_customization.md @@ -21,6 +21,7 @@ Name | Description ---- | ----------- `-v, --version ` | Will bump all versions to the version specified `-b, --buildNrVersion ` | Will add this version next to the version (v-b) +`-p, --preReleaseVersion ` | Will add this version as pre-release version (v-p) `-pckNames, --packageNames ` | Packages to be bumped `-isToTag` | Instead of replacing the version will add -$version [default: False] `-?, -h, --help` | Show help and usage information diff --git a/tests/Specs/Bump.cs b/tests/Specs/Bump.cs index e8c93ca2a..f858089ad 100644 --- a/tests/Specs/Bump.cs +++ b/tests/Specs/Bump.cs @@ -105,6 +105,98 @@ function applyConfig (packageName: string) {{ metadataFile.Should().Contain($"version: \"{bumpVersion}\""); } + [Theory] + [InlineData("alpha.1")] + [InlineData("beta")] + [InlineData("rc.1")] + [InlineData("featureA")] + public void Bump_PreRelease(string preRelease) + { + // files + string cmfPackageJson = $"help/{CliConstants.CmfPackageFileName}"; + string npmPackageJson = "/help/package.json"; + string metadataTS = + "/help/src/packages/cmf.docs.area.cmf.custom.help/src/cmf.docs.area.cmf.custom.help.metadata.ts"; + + string bumpVersion = "1.0.1"; + string expectedVersion = $"{bumpVersion}-{preRelease}"; + + var fileSystem = new MockFileSystem(new Dictionary + { + { + MockUnixSupport.Path(@"c:\.project-config.json"), new MockFileData( + @"{ + ""MESVersion"": ""9.0.0"" + }") + }, + { + cmfPackageJson, new MockFileData( + @$"{{ + ""packageId"": ""Cmf.Custom.Help"", + ""version"": ""1.0.0"", + ""description"": ""Cmf Custom Cmf.Custom.Help Package"", + ""packageType"": ""Help"", + ""isInstallable"": true, + ""isUniqueInstall"": false, + ""contentToPack"": [ + {{ + ""source"": ""src/packages/*"", + ""target"": ""node_modules"", + ""ignoreFiles"": [ + "".npmignore"" + ] + }} + ] + }}") + }, + { + npmPackageJson, new MockFileData( + @$"{{ + ""name"": ""cmf.docs.area"", + ""version"": ""1.0.0"", + ""description"": ""Help customization package"", + ""private"": true, + ""scripts"": {{ + ""preinstall"": ""node npm.preinstall.js"", + ""postinstall"": ""node npm.postinstall.js"" + }}, + ""repository"": {{ + ""type"": ""git"", + ""url"": ""https://url/git"" + }} + }}") + }, + { + metadataTS, new MockFileData( + @$" + (...) + function applyConfig (packageName: string) {{ + const config: PackageMetadata = {{ + version: ""1.0.0"", + (...) + ") + } + }); + + ExecutionContext.ServiceProvider = (new ServiceCollection()) + .AddSingleton(new ProjectConfigService()) + .BuildServiceProvider(); + ExecutionContext.Initialize(fileSystem); + + IFileInfo cmfpackageFile = fileSystem.FileInfo.New(cmfPackageJson); + IPackageTypeHandler packageTypeHandler = PackageTypeFactory.GetPackageTypeHandler(cmfpackageFile); + packageTypeHandler.Bump(bumpVersion, preRelease); + + string cmfPackageVersion = (packageTypeHandler as HelpGulpPackageTypeHandler).CmfPackage.Version; + dynamic packageFile = JsonConvert.DeserializeObject(fileSystem.File.ReadAllText(npmPackageJson)); + string packageFileVersion = packageFile.version; + string metadataFile = fileSystem.File.ReadAllText(metadataTS); + + cmfPackageVersion.Should().Be(expectedVersion); + packageFileVersion.Should().Be(expectedVersion); + metadataFile.Should().Contain($"version: \"{expectedVersion}\""); + } + [Theory] [InlineData("1.1.0", ".")] [InlineData("1.1.0", "Cmf.Custom.Business")] @@ -598,4 +690,4 @@ public class Class1 testAssemblyInfoFile.Should().ContainAll($"[assembly: AssemblyVersion(\"{version}.0\")]", $"[assembly: AssemblyFileVersion(\"{version}.0\")]"); businessAssemblyInfoFile.Should().ContainAll($"[assembly: AssemblyVersion(\"1.0.0.0\")]", $"[assembly: AssemblyFileVersion(\"1.0.0.0\")]"); } -} \ No newline at end of file +} From 68c55ba7a5e585c50222597258460e21c0fbe58a Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Fri, 6 Mar 2026 13:23:45 +0000 Subject: [PATCH 2/3] fix(): a non-integer version suffix should not impact the assembly info version --- cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs b/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs index a33af1ad2..25ab448c6 100644 --- a/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs +++ b/cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs @@ -109,9 +109,9 @@ public override void Bump(string version, string versionSuffix, Dictionary 0 ? versionTags[0] : metadataVersionInfo[0]; string minor = versionTags != null && versionTags.Length > 1 ? versionTags[1] : metadataVersionInfo[1]; string patch = versionTags != null && versionTags.Length > 2 ? versionTags[2] : metadataVersionInfo[2]; - string suffix = !string.IsNullOrEmpty(versionSuffix) ? versionSuffix : "0"; + string suffix = !string.IsNullOrEmpty(versionSuffix) && int.TryParse(versionSuffix, out _) ? versionSuffix : "0"; string newVersion = string.Format(@"Version(""{0}.{1}.{2}.{3}"")", major, minor, patch, suffix); - text = Regex.Replace(text, pattern, newVersion, System.Text.RegularExpressions.RegexOptions.IgnoreCase); + text = Regex.Replace(text, pattern, newVersion, RegexOptions.IgnoreCase); this.fileSystem.File.WriteAllText(filePath, text); } } From d79781a5d8ab242d3cbfee908793fbd79a4118ab Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Fri, 6 Mar 2026 13:26:20 +0000 Subject: [PATCH 3/3] fix(): bring back support to a version suffix on `cmfpackage.json` --- cmf-cli/Handlers/PackageType/PackageTypeHandler.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs b/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs index e9de41298..1605a06ec 100644 --- a/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs +++ b/cmf-cli/Handlers/PackageType/PackageTypeHandler.cs @@ -501,14 +501,13 @@ public virtual void Bump(string version, string versionSuffix, Dictionary 1 ? CmfPackage.Version.Split("-")[1] : null; - if (!currentVersion.IgnoreCaseEquals(version)) + if (!currentVersion.IgnoreCaseEquals(version) || !currentVersionSuffix.IgnoreCaseEquals(versionSuffix)) { - // TODO :: Uncomment if the cmfpackage.json support build number - // cmfPackage.SetVersion(GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix)); + CmfPackage.SetVersion(GenericUtilities.RetrieveNewVersion(currentVersion, version, versionSuffix)); - CmfPackage.SetVersion(!string.IsNullOrWhiteSpace(version) ? version : CmfPackage.Version); + string oldVersion = $"{currentVersion}{(string.IsNullOrEmpty(currentVersionSuffix) ? string.Empty : $"-{currentVersionSuffix}")}"; - Log.Information($"Will bump {CmfPackage.PackageId} from version {currentVersion} to version {CmfPackage.Version}"); + Log.Information($"Will bump {CmfPackage.PackageId} from version {oldVersion} to version {CmfPackage.Version}"); } }