[shared] Improve fork version string handling
This commit is contained in:
parent
8d29869f76
commit
c40c13261d
2 changed files with 28 additions and 3 deletions
|
@ -11,6 +11,8 @@ public static class Constants
|
||||||
// Leave this as-is, unless you've forked the project & want to reference your own website / repository (irrelevant for license compliance)
|
// Leave this as-is, unless you've forked the project & want to reference your own website / repository (irrelevant for license compliance)
|
||||||
public const string ProjectHomepageUrl = "https://iceshrimp.dev/iceshrimp/Iceshrimp.NET";
|
public const string ProjectHomepageUrl = "https://iceshrimp.dev/iceshrimp/Iceshrimp.NET";
|
||||||
|
|
||||||
|
// Make sure to also update VersionHelpers.VersionIdentifier if you are building a fork
|
||||||
|
|
||||||
public const string ActivityStreamsNs = "https://www.w3.org/ns/activitystreams";
|
public const string ActivityStreamsNs = "https://www.w3.org/ns/activitystreams";
|
||||||
public const string W3IdSecurityNs = "https://w3id.org/security";
|
public const string W3IdSecurityNs = "https://w3id.org/security";
|
||||||
public const string PurlDcNs = "http://purl.org/dc/terms";
|
public const string PurlDcNs = "http://purl.org/dc/terms";
|
||||||
|
|
|
@ -6,6 +6,10 @@ public record VersionInfo(string Version, string RawVersion, string Codename, st
|
||||||
|
|
||||||
public static class VersionHelpers
|
public static class VersionHelpers
|
||||||
{
|
{
|
||||||
|
// Leave this as-is, unless you've forked the project. Set to a shorthand string that identifies your fork.
|
||||||
|
// Gets appended to the version string like this: v1234.5+fork.commit
|
||||||
|
private const string VersionIdentifier = "upstream";
|
||||||
|
|
||||||
public static VersionInfo GetVersionInfo()
|
public static VersionInfo GetVersionInfo()
|
||||||
{
|
{
|
||||||
var attributes = Assembly.GetExecutingAssembly()
|
var attributes = Assembly.GetExecutingAssembly()
|
||||||
|
@ -37,10 +41,29 @@ public static class VersionHelpers
|
||||||
|
|
||||||
// If we have a git revision, limit it to 10 characters
|
// If we have a git revision, limit it to 10 characters
|
||||||
if (fullVersion.Split('+') is { Length: 2 } split)
|
if (fullVersion.Split('+') is { Length: 2 } split)
|
||||||
|
{
|
||||||
|
int maxLength;
|
||||||
|
|
||||||
|
#pragma warning disable CS8519 // The given expression never matches the provided pattern.
|
||||||
|
#pragma warning disable CS8793 // The input always matches the provided pattern.
|
||||||
|
#pragma warning disable CS8794 // The given expression always matches the provided pattern.
|
||||||
|
// ReSharper disable HeuristicUnreachableCode
|
||||||
|
// ReSharper disable once RedundantIfElseBlock
|
||||||
|
if (VersionIdentifier is not "upstream")
|
||||||
|
{
|
||||||
|
split[1] = $"{VersionIdentifier}.{split[1]}";
|
||||||
|
maxLength = VersionIdentifier.Length + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Accomodate for fork information, e.g. version+fork.commit
|
// Accomodate for fork information, e.g. version+fork.commit
|
||||||
var extra = split[1].Split(".");
|
var extra = split[1].Split(".");
|
||||||
var maxLength = extra.Length == 2 ? extra[0].Length + 1 : 0;
|
maxLength = extra.Length == 2 ? extra[0].Length + 1 : 0;
|
||||||
|
}
|
||||||
|
// ReSharper restore HeuristicUnreachableCode
|
||||||
|
#pragma warning restore CS8519 // The given expression never matches the provided pattern.
|
||||||
|
#pragma warning restore CS8794 // The input always matches the provided pattern.
|
||||||
|
#pragma warning restore CS8793 // The given expression always matches the provided pattern.
|
||||||
|
|
||||||
maxLength += Math.Min(split[1].Length, 10);
|
maxLength += Math.Min(split[1].Length, 10);
|
||||||
commitHash = split[1];
|
commitHash = split[1];
|
||||||
|
|
Loading…
Add table
Reference in a new issue