From 0027a68c9982959809780980ec989b7a33a5e0ad Mon Sep 17 00:00:00 2001 From: Beisi Zhou Date: Mon, 31 May 2021 17:24:46 +0800 Subject: [PATCH] update the dependencies for Az.Accounts --- .../VersionController/Models/VersionBumper.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/VersionController/Models/VersionBumper.cs b/tools/VersionController/Models/VersionBumper.cs index 77f003e8bef6..9fb0494cf51d 100644 --- a/tools/VersionController/Models/VersionBumper.cs +++ b/tools/VersionController/Models/VersionBumper.cs @@ -68,6 +68,7 @@ public void BumpAllVersions() UpdateChangeLog(); var releaseNotes = GetReleaseNotes(); UpdateOutputModuleManifest(releaseNotes); + UpdateDependentModules(); UpdateRollupModuleManifest(); UpdateAssemblyInfo(); Console.WriteLine("Finished bumping version " + moduleName + "\n"); @@ -354,7 +355,7 @@ private void UpdateOutputModuleManifest(List releaseNotes) var outputModuleManifestPath = _fileHelper.OutputModuleManifestPath; var projectModuleManifestPath = _fileHelper.ProjectModuleManifestPath; var tempModuleManifestPath = Path.Combine(outputModuleDirectory, moduleName + "-temp.psd1"); - File.Copy(outputModuleManifestPath, tempModuleManifestPath); + File.Copy(outputModuleManifestPath, tempModuleManifestPath, true); var script = "$releaseNotes = @();"; releaseNotes.ForEach(l => script += "$releaseNotes += \"" + l + "\";"); script += $"$env:PSModulePath+=\";{_fileHelper.OutputResourceManagerDirectory}\";"; @@ -378,6 +379,34 @@ private void UpdateOutputModuleManifest(List releaseNotes) File.Delete(tempModuleManifestPath); } + /// + /// Update the ModuleVersion of the bumped module in any dependent module's RequiredModule field. + /// + private void UpdateDependentModules() + { + var moduleName = _fileHelper.ModuleName; + var projectDirectories = _fileHelper.ProjectDirectories; + foreach (var projectDirectory in projectDirectories) + { + var moduleManifestPaths = Directory.GetFiles(projectDirectory, "*.psd1", SearchOption.AllDirectories) + .Where(f => !f.Contains("Netcore") && + !f.Contains("bin") && + !f.Contains("dll-Help") && + !ModuleFilter.IsAzureStackModule(f)) + .ToList(); + foreach (var moduleManifestPath in moduleManifestPaths) + { + var file = File.ReadAllLines(moduleManifestPath); + var pattern = @"ModuleName(\s*)=(\s*)(['\""])" + moduleName + @"(['\""])(\s*);(\s*)ModuleVersion(\s*)=(\s*)(['\""])" + "\\d+(\\.\\d+)+" + @"(['\""])"; + if (file.Where(l => Regex.IsMatch(l, pattern)).Any()) + { + var updatedFile = file.Select(l => Regex.Replace(l, pattern, "ModuleName = '" + moduleName + "'; ModuleVersion = '" + _newVersion + "'")); + File.WriteAllLines(moduleManifestPath, updatedFile); + } + } + } + } + /// /// Creates a new header for the upcoming release based on the new version. ///