Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Git method use the new packeger if possible, else fallback to python #25

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 48 additions & 15 deletions SS14.Watchdog/Components/Updates/UpdateProviderGit.cs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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<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
{
@@ -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))
{
@@ -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);
@@ -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))
{
@@ -332,7 +365,7 @@ public override async Task<bool> 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!;
}

Unchanged files with check annotations Beta

}
catch (OperationCanceledException)
{
_logger.LogInformation("{Key} did not gracefully shut down in time, killing");

Check warning on line 390 in SS14.Watchdog/Components/ServerManagement/ServerInstance.cs

GitHub Actions / build

Number of parameters supplied in the logging message template do not match the number of named placeholders (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017)

Check warning on line 390 in SS14.Watchdog/Components/ServerManagement/ServerInstance.cs

GitHub Actions / build

Number of parameters supplied in the logging message template do not match the number of named placeholders (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017)
proc.Kill();
}