Skip to content

Commit

Permalink
switch to xml-based files
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Nov 3, 2024
1 parent 11ff42a commit ff69fcf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ FodyWeavers.xsd
*.sln.iml

# App.config
App.config
oniondeploy.xml

# temp folders
releases/*
Expand Down
16 changes: 0 additions & 16 deletions App.config

This file was deleted.

8 changes: 2 additions & 6 deletions DragonFruit.OnionFruit.Deploy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="8.0.1" />
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
36 changes: 22 additions & 14 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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; }

Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -132,8 +140,8 @@ public static async Task<bool> 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();
Expand Down
17 changes: 17 additions & 0 deletions oniondeploy.xml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<SolutionName>DragonFruit.OnionFruit.sln</SolutionName>
<GitHub>
<User>dragonfruitnetwork</User>
<Repo>onionfruit</Repo>
<Token></Token>
</GitHub>
<Velopack>
<PackageId>onionfruit</PackageId>
<PackageIcon>DragonFruit.OnionFruit/Assets/icon.ico</PackageIcon>
</Velopack>
<CodeSign>
<Certificate></Certificate>
<Password></Password>
</CodeSign>
</configuration>

0 comments on commit ff69fcf

Please sign in to comment.