Skip to content

Commit

Permalink
Make the Git method use the new packeger if possible, else fallback t…
Browse files Browse the repository at this point in the history
…o python (#25)
  • Loading branch information
VasilisThePikachu authored Dec 3, 2023
1 parent d603d89 commit 54454bb
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions SS14.Watchdog/Components/Updates/UpdateProviderGit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class UpdateProviderGit : UpdateProvider
private readonly ILogger<UpdateProviderGit> _logger;
private readonly string _repoPath;
private readonly IConfiguration _configuration;

private bool _newPackaging;

public UpdateProviderGit(ServerInstance serverInstanceInstance, UpdateProviderGitConfiguration configuration, ILogger<UpdateProviderGit> logger, IConfiguration config)
{
_serverInstance = serverInstanceInstance;
Expand Down Expand Up @@ -142,7 +143,7 @@ private async Task GitResetToFetchHead(CancellationToken cancel = default)
private async Task TryClone(CancellationToken cancel = default)
{
_logger.LogTrace("Cloning git repository...");

if(Directory.Exists(_repoPath))
Directory.Delete(_repoPath, true);

Expand Down Expand Up @@ -251,9 +252,28 @@ public override async Task<bool> CheckForUpdateAsync(string? currentVersion, Can
var serverPackage = Path.Combine(_repoPath, "release", ServerZipName);
var serverPlatform = GetHostSS14RID();

// check for the new packaging system, else it will fallback to the old python one
if (Directory.Exists(Path.Combine(_repoPath, "Content.Packaging")))
{
_newPackaging = true;

await CommandHelperChecked("Failed to dotnet restore", _repoPath, "dotnet", new[] { "restore" }, cancel);

await CommandHelperChecked("Failed to build Content Packaging",
_repoPath, "dotnet", new[] { "build", "Content.Packaging","--configuration", "Release", "--no-restore", "/m" }, cancel);
}
else
_newPackaging = false;

if (_hybridACZ)
{
await CommandHelperChecked("Failed to build Hybrid ACZ package", _repoPath, "python", new[] {"Tools/package_server_build.py", "--hybrid-acz", "-p", serverPlatform}, cancel);
if (_newPackaging)
{
await CommandHelperChecked("Failed to build Hybrid ACZ package with Content Packaging",
_repoPath, "dotnet", new[] { "run", "--project", "Content.Packaging", "server", "--platform", serverPlatform, "--hybrid-acz" }, cancel);
}
else
await CommandHelperChecked("Failed to build Hybrid ACZ package with Python", _repoPath, "python", new[] {"Tools/package_server_build.py", "--hybrid-acz", "-p", serverPlatform}, cancel);
}
else
{
Expand All @@ -263,15 +283,28 @@ public override async Task<bool> CheckForUpdateAsync(string? currentVersion, Can
var binariesRoot = new Uri(new Uri(_configuration["BaseUrl"]!),
$"instances/{_serverInstance.Key}/binaries/");

_logger.LogTrace("Building client packages...");
_logger.LogTrace("Building server packages...");

if (_newPackaging)
{
await CommandHelperChecked("Failed to build server packages with Content Packaging",
_repoPath, "dotnet", new[] { "run", "--project", "Content.Packaging", "server", "--platform", serverPlatform}, cancel);
}
else
await CommandHelperChecked("Failed to build server packages with Python", _repoPath, "python", new[] {"Tools/package_server_build.py", "-p", serverPlatform}, cancel);

await CommandHelperChecked("Failed to build client packages", _repoPath, "python", new[] {"Tools/package_client_build.py"}, cancel);

File.Move(Path.Combine(_repoPath, "release", ClientZipName), Path.Combine(binariesPath, ClientZipName), true);
_logger.LogTrace("Building client packages...");

_logger.LogTrace("Building server packages...");
await CommandHelperChecked("Failed to build server packages", _repoPath, "python", new[] {"Tools/package_server_build.py", "-p", serverPlatform}, cancel);
if (_newPackaging)
{
await CommandHelperChecked("Failed to build client packages with Content Packaging",
_repoPath, "dotnet", new[] { "run", "--project", "Content.Packaging", "client", "--no-wipe-release"}, cancel);
}
else
await CommandHelperChecked("Failed to build client packages", _repoPath, "python", new[] {"Tools/package_client_build.py"}, cancel);

File.Move(Path.Combine(_repoPath, "release", ClientZipName), Path.Combine(binariesPath, ClientZipName), true);
// Unless using Hybrid ACZ, a build.json file must be written.
await using (var stream = File.Open(serverPackage, FileMode.Open))
{
Expand All @@ -296,7 +329,7 @@ public override async Task<bool> CheckForUpdateAsync(string? currentVersion, Can
}

_logger.LogTrace("Applying server update.");

if (Directory.Exists(binPath))
{
Directory.Delete(binPath, true);
Expand All @@ -322,7 +355,7 @@ public override async Task<bool> CheckForUpdateAsync(string? currentVersion, Can
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// chmod +x Robust.Server

var rsPath = Path.Combine(binPath, "Robust.Server");
if (File.Exists(rsPath))
{
Expand All @@ -332,7 +365,7 @@ public override async Task<bool> CheckForUpdateAsync(string? currentVersion, Can
FileAccessPermissions.OtherExecute;
}
}

// ReSharper disable once RedundantTypeArgumentsOfMethod
return actualConfirmedHead;
}
Expand All @@ -348,16 +381,16 @@ private class Build
{
[JsonPropertyName("download")]
public string Download { get; set; } = default!;

[JsonPropertyName("hash")]
public string Hash { get; set; } = default!;

[JsonPropertyName("version")]
public string Version { get; set; } = default!;

[JsonPropertyName("engine_version")]
public string EngineVersion { get; set; } = default!;

[JsonPropertyName("fork_id")]
public string ForkId { get; set; } = default!;
}
Expand Down

0 comments on commit 54454bb

Please sign in to comment.