Skip to content

Commit 2ea26b9

Browse files
committed
version provider support for custom1
1 parent a74e997 commit 2ea26b9

3 files changed

Lines changed: 47 additions & 10 deletions

File tree

src/Server/Controllers/Api/v1/Admin/VersioningController.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,28 @@ public ActionResult Increment([FromQuery] string rc, [FromHeader(Name = "Authori
9494
[ProducesResponseType(StatusCodes.Status202Accepted)]
9595
[EndpointDescription("Increases the major version number for the Ryubing version provider for both release channels." +
9696
"Requires Admin Token authentication via 'Authorization' header.")]
97-
public ActionResult Advance([FromHeader(Name = "Authorization")] string adminAccessToken)
97+
public ActionResult Advance([FromHeader(Name = "Authorization")] string adminAccessToken,
98+
[FromQuery] string? rc = null)
9899
{
99100
if (!AdminEndpointMetadata.Enabled)
100101
return Problem("This instance of Ryubing UpdateServer is not configured to support this endpoint.",
101102
statusCode: 418);
102103

104+
ReleaseChannel? releaseChannel = null;
105+
106+
if (rc != null)
107+
{
108+
if (rc.TryParseAsReleaseChannel(out var rcOut))
109+
{
110+
releaseChannel = rcOut;
111+
}
112+
else
113+
{
114+
return Problem(
115+
$"Unknown release channel '{rc}'; valid are '{Constants.StableRoute}' and '{Constants.CanaryRoute}'",
116+
statusCode: 404);
117+
}
118+
}
103119

104120
if (!AdminEndpointMetadata.AccessToken.Equals(adminAccessToken))
105121
return Unauthorized();
@@ -111,7 +127,7 @@ public ActionResult Advance([FromHeader(Name = "Authorization")] string adminAcc
111127
return Problem("This instance of Ryubing UpdateServer is not configured to support this endpoint.",
112128
statusCode: 418);
113129

114-
versionProviderService.Advance();
130+
versionProviderService.Advance(releaseChannel ?? ReleaseChannel.Stable);
115131

116132
_logger.LogInformation("Advanced major version to 1.{major}.", versionProviderService.CurrentMajor);
117133

src/Server/Initialization/VersionProvider.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text.Json;
22
using System.Text.Json.Serialization;
33
using Gommon;
4+
using Ryujinx.Systems.Update.Common;
45

56
namespace Ryujinx.Systems.Update.Server;
67

@@ -20,14 +21,27 @@ public class VersionProvider
2021

2122
public Entry Stable { get; set; } = new();
2223
public Entry Canary { get; set; } = new();
24+
public Entry Custom1 { get; set; } = new();
2325

24-
public void IncrementAndReset()
26+
public void IncrementAndReset(ReleaseChannel rc = ReleaseChannel.Stable)
2527
{
26-
Stable = Stable.NextMajor();
27-
Canary = Canary.NextMajor();
28-
if (Stable.Major != Canary.Major)
29-
Canary.Major = Stable.Major;
30-
28+
switch (rc)
29+
{
30+
case ReleaseChannel.Stable or ReleaseChannel.Canary:
31+
{
32+
Stable = Stable.NextMajor();
33+
Canary = Canary.NextMajor();
34+
if (Stable.Major != Canary.Major)
35+
Canary.Major = Stable.Major;
36+
break;
37+
}
38+
case ReleaseChannel.Custom1:
39+
Custom1 = Custom1.NextMajor();
40+
break;
41+
default:
42+
return;
43+
}
44+
3145
Save();
3246
}
3347

src/Server/Services/VersionProviderService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public string GetCurrentVersion(ReleaseChannel rc) =>
2727
{
2828
ReleaseChannel.Stable => _data.Stable.ToString(),
2929
ReleaseChannel.Canary => _data.Canary.ToString(),
30+
ReleaseChannel.Custom1 => _data.Custom1.ToString(),
3031
_ => throw new ArgumentOutOfRangeException()
3132
};
3233

@@ -39,6 +40,11 @@ public string GetNextVersion(ReleaseChannel rc, bool isMajorRelease = false) =>
3940
: _data.Stable.NextBuild()
4041
).ToString(),
4142
ReleaseChannel.Canary => _data.Canary.NextBuild().ToString(), // canaries cannot move the major release, so ignore that boolean for this branch.
43+
ReleaseChannel.Custom1 => (
44+
isMajorRelease
45+
? _data.Custom1.NextMajor()
46+
: _data.Custom1.NextBuild()
47+
).ToString(),
4248
_ => throw new ArgumentOutOfRangeException()
4349
};
4450

@@ -48,6 +54,7 @@ public VersionProvider.Entry IncrementBuild(ReleaseChannel rc)
4854
{
4955
ReleaseChannel.Stable => _data.Stable = _data.Stable.NextBuild(),
5056
ReleaseChannel.Canary => _data.Canary = _data.Canary.NextBuild(),
57+
ReleaseChannel.Custom1 => _data.Custom1 = _data.Custom1.NextBuild(),
5158
_ => throw new ArgumentOutOfRangeException()
5259
};
5360

@@ -56,8 +63,8 @@ public VersionProvider.Entry IncrementBuild(ReleaseChannel rc)
5663
return entry;
5764
}
5865

59-
public void Advance()
66+
public void Advance(ReleaseChannel rc)
6067
{
61-
_data.IncrementAndReset();
68+
_data.IncrementAndReset(rc);
6269
}
6370
}

0 commit comments

Comments
 (0)