Add releaser helper to automate updating versions

This commit is contained in:
theolivenbaum
2022-04-21 09:36:22 +02:00
parent 4f9b46c616
commit d910eec8df
4 changed files with 76 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

View File

@@ -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

59
Releaser/Program.cs Normal file
View File

@@ -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;
}

10
Releaser/Releaser.csproj Normal file
View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>