From ff69fcf632cd018bb4f7f610c02ce173839500c1 Mon Sep 17 00:00:00 2001 From: Albie Spriddell Date: Sun, 3 Nov 2024 19:17:13 +0000 Subject: [PATCH] switch to xml-based files --- .gitignore | 2 +- App.config | 16 ------------- DragonFruit.OnionFruit.Deploy.csproj | 8 ++----- Program.cs | 36 +++++++++++++++++----------- oniondeploy.xml.example | 17 +++++++++++++ 5 files changed, 42 insertions(+), 37 deletions(-) delete mode 100644 App.config create mode 100644 oniondeploy.xml.example diff --git a/.gitignore b/.gitignore index 219ccff..f118bdd 100644 --- a/.gitignore +++ b/.gitignore @@ -400,7 +400,7 @@ FodyWeavers.xsd *.sln.iml # App.config -App.config +oniondeploy.xml # temp folders releases/* diff --git a/App.config b/App.config deleted file mode 100644 index 41f8f32..0000000 --- a/App.config +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/DragonFruit.OnionFruit.Deploy.csproj b/DragonFruit.OnionFruit.Deploy.csproj index ec5a2da..a8d0a4d 100644 --- a/DragonFruit.OnionFruit.Deploy.csproj +++ b/DragonFruit.OnionFruit.Deploy.csproj @@ -7,16 +7,12 @@ + + - - - PreserveNewest - - - diff --git a/Program.cs b/Program.cs index fe7b699..dc67fdc 100644 --- a/Program.cs +++ b/Program.cs @@ -1,11 +1,12 @@ using System; -using System.Configuration; using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using DragonFruit.OnionFruit.Deploy.Build; +using Microsoft.Extensions.Configuration; using Octokit; using Serilog; using Serilog.Sinks.SystemConsole.Themes; @@ -14,24 +15,26 @@ namespace DragonFruit.OnionFruit.Deploy; public static class Program { + private static readonly IConfiguration Config; + public static string ReleasesDirectory { get; } = Path.Combine(Environment.CurrentDirectory, "releases"); public static string StagingDirectory { get; } = Path.Combine(Environment.CurrentDirectory, "staging"); - internal static string SolutionName => ConfigurationManager.AppSettings["SolutionName"] ?? throw new InvalidOperationException("SolutionName not set in app.config"); + internal static string SolutionName => Config["SolutionName"] ?? throw new InvalidOperationException("SolutionName not set in app.config"); - internal static string GitHubRepoUser => ConfigurationManager.AppSettings["GHUser"]; - internal static string GitHubRepoName => ConfigurationManager.AppSettings["GHRepo"]; - internal static string GitHubAccessToken => ConfigurationManager.AppSettings["GHToken"]; - internal static string GitHubRepoUrl => $"https://github.com/{GitHubRepoUser}/{GitHubRepoName}"; + internal static string GitHubRepoUser => Config["GitHub:User"] ?? string.Empty; + internal static string GitHubRepoName => Config["GitHub:Repo"] ?? string.Empty; + internal static string GitHubAccessToken => Config["GitHub:Token"] ?? string.Empty; + internal static string GitHubRepoUrl => CanUseGitHub ? $"https://github.com/{GitHubRepoUser}/{GitHubRepoName}" : string.Empty; internal static bool CanUseGitHub => !string.IsNullOrEmpty(GitHubAccessToken) && !string.IsNullOrEmpty(GitHubRepoName) && !string.IsNullOrEmpty(GitHubRepoUser); - internal static string VelopackId => ConfigurationManager.AppSettings["VPKId"]; - internal static string VelopackIcon => ConfigurationManager.AppSettings["VPKIcon"]; + internal static string VelopackId => Config["Velopack:PackageId"] ?? string.Empty; + internal static string VelopackIcon => Config["Velopack:PackageIcon"] ?? string.Empty; internal static string VelopackIconPath => Path.GetFullPath(Path.Combine(SolutionPath, VelopackIcon)); - internal static string CodeSignCert => ConfigurationManager.AppSettings["CodeSignCert"]; - internal static string CodeSignCertPassword => ConfigurationManager.AppSettings["CodeSignPassword"]; + internal static string CodeSignCert => Config["CodeSign:Certificate"] ?? string.Empty; + internal static string CodeSignCertPassword => Config["CodeSign:Password"] ?? string.Empty; public static GitHubClient? GitHubClient { get; private set; } @@ -45,6 +48,11 @@ static Program() .Enrich.With(new ProcessAgeEnricher()) .WriteTo.Console(outputTemplate: "> [{ProcessAge} {Level}]: {Message}{NewLine}", theme: AnsiConsoleTheme.Literate) .CreateLogger(); + + Config = new ConfigurationBuilder() + .AddXmlFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "oniondeploy.xml"), optional: true) + .AddEnvironmentVariables("ONIONDEPLOY_") + .Build(); } public static async Task Main(string[] args) @@ -63,9 +71,9 @@ public static async Task Main(string[] args) }; } - ProjectLocation = GetArg(0); + ProjectLocation = GetArg(0) ?? string.Empty; - if (ProjectLocation == null || Path.GetExtension(ProjectLocation) != ".csproj" || !File.Exists(ProjectLocation)) + if (Path.GetExtension(ProjectLocation) != ".csproj" || !File.Exists(ProjectLocation)) { Log.Error("Invalid project file"); return; @@ -132,8 +140,8 @@ public static async Task RunCommand(string command, string args, bool useS Debug.Assert(process != null); - process.ErrorDataReceived += (_, args) => Log.Error(args.Data); - process.OutputDataReceived += (_, args) => Log.Debug(args.Data); + process.ErrorDataReceived += (_, err) => Log.Error(err.Data!); + process.OutputDataReceived += (_, output) => Log.Debug(output.Data!); process.BeginErrorReadLine(); process.BeginOutputReadLine(); diff --git a/oniondeploy.xml.example b/oniondeploy.xml.example new file mode 100644 index 0000000..92ffedf --- /dev/null +++ b/oniondeploy.xml.example @@ -0,0 +1,17 @@ + + + DragonFruit.OnionFruit.sln + + dragonfruitnetwork + onionfruit + + + + onionfruit + DragonFruit.OnionFruit/Assets/icon.ico + + + + + + \ No newline at end of file