Skip to content

Commit 7c7bd5f

Browse files
committed
Changes to update version numbers for netcore.
1 parent fa06462 commit 7c7bd5f

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

tools/NetCorePsd1Sync/NetCorePsd1Sync/NetCoreDefinitionGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ public static Hashtable GetHashtable(PowerShell powershell, string path)
8787
return hashtable;
8888
}
8989

90-
public static IEnumerable<Hashtable> GetDesktopHashtables(IEnumerable<string> desktopFilePaths)
90+
public static IEnumerable<Hashtable> GetHashtables(IEnumerable<string> filePaths)
9191
{
9292
using (var powershell = PowerShell.Create())
9393
{
94-
foreach (var path in desktopFilePaths)
94+
foreach (var path in filePaths)
9595
{
9696
yield return GetHashtable(powershell, path);
9797
}

tools/NetCorePsd1Sync/NetCorePsd1Sync/Program.cs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,59 @@ public static class Program
2727
{
2828
private const string Validate = "-v";
2929
private const string Create = "-c";
30+
private const string UpdateVersion = "-u";
3031

3132
private static readonly Dictionary<string, Action<string>> ModeMap = new Dictionary<string, Action<string>>
3233
{
3334
{ Validate, ValidateDefinitionFiles },
34-
{ Create, CreateDefinitionFiles }
35+
{ Create, CreateDefinitionFiles },
36+
{ UpdateVersion, p => UpdateModuleVersions(p, _newVersion) }
3537
};
38+
39+
private static Version _newVersion;
40+
3641
public static void Main(string[] args)
3742
{
38-
var rmPath = args.FirstOrDefault(a => !ModeMap.ContainsKey(a)) ?? @"..\..\..\src\ResourceManager";
43+
var rmPath = args.FirstOrDefault(a => !ModeMap.ContainsKey(a.ToLower())) ?? @"..\..\..\src\ResourceManager";
3944
if (!Directory.Exists(rmPath))
4045
{
4146
throw new ArgumentException($"Directory [{rmPath}] does not exist");
4247
}
4348
//https://stackoverflow.com/a/17563994/294804
44-
var mode = args.Any(a => a.IndexOf(Create, StringComparison.InvariantCultureIgnoreCase) >= 0) ? Create : Validate;
49+
var mode = ModeMap.Keys.FirstOrDefault(k => args.Any(a => a.IndexOf(k, StringComparison.InvariantCultureIgnoreCase) >= 0)) ?? Validate;
50+
if(mode == UpdateVersion)
51+
{
52+
var newVersion = args.FirstOrDefault(a => Version.TryParse(a, out var _));
53+
_newVersion = Version.Parse(newVersion ?? "0.12.0");
54+
}
4555
ModeMap[mode](rmPath);
4656
}
4757

58+
private static void UpdateModuleVersions(string rmPath, Version newVersion)
59+
{
60+
var modulePaths = GetModulePaths(rmPath, true);
61+
var desktopFilePaths = GetDesktopFilePaths(modulePaths);
62+
var netCoreFilePaths = desktopFilePaths.Select(ConvertDesktopToNetCorePath).Where(File.Exists).ToList();
63+
netCoreFilePaths.Add(Path.Combine(rmPath, @"..\Storage\Azure.Storage.Netcore.psd1"));
64+
var netCoreHashTables = GetHashtables(netCoreFilePaths);
65+
66+
foreach (var netCoreHashtable in netCoreHashTables)
67+
{
68+
var netCoreDefinition = CreateNetCoreDefinition(netCoreHashtable);
69+
netCoreDefinition.ModuleVersion = newVersion;
70+
if (netCoreDefinition.RequiredModules.Any(rm => rm.ModuleName == "AzureRM.Profile.Netcore"))
71+
{
72+
netCoreDefinition.RequiredModules.First(rm => rm.ModuleName == "AzureRM.Profile.Netcore").ModuleVersion = newVersion;
73+
}
74+
File.WriteAllLines(netCoreHashtable.GetValueAsString("FilePath"), netCoreDefinition.ToDefinitionEntry());
75+
}
76+
}
77+
4878
private static void ValidateDefinitionFiles(string rmPath)
4979
{
5080
var modulePaths = GetModulePaths(rmPath, true);
5181
var desktopFilePaths = GetDesktopFilePaths(modulePaths);
52-
var desktopHashtables = GetDesktopHashtables(desktopFilePaths);
82+
var desktopHashtables = GetHashtables(desktopFilePaths);
5383
foreach (var desktopHashtable in desktopHashtables)
5484
{
5585
var netCorePath = ConvertDesktopToNetCorePath(desktopHashtable.GetValueAsString("FilePath"));
@@ -109,7 +139,7 @@ private static void CreateDefinitionFiles(string rmPath)
109139
{
110140
var modulePaths = GetModulePaths(rmPath);
111141
var desktopFilePaths = GetDesktopFilePaths(modulePaths);
112-
var desktopHashtables = GetDesktopHashtables(desktopFilePaths);
142+
var desktopHashtables = GetHashtables(desktopFilePaths);
113143
foreach (var desktopHashtable in desktopHashtables)
114144
{
115145
var netCoreFilePath = ConvertDesktopToNetCorePath(desktopHashtable.GetValueAsString("FilePath"));

0 commit comments

Comments
 (0)