Skip to content

Commit

Permalink
Improved version logging (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbah committed Jul 8, 2023
1 parent b585b0f commit 7060821
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 39 deletions.
11 changes: 9 additions & 2 deletions .idea/.idea.CentCom/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CentCom.API/Models/AppVersionDTO.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CentCom.API.Services.Implemented;
using CentCom.Common.Util;

namespace CentCom.API.Models;

Expand Down
19 changes: 2 additions & 17 deletions CentCom.API/Services/Implemented/AppStatusService.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
using System;
using System.Linq;
using System.Reflection;
using CentCom.API.Models;
using CentCom.Common.Util;

namespace CentCom.API.Services.Implemented;

internal record AssemblyInformation(string Version, string Commit, string CopyrightNotice)
{
internal static readonly AssemblyInformation Current = new(typeof(AssemblyInformation).Assembly);

private AssemblyInformation(Assembly assembly) : this(
assembly.GetCustomAttributes<AssemblyMetadataAttribute>().FirstOrDefault(x => x.Key == "MinVerVersion")
?.Value,
assembly.GetCustomAttributes<AssemblyMetadataAttribute>().FirstOrDefault(x => x.Key == "SourceRevisionId")
?.Value,
assembly.GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright)
{
}
}

public class AppStatusService : IAppStatusService
{
private static AppVersionDTO _versionDTO;
Expand All @@ -40,7 +25,7 @@ public ReadOnlySpan<char> GetBuildCommit(int maxHashLength = 7)
return null;

var commitSpan = AssemblyInformation.Current.Commit.AsSpan();
return commitSpan[..(Math.Clamp(maxHashLength, 1, commitSpan.Length) - 1)];
return commitSpan[..Math.Clamp(maxHashLength, 0, commitSpan.Length)];
}

/// <inheritdoc />
Expand Down
5 changes: 3 additions & 2 deletions CentCom.Bot/Commands/AboutCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Threading.Tasks;
using CentCom.Common.Data;
using CentCom.Common.Util;
using Microsoft.EntityFrameworkCore;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
Expand Down Expand Up @@ -48,7 +49,7 @@ public async Task<IResult> GetAboutAsync()
Fields: stats,
Colour: _feedback.Theme.Success,
Timestamp: DateTimeOffset.UtcNow,
Footer: new EmbedFooter(VersionUtility.Version));
Footer: new EmbedFooter($"{AssemblyInformation.Current.Version} ({AssemblyInformation.Current.Commit[..7]})"));
var result = await _feedback.SendContextualEmbedAsync(embed, ct: CancellationToken);
return result.IsSuccess ? Result.FromSuccess() : Result.FromError(result);
}
Expand All @@ -64,6 +65,6 @@ public async Task<IResult> GetInviteAsync()
Description: $"[Click here]({inviteLink}) to invite me to your server!",
Colour: _feedback.Theme.Primary,
Timestamp: DateTimeOffset.UtcNow,
Footer: new EmbedFooter(VersionUtility.Version)));
Footer: new EmbedFooter($"{AssemblyInformation.Current.Version} ({AssemblyInformation.Current.Commit[..7]})")));
}
}
3 changes: 2 additions & 1 deletion CentCom.Bot/Commands/SearchCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using CentCom.Common.Models;
using CentCom.Common.Models.Byond;
using CentCom.Common.Models.DTO;
using CentCom.Common.Util;
using Microsoft.EntityFrameworkCore;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
Expand Down Expand Up @@ -57,7 +58,7 @@ public async Task<IResult> LookupCkey(string key)
$"their /tg/ activity on [Scrubby](https://scrubby.melonmesa.com/ckey/{key}).",
Fields: fields,
Timestamp: DateTimeOffset.UtcNow,
Footer: new EmbedFooter(VersionUtility.Version));
Footer: new EmbedFooter($"{AssemblyInformation.Current.Version} ({AssemblyInformation.Current.Commit[..7]})"));

return await _feedback.SendContextualEmbedAsync(embed);
}
Expand Down
11 changes: 0 additions & 11 deletions CentCom.Bot/VersionUtility.cs

This file was deleted.

20 changes: 20 additions & 0 deletions CentCom.Common/Util/AssemblyInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Linq;
using System.Reflection;

namespace CentCom.Common.Util;

public record AssemblyInformation(string Version, string Commit, string CopyrightNotice)
{
// Note that if this was ever used in a situation where projects had differing version numbers this is
// getting the version number/details of CentCom.Common
public static readonly AssemblyInformation Current = new(typeof(AssemblyInformation).Assembly);

private AssemblyInformation(Assembly assembly) : this(
assembly.GetCustomAttributes<AssemblyMetadataAttribute>().FirstOrDefault(x => x.Key == "MinVerVersion")
?.Value,
assembly.GetCustomAttributes<AssemblyMetadataAttribute>().FirstOrDefault(x => x.Key == "SourceRevisionId")
?.Value,
assembly.GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright)
{
}
}
12 changes: 8 additions & 4 deletions CentCom.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using CentCom.Common.Configuration;
using CentCom.Common.Data;
using CentCom.Common.Util;
using CentCom.Server.BanSources;
using CentCom.Server.Data;
using CentCom.Server.FlatData;
Expand Down Expand Up @@ -41,7 +41,8 @@ static Task Main(string[] args)
.CreateLogger();

Log.Logger.ForContext<Program>()
.Information("Starting CentCom Server {Version}", Assembly.GetExecutingAssembly().GetName().Version);
.Information("Starting CentCom Server {Version} ({Commit})", AssemblyInformation.Current.Version,
AssemblyInformation.Current.Commit[..7]);

return CreateHostBuilder(args).RunConsoleAsync();
}
Expand Down Expand Up @@ -96,7 +97,7 @@ static Task Main(string[] args)
services.AddSingleton<FulpBanService>();
services.AddSingleton<TGMCBanService>();
services.AddSingleton<TgBanService>();
// Standard provider is transient as it differs per request
services.AddTransient<StandardProviderService>();
Expand Down Expand Up @@ -127,6 +128,9 @@ static Task Main(string[] args)
.WithIdentity("updater"),
job => job.WithIdentity("updater"));
});
services.AddQuartzHostedService();
services.AddQuartzHostedService(o =>
{
o.WaitForJobsToComplete = true;
});
});
}
1 change: 0 additions & 1 deletion CentCom.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
add-migration.bat = add-migration.bat
README.md = README.md
publish-script.bat = publish-script.bat
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CentCom.Bot", "CentCom.Bot\CentCom.Bot.csproj", "{A99A54D9-F216-45EA-9758-1092C82CEC57}"
Expand Down

0 comments on commit 7060821

Please sign in to comment.