-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSemverValidateStep.cs
More file actions
26 lines (22 loc) · 943 Bytes
/
Copy pathSemverValidateStep.cs
File metadata and controls
26 lines (22 loc) · 943 Bytes
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
using System.Threading;
using System.Threading.Tasks;
using GeneralUpdate.Tools.Services;
namespace GeneralUpdate.Tools.Pipeline.Steps;
public class SemverValidateStep : IConfigStep
{
public string Name => "Validate semver";
public Task<PipelineContext> ExecuteAsync(PipelineContext ctx, CancellationToken ct)
{
var m = ctx.Manifest;
Validate(m.ClientVersion, nameof(m.ClientVersion), ctx);
Validate(m.UpgradeClientVersion, nameof(m.UpgradeClientVersion), ctx);
return Task.FromResult(ctx);
}
internal static void Validate(string? version, string fieldName, PipelineContext ctx)
{
if (string.IsNullOrWhiteSpace(version))
ctx.Errors.Add($"{fieldName} is required and must follow semver (e.g. 1.0.0).");
else if (!SemverValidator.IsValid(version))
ctx.Errors.Add($"{fieldName} '{version}' does not follow semver (https://semver.org).");
}
}