-
Notifications
You must be signed in to change notification settings - Fork 9
/
VersionInfo.cs
81 lines (70 loc) · 2.14 KB
/
VersionInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Text.Json.Serialization;
namespace CreateMatrix;
public class VersionInfo
{
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum LabelType
{
None,
Stable,
Latest,
Beta,
RC
}
public string Version { get; set; } = "";
public string UriX64 { get; set; } = "";
public string UriArm64 { get; set; } = "";
public List<LabelType> Labels { get; set; } = [];
public int GetBuildNumber()
{
// Extract the build number using the Version class (vs. regex)
// 5.0.0.35271 -> 35271
// 5.1.0.35151 R1 -> 35151
var version = new Version(Version);
return version.Revision;
}
public void SetVersion(string version)
{
// Remove Rxx from version string
// "5.0.0.35134 R10" -> "5.0.0.35134"
var spaceIndex = version.IndexOf(' ');
Version = spaceIndex == -1 ? version : version[..spaceIndex];
}
public int CompareTo(VersionInfo rhs)
{
return Compare(this, rhs);
}
public int CompareTo(string rhs)
{
return Compare(Version, rhs);
}
public static int Compare(string lhs, string rhs)
{
// Compare version numbers using Version class
var lhsVersion = new Version(lhs);
var rhsVersion = new Version(rhs);
return lhsVersion.CompareTo(rhsVersion);
}
public static int Compare(VersionInfo lhs, VersionInfo rhs)
{
return Compare(lhs.Version, rhs.Version);
}
public static IEnumerable<LabelType> GetLabelTypes()
{
// Create list of label types
return Enum.GetValues(typeof(LabelType)).Cast<LabelType>().Where(labelType => labelType != LabelType.None).ToList();
}
}
public class VersionInfoComparer : Comparer<VersionInfo>
{
// Compare using version numbers
public override int Compare(VersionInfo? x, VersionInfo? y)
{
return x switch
{
null when y == null => 0,
null => -1,
_ => y == null ? 1 : VersionInfo.Compare(x, y)
};
}
}