From d910eec8df2ab57a449bc67614c6bd2d97c4bdfb Mon Sep 17 00:00:00 2001 From: theolivenbaum Date: Thu, 21 Apr 2022 09:36:22 +0200 Subject: [PATCH] Add releaser helper to automate updating versions --- ElectronNET.CLI/Commands/BuildCommand.cs | 2 +- ElectronNET.sln | 6 +++ Releaser/Program.cs | 59 ++++++++++++++++++++++++ Releaser/Releaser.csproj | 10 ++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Releaser/Program.cs create mode 100644 Releaser/Releaser.csproj diff --git a/ElectronNET.CLI/Commands/BuildCommand.cs b/ElectronNET.CLI/Commands/BuildCommand.cs index ec51777..e7142c1 100644 --- a/ElectronNET.CLI/Commands/BuildCommand.cs +++ b/ElectronNET.CLI/Commands/BuildCommand.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/ElectronNET.sln b/ElectronNET.sln index 1d12175..b57e044 100644 --- a/ElectronNET.sln +++ b/ElectronNET.sln @@ -44,6 +44,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution start.sh = start.sh EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Releaser", "Releaser\Releaser.csproj", "{8209F641-B8AA-413A-8523-25ACF1BAD55D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -66,6 +68,10 @@ Global {B33E9B82-B6B4-4DB0-B6EE-61CC34641518}.Debug|Any CPU.Build.0 = Debug|Any CPU {B33E9B82-B6B4-4DB0-B6EE-61CC34641518}.Release|Any CPU.ActiveCfg = Debug|Any CPU {B33E9B82-B6B4-4DB0-B6EE-61CC34641518}.Release|Any CPU.Build.0 = Debug|Any CPU + {8209F641-B8AA-413A-8523-25ACF1BAD55D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8209F641-B8AA-413A-8523-25ACF1BAD55D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8209F641-B8AA-413A-8523-25ACF1BAD55D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8209F641-B8AA-413A-8523-25ACF1BAD55D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Releaser/Program.cs b/Releaser/Program.cs new file mode 100644 index 0000000..6ca1ca2 --- /dev/null +++ b/Releaser/Program.cs @@ -0,0 +1,59 @@ +using System.Diagnostics; +using System.Text.RegularExpressions; + +var version = args[0]; + +if (!Version.TryParse(version, out _)) +{ + Console.WriteLine($"Invalid version, expected x.x.x: {version}"); + return 0xDEAD; +} + +var yamlFile = Path.GetFullPath("../.devops/build-nuget.yaml"); +var csFile = Path.GetFullPath("../ElectronNET.CLI/Commands/BuildCommand.cs"); +var packageFile = Path.GetFullPath("../ElectronNET.Host/package.json"); +var packagePath = Path.GetFullPath("../ElectronNET.Host"); + +if(!File.Exists(yamlFile) || !File.Exists(csFile) || !(File.Exists(packageFile))) +{ + Console.WriteLine($"One of these files was not found:\n{yamlFile}\n{csFile}\n{packageFile}"); + return 0xDEAD; +} + +var reYaml = new Regex(@"PackageVersion: \d{1,2}\.\d{1,2}\.\d{1,2}"); +var reCs = new Regex(@"_defaultElectronVersion = ""\d{1,2}\.\d{1,2}\.\d{1,2}"""); +var rePackage = new Regex(@"""electron"": ""\d{1,2}\.\d{1,2}\.\d{1,2}"""); + + +var yaml = File.ReadAllText(yamlFile); +var cs = File.ReadAllText(csFile); +var package = File.ReadAllText(packageFile); + +if(reYaml.IsMatch(yaml) && reCs.IsMatch(cs) && rePackage.IsMatch(package)) +{ + yaml = reYaml.Replace(yaml, $"PackageVersion: {version}"); + cs = reCs.Replace(cs, $"_defaultElectronVersion = \"{version}\""); + package = rePackage.Replace(package, $"\"electron\": \"{version}\""); + + File.WriteAllText(yamlFile, yaml); + File.WriteAllText(csFile, cs); + File.WriteAllText(packageFile, package); + + Directory.SetCurrentDirectory(packagePath); + + var psi = new ProcessStartInfo(); + psi.FileName = "cmd"; + psi.Arguments = "/c \"npm update -D\""; + + var npmProcess = Process.Start(psi); + + npmProcess.WaitForExit(); + + return 0; +} +else +{ + Console.WriteLine($"Regex didn't match, check source code"); + return 0xDEAD; +} + diff --git a/Releaser/Releaser.csproj b/Releaser/Releaser.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/Releaser/Releaser.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + +