Skip to content

Commit

Permalink
fix(bump): prevent wrong assembly files to being changed when running…
Browse files Browse the repository at this point in the history
… bump from root

#433
  • Loading branch information
ricardofslp authored and joaoopereira committed Dec 5, 2024
1 parent d9ad1b5 commit bee0f02
Show file tree
Hide file tree
Showing 3 changed files with 512 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void Bump(string version, string buildNr, Dictionary<string, obj
}

// Assembly Info
string[] filesToUpdate = this.fileSystem.Directory.GetFiles(".", "AssemblyInfo.cs", SearchOption.AllDirectories);
string[] filesToUpdate = this.fileSystem.Directory.GetFiles(this.CmfPackage.GetFileInfo().DirectoryName, "AssemblyInfo.cs", SearchOption.AllDirectories);
string pattern = @"Version\(\""[0-9.]*\""\)";
foreach (var filePath in filesToUpdate)
{
Expand Down
6 changes: 3 additions & 3 deletions cmf-cli/Handlers/PackageType/TestPackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ public override void Bump(string version, string buildNr, Dictionary<string, obj
}

// Assembly Info
string[] filesToUpdate = Directory.GetFiles(".", "AssemblyInfo.cs", SearchOption.AllDirectories);
string[] filesToUpdate = this.fileSystem.Directory.GetFiles(this.CmfPackage.GetFileInfo().DirectoryName, "AssemblyInfo.cs", SearchOption.AllDirectories);
string pattern = @"Version\(\""[0-9.]*\""\)";
foreach (var filePath in filesToUpdate)
{
string text = File.ReadAllText(filePath);
string text = this.fileSystem.File.ReadAllText(filePath);
var metadataVersionInfo = Regex.Match(text, pattern, RegexOptions.Singleline)?.Value?.Split("\"")[1].Split('.');
string major = versionTags != null && versionTags.Length > 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);
text = Regex.Replace(text, pattern, newVersion, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
File.WriteAllText(filePath, text);
this.fileSystem.File.WriteAllText(filePath, text);
}
}

Expand Down
Loading

0 comments on commit bee0f02

Please sign in to comment.