Skip to content

Commit 0a2d3e6

Browse files
authored
Handle alpha versions correctly (#39)
* Handle alpha builds as if they are snapshots. Since they can be found in staging this currently works for 8.0.0-alpha1. * Fix typo * Only fallback for alphas when not released
1 parent 4868201 commit 0a2d3e6

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/Elastic.Elasticsearch.Managed/ClusterBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public IDisposable Start(IConsoleLineHandler writer, TimeSpan waitForStarted)
118118
if (!Started)
119119
{
120120
var nodeExceptions = Nodes.Select(n => n.LastSeenException).Where(e => e != null).ToList();
121-
var message = $"{{{GetType().Name}.{nameof(Start)}}} cluster did not start succesfully";
121+
var message = $"{{{GetType().Name}.{nameof(Start)}}} cluster did not start successfully";
122122
var seeLogsMessage = SeeLogsMessage(message);
123123
writer?.WriteError(seeLogsMessage);
124124
throw new AggregateException(seeLogsMessage, nodeExceptions);

src/Elastic.Stack.ArtifactsApi/ElasticVersion.cs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ namespace Elastic.Stack.ArtifactsApi
1414
{
1515
public class ElasticVersion : Version, IComparable<string>
1616
{
17-
private readonly ConcurrentDictionary<string, Artifact>
18-
_resolved = new ConcurrentDictionary<string, Artifact>();
17+
private readonly ConcurrentDictionary<string, Artifact> _resolved = new();
1918

2019
protected ElasticVersion(string version, ArtifactBuildState state, string buildHash = null) : base(version)
2120
{
@@ -28,7 +27,7 @@ protected ElasticVersion(string version, ArtifactBuildState state, string buildH
2827

2928
public int CompareTo(string other)
3029
{
31-
var v = (ElasticVersion) other;
30+
var v = (ElasticVersion)other;
3231
return CompareTo(v);
3332
}
3433

@@ -73,25 +72,29 @@ ArtifactBuildState GetReleaseState(string s)
7372
: ArtifactBuildState.BuildCandidate;
7473
}
7574

76-
if (string.IsNullOrWhiteSpace(managedVersionString)) return null;
75+
if (string.IsNullOrWhiteSpace(managedVersionString))
76+
return null;
7777

7878
var version = managedVersionString;
7979
var state = GetReleaseState(version);
8080
var buildHash = string.Empty;
8181

8282
switch (managedVersionString)
8383
{
84-
case string _ when managedVersionString.StartsWith("latest-", StringComparison.OrdinalIgnoreCase):
84+
case { } when managedVersionString.StartsWith("latest-", StringComparison.OrdinalIgnoreCase):
8585
var major = int.Parse(managedVersionString.Replace("latest-", ""));
8686
version = SnapshotApiResolver.LatestReleaseOrSnapshotForMajor(major).ToString();
8787
state = GetReleaseState(version);
8888
if (state == ArtifactBuildState.BuildCandidate)
8989
buildHash = ApiResolver.LatestBuildHash(version);
9090
break;
91-
case string _ when managedVersionString.EndsWith("-snapshot", StringComparison.OrdinalIgnoreCase):
91+
// When the version is not yet released but contains the alpha label, we treat it in the same way as snapshots so it is resolved correctly
92+
case { } _ when managedVersionString.EndsWith("-snapshot", StringComparison.OrdinalIgnoreCase)
93+
|| state != ArtifactBuildState.Released &&
94+
managedVersionString.IndexOf("-alpha", StringComparison.OrdinalIgnoreCase) >= 0:
9295
state = ArtifactBuildState.Snapshot;
9396
break;
94-
case string _ when TryParseBuildCandidate(managedVersionString, out var v, out buildHash):
97+
case { } _ when TryParseBuildCandidate(managedVersionString, out var v, out buildHash):
9598
state = ArtifactBuildState.BuildCandidate;
9699
version = v;
97100
break;
@@ -109,7 +112,8 @@ internal static bool TryParseBuildCandidate(string passedVersion, out string ver
109112
version = null;
110113
gitHash = null;
111114
var tokens = passedVersion.Split(':');
112-
if (tokens.Length < 2) return false;
115+
if (tokens.Length < 2)
116+
return false;
113117
version = tokens[1].Trim();
114118
gitHash = tokens[0].Trim();
115119
return true;
@@ -124,7 +128,8 @@ public bool InRange(string range)
124128
public bool InRange(Range versionRange)
125129
{
126130
var satisfied = versionRange.IsSatisfied(this);
127-
if (satisfied) return true;
131+
if (satisfied)
132+
return true;
128133

129134
//Semver can only match snapshot version with ranges on the same major and minor
130135
//anything else fails but we want to know e.g 2.4.5-SNAPSHOT satisfied by <5.0.0;
@@ -135,24 +140,24 @@ public bool InRange(Range versionRange)
135140

136141
public static implicit operator ElasticVersion(string version) => From(version);
137142

138-
public static bool operator <(ElasticVersion first, string second) => first < (ElasticVersion) second;
139-
public static bool operator >(ElasticVersion first, string second) => first > (ElasticVersion) second;
143+
public static bool operator <(ElasticVersion first, string second) => first < (ElasticVersion)second;
144+
public static bool operator >(ElasticVersion first, string second) => first > (ElasticVersion)second;
140145

141-
public static bool operator <(string first, ElasticVersion second) => (ElasticVersion) first < second;
142-
public static bool operator >(string first, ElasticVersion second) => (ElasticVersion) first > second;
146+
public static bool operator <(string first, ElasticVersion second) => (ElasticVersion)first < second;
147+
public static bool operator >(string first, ElasticVersion second) => (ElasticVersion)first > second;
143148

144-
public static bool operator <=(ElasticVersion first, string second) => first <= (ElasticVersion) second;
145-
public static bool operator >=(ElasticVersion first, string second) => first >= (ElasticVersion) second;
149+
public static bool operator <=(ElasticVersion first, string second) => first <= (ElasticVersion)second;
150+
public static bool operator >=(ElasticVersion first, string second) => first >= (ElasticVersion)second;
146151

147-
public static bool operator <=(string first, ElasticVersion second) => (ElasticVersion) first <= second;
148-
public static bool operator >=(string first, ElasticVersion second) => (ElasticVersion) first >= second;
152+
public static bool operator <=(string first, ElasticVersion second) => (ElasticVersion)first <= second;
153+
public static bool operator >=(string first, ElasticVersion second) => (ElasticVersion)first >= second;
149154

150-
public static bool operator ==(ElasticVersion first, string second) => first == (ElasticVersion) second;
151-
public static bool operator !=(ElasticVersion first, string second) => first != (ElasticVersion) second;
155+
public static bool operator ==(ElasticVersion first, string second) => first == (ElasticVersion)second;
156+
public static bool operator !=(ElasticVersion first, string second) => first != (ElasticVersion)second;
152157

153158

154-
public static bool operator ==(string first, ElasticVersion second) => (ElasticVersion) first == second;
155-
public static bool operator !=(string first, ElasticVersion second) => (ElasticVersion) first != second;
159+
public static bool operator ==(string first, ElasticVersion second) => (ElasticVersion)first == second;
160+
public static bool operator !=(string first, ElasticVersion second) => (ElasticVersion)first != second;
156161

157162
// ReSharper disable once UnusedMember.Local
158163
private bool Equals(ElasticVersion other) => base.Equals(other);

0 commit comments

Comments
 (0)