mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-24 14:11:29 +00:00
Add ability for git version/branch to be embedded in builds of lighthouse
This commit is contained in:
parent
f636fcb3d7
commit
479057fdcc
4 changed files with 57 additions and 2 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -12,4 +12,6 @@ riderModule.iml
|
|||
/ProjectLighthouse/logs/*
|
||||
/ProjectLighthouse/ProjectLighthouse.csproj.user
|
||||
.vs/
|
||||
lighthouse.config.json
|
||||
lighthouse.config.json
|
||||
gitBranch.txt
|
||||
gitVersion.txt
|
39
ProjectLighthouse/Helpers/GitVersionHelper.cs
Normal file
39
ProjectLighthouse/Helpers/GitVersionHelper.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Helpers
|
||||
{
|
||||
public static class GitVersionHelper
|
||||
{
|
||||
static GitVersionHelper()
|
||||
{
|
||||
try
|
||||
{
|
||||
CommitHash = readManifestFile("gitVersion.txt");
|
||||
Branch = readManifestFile("gitBranch.txt");
|
||||
CanCheckForUpdates = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logger.Log("Project Lighthouse was built incorrectly. Please make sure git is available when building.", LoggerLevelStartup.Instance);
|
||||
CommitHash = "invalid";
|
||||
Branch = "invalid";
|
||||
CanCheckForUpdates = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string readManifestFile(string fileName)
|
||||
{
|
||||
using Stream stream = typeof(Program).Assembly.GetManifestResourceStream($"{typeof(Program).Namespace}.{fileName}");
|
||||
using StreamReader reader = new(stream ?? throw new Exception("The assembly or manifest resource is null."));
|
||||
|
||||
return reader.ReadToEnd().Trim();
|
||||
}
|
||||
|
||||
public static string CommitHash { get; set; }
|
||||
public static string Branch { get; set; }
|
||||
public static bool CanCheckForUpdates { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Kettu;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
@ -28,6 +29,7 @@ namespace LBPUnion.ProjectLighthouse
|
|||
Logger.AddLogger(new LighthouseFileLogger());
|
||||
|
||||
Logger.Log("Welcome to Project Lighthouse!", LoggerLevelStartup.Instance);
|
||||
Logger.Log($"Running {ServerStatics.ServerName} {GitVersionHelper.CommitHash}@{GitVersionHelper.Branch}", LoggerLevelStartup.Instance);
|
||||
|
||||
// This loads the config, see ServerSettings.cs for more information
|
||||
Logger.Log("Loaded config file version " + ServerSettings.Instance.ConfigVersion, LoggerLevelStartup.Instance);
|
||||
|
|
|
@ -21,7 +21,19 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Types\SlotXsd.cs"/>
|
||||
<None Remove="gitVersion.txt"/>
|
||||
<EmbeddedResource Include="gitVersion.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<None Remove="gitBranch.txt"/>
|
||||
<EmbeddedResource Include="gitBranch.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt""/>
|
||||
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt""/>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue