From 54454bbb913d86f62c6adf9a86692c74339d4d7f Mon Sep 17 00:00:00 2001 From: Vasilis Date: Mon, 4 Dec 2023 00:25:04 +0100 Subject: [PATCH] Make the Git method use the new packeger if possible, else fallback to python (#25) --- .../Components/Updates/UpdateProviderGit.cs | 63 ++++++++++++++----- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/SS14.Watchdog/Components/Updates/UpdateProviderGit.cs b/SS14.Watchdog/Components/Updates/UpdateProviderGit.cs index 5c1a404..ec738ae 100644 --- a/SS14.Watchdog/Components/Updates/UpdateProviderGit.cs +++ b/SS14.Watchdog/Components/Updates/UpdateProviderGit.cs @@ -25,7 +25,8 @@ public class UpdateProviderGit : UpdateProvider private readonly ILogger _logger; private readonly string _repoPath; private readonly IConfiguration _configuration; - + private bool _newPackaging; + public UpdateProviderGit(ServerInstance serverInstanceInstance, UpdateProviderGitConfiguration configuration, ILogger logger, IConfiguration config) { _serverInstance = serverInstanceInstance; @@ -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); @@ -251,9 +252,28 @@ public override async Task 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 { @@ -263,15 +283,28 @@ public override async Task 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)) { @@ -296,7 +329,7 @@ public override async Task CheckForUpdateAsync(string? currentVersion, Can } _logger.LogTrace("Applying server update."); - + if (Directory.Exists(binPath)) { Directory.Delete(binPath, true); @@ -322,7 +355,7 @@ public override async Task CheckForUpdateAsync(string? currentVersion, Can RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { // chmod +x Robust.Server - + var rsPath = Path.Combine(binPath, "Robust.Server"); if (File.Exists(rsPath)) { @@ -332,7 +365,7 @@ public override async Task CheckForUpdateAsync(string? currentVersion, Can FileAccessPermissions.OtherExecute; } } - + // ReSharper disable once RedundantTypeArgumentsOfMethod return actualConfirmedHead; } @@ -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!; }