mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-08 12:58:41 +00:00
Make numeric revision numbers only usable on full clones
This commit is contained in:
parent
dc81d8fceb
commit
40f84f861c
4 changed files with 27 additions and 9 deletions
|
@ -3,6 +3,6 @@ namespace LBPUnion.ProjectLighthouse.Configuration.ConfigurationCategories;
|
|||
public class CustomizationConfiguration
|
||||
{
|
||||
public string ServerName { get; set; } = "Project Lighthouse";
|
||||
public string EnvironmentName { get; set; } = "lighthouse";
|
||||
public bool UseNumericRevisionNumber { get; set; } = false;
|
||||
public string EnvironmentName { get; set; } = "project-lighthouse";
|
||||
public bool UseLessReliableNumericRevisionNumberingSystem { get; set; } = false;
|
||||
}
|
|
@ -8,13 +8,25 @@ public static class VersionHelper
|
|||
{
|
||||
static VersionHelper()
|
||||
{
|
||||
string rawRevision = "<unknown>";
|
||||
string commitNumber = "invalid";
|
||||
try
|
||||
{
|
||||
CommitHash = ResourceHelper.ReadManifestFile("gitVersion.txt");
|
||||
Branch = ResourceHelper.ReadManifestFile("gitBranch.txt");
|
||||
rawRevision = ServerConfiguration.Instance.Customization.UseNumericRevisionNumber ? ResourceHelper.ReadManifestFile("gitRevCount.txt") : $"{CommitHash}_{Build}";
|
||||
Revision = (Branch == "main") ? $"r{rawRevision}" : $"{Branch}_r{rawRevision}";
|
||||
bool isShallowRepo = ResourceHelper.ReadManifestFile("gitIsShallowRepo.txt") == "true";
|
||||
if (isShallowRepo)
|
||||
{
|
||||
Logger.Warn
|
||||
(
|
||||
"The UseLessReliavleNumericRevisionNumberingSystem option is not supported for builds made from a shallow clone." +
|
||||
"Please perform a full clone if you want to use numeric revision numbers." +
|
||||
"UseLessReliavleNumericRevisionNumberingSystem is now disabled.",
|
||||
LogArea.Startup
|
||||
);
|
||||
ServerConfiguration.Instance.Customization.UseLessReliableNumericRevisionNumberingSystem = false;
|
||||
}
|
||||
commitNumber = ServerConfiguration.Instance.Customization.UseLessReliableNumericRevisionNumberingSystem ? ResourceHelper.ReadManifestFile("gitRevCount.txt") : $"{CommitHash}_{Build}";
|
||||
OrdinalCommitNumber = (Branch == "main") ? $"r{commitNumber}" : $"{Branch}_r{commitNumber}";
|
||||
|
||||
string remotesFile = ResourceHelper.ReadManifestFile("gitRemotes.txt");
|
||||
|
||||
|
@ -51,16 +63,16 @@ public static class VersionHelper
|
|||
"Please make sure you are properly disclosing the source code to any users who may be using this instance.",
|
||||
LogArea.Startup
|
||||
);
|
||||
Revision = $"{Branch}-dirty_r{rawRevision}";
|
||||
OrdinalCommitNumber = $"{Branch}-dirty_r{commitNumber}";
|
||||
CanCheckForUpdates = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string CommitHash { get; set; }
|
||||
public static string Branch { get; set; }
|
||||
public static string Revision { get; set; }
|
||||
public static string EnvVer => $"{ServerConfiguration.Instance.Customization.EnvironmentName} {Revision}";
|
||||
public static string FullVersion => $"Project Lighthouse {Branch}@{CommitHash} {Build} ({EnvVer})";
|
||||
public static string OrdinalCommitNumber { get; set; }
|
||||
public static string EnvVer => $"{ServerConfiguration.Instance.Customization.EnvironmentName} {OrdinalCommitNumber}";
|
||||
public static string FullVersion => $"Project Lighthouse {Branch}@{CommitHash} {Build} ({(ServerConfiguration.Instance.Customization.UseLessReliableNumericRevisionNumberingSystem ? EnvVer : ServerConfiguration.Instance.Customization.EnvironmentName)})";
|
||||
public static bool IsDirty => CommitHash.EndsWith("-dirty") || CommitsOutOfDate != 1 || CommitHash == "invalid" || Branch == "invalid";
|
||||
public static int CommitsOutOfDate { get; set; }
|
||||
public static bool CanCheckForUpdates { get; set; }
|
||||
|
|
|
@ -52,6 +52,10 @@
|
|||
<EmbeddedResource Include="gitRevCount.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<None Remove="gitIsShallowRepo.txt" />
|
||||
<EmbeddedResource Include="gitIsShallowRepo.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -63,6 +67,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Exec Command="git rev-parse --is-shallow-repository > "$(ProjectDir)/gitIsShallowRepo.txt"" />
|
||||
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt"" />
|
||||
<Exec Command="git rev-list HEAD --count > "$(ProjectDir)/gitRevCount.txt"" />
|
||||
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt"" />
|
||||
|
|
1
ProjectLighthouse/gitIsShallowRepo.txt
Normal file
1
ProjectLighthouse/gitIsShallowRepo.txt
Normal file
|
@ -0,0 +1 @@
|
|||
false
|
Loading…
Add table
Add a link
Reference in a new issue