From e49598a9ce4f8ffc70431fe0c9e5749ff8a856df Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 30 Dec 2019 11:58:07 -0500 Subject: [PATCH] Build system fixes and cleanups --- build/Version.props | 7 + .../Tgstation.Server.Api.csproj | 24 +++- .../Tgstation.Server.Client.csproj | 13 +- .../Tgstation.Server.Host.Console.csproj | 5 +- .../GlobalSuppressions.cs | Bin 1284 -> 1316 bytes .../Properties/AssemblyInfo.cs | 12 +- .../Tgstation.Server.Host.Service.csproj | 133 ++++-------------- .../Tgstation.Server.Host.Watchdog.csproj | 3 +- .../Watchdog.cs | 52 +++---- .../ClientApp/package.json | 2 +- .../Controllers/AdministrationController.cs | 88 +++++++----- .../Core/TaskExtensions.cs | 52 +++++++ .../Tgstation.Server.Host.csproj | 12 +- .../Properties/AssemblyInfo.cs | 11 -- ...Tgstation.Server.Host.Service.Tests.csproj | 92 +++--------- tgstation-server.sln | 5 +- 16 files changed, 234 insertions(+), 277 deletions(-) create mode 100644 build/Version.props create mode 100644 src/Tgstation.Server.Host/Core/TaskExtensions.cs delete mode 100644 tests/Tgstation.Server.Host.Service.Tests/Properties/AssemblyInfo.cs diff --git a/build/Version.props b/build/Version.props new file mode 100644 index 0000000000..68a795b9da --- /dev/null +++ b/build/Version.props @@ -0,0 +1,7 @@ + + + 4.0.1.4 + 4.0.2 + 4.0.3.0 + + diff --git a/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj b/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj index ba131b26ce..f4a8f71249 100644 --- a/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj +++ b/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj @@ -1,8 +1,22 @@  + netstandard2.0 Full + true + Cyberboss + /tg/station + API definitions for tgstation-server + LICENSE + tgs.ico + https://tgstation.github.io/tgstation-server + Git + https://github.com/tgstation/tgstation-server + 2018 + json web api tgstation-server tgstation ss13 byond + Added ApiHeaders.RawUserAgent + $(TgsApiVersion) ../../build/analyzers.ruleset latest @@ -21,18 +35,16 @@ - - all - compile; build; native; contentfiles; analyzers - - + all runtime; build; native; contentfiles; analyzers - + + + diff --git a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj index 647a6ebe46..688664cfb2 100644 --- a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj +++ b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj @@ -1,9 +1,10 @@ - + + netstandard2.0 Full - 4.0.3.0 + $(TgsClientVersion) true Cyberboss /tg/station 13 @@ -13,8 +14,8 @@ https://github.com/tgstation/tgstation-server Git en-CA - https://raw.githubusercontent.com/tgstation/tgstation-server/master/build/tgs.ico - https://github.com/tgstation/tgstation-server/blob/master/LICENSE + LICENSE + tgs.ico json web api tgstation-server tgstation ss13 byond client Added the ability to change the Token of IServerClient 2018 @@ -40,7 +41,7 @@ compile; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers @@ -52,5 +53,7 @@ + + diff --git a/src/Tgstation.Server.Host.Console/Tgstation.Server.Host.Console.csproj b/src/Tgstation.Server.Host.Console/Tgstation.Server.Host.Console.csproj index c29a5d688d..507129668e 100644 --- a/src/Tgstation.Server.Host.Console/Tgstation.Server.Host.Console.csproj +++ b/src/Tgstation.Server.Host.Console/Tgstation.Server.Host.Console.csproj @@ -1,10 +1,11 @@ - + + Exe netcoreapp2.1 Full - 4.0.1.4 + $(TgsCoreVersion) ../../build/analyzers.ruleset latest diff --git a/src/Tgstation.Server.Host.Service/GlobalSuppressions.cs b/src/Tgstation.Server.Host.Service/GlobalSuppressions.cs index dfc5c7f3e33f5b0271aaee89d88c7f717670f142..40d2c0f8474b4042e237e7c8162d9491ae56ea9c 100644 GIT binary patch delta 42 vcmZqSTEex#j8RsHL4hHYp#(@KF%&VRG9)r&GZX`P#S9q?nVXFnFERrFzXS;( delta 12 TcmZ3&)xx#GjB#@q<2hyk8zlq( diff --git a/src/Tgstation.Server.Host.Service/Properties/AssemblyInfo.cs b/src/Tgstation.Server.Host.Service/Properties/AssemblyInfo.cs index 2b77d018db..d7c3dd8a1b 100644 --- a/src/Tgstation.Server.Host.Service/Properties/AssemblyInfo.cs +++ b/src/Tgstation.Server.Host.Service/Properties/AssemblyInfo.cs @@ -1,11 +1,3 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; -[assembly: AssemblyTitle("Tgstation.Server.Host.Service")] -[assembly: ComVisible(false)] -[assembly: Guid("29927416-3b78-49a7-a560-5ccaa638b6b4")] -[assembly: InternalsVisibleTo("Tgstation.Server.Host.Service.Tests")] - -[assembly: AssemblyVersion("4.0.1.4")] -[assembly: AssemblyFileVersion("4.0.1.4")] +[assembly:InternalsVisibleTo("Tgstation.Server.Host.Service.Tests")] diff --git a/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj b/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj index 6bd52c6f69..fc30494bf2 100644 --- a/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj +++ b/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj @@ -1,116 +1,45 @@ - - - + + + - Debug - AnyCPU - {29927416-3B78-49A7-A560-5CCAA638B6B4} - WinExe - Tgstation.Server.Host.Service - Tgstation.Server.Host.Service - v4.7.1 - 512 - true - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - latest - 4 + Exe + net471 + win + Full + $(TgsCoreVersion) ../../build/analyzers.ruleset - true - AnyCPU - prompt - + latest + bin\Debug\Tgstation.Server.Host.Console.xml - - true - full - false - bin\Debug\ - DEBUG;TRACE - bin\Debug\Tgstation.Server.Host.Service.xml - SA1101;SA1121;SA1200;SA1202;SA1208;SA1400;SA1413;SA1501;SA1503;SA1519;SA1520;SA1623;SA1629;SA1633;SA1642 - - - pdbonly - true - bin\Release\ - TRACE + + true - bin\Release\Tgstation.Server.Host.Service.xml - SA1101;SA1121;SA1200;SA1202;SA1208;SA1400;SA1413;SA1501;SA1503;SA1519;SA1520;SA1623;SA1629;SA1633;SA1642 + - - Tgstation.Server.Host.Service.Program - - - - ../../build/tgs.ico + + + 1701;1702;SA1652 + - - - - - Component - - - - - False - Microsoft .NET Framework 4.7.1 %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 - false - - - - - - - - - - - {5d2d682c-6bf0-439c-850b-6ab945bbeaea} - Tgstation.Server.Host.Watchdog - - - - - 2.2.5 - - - all - compile; build; native; contentfiles; analyzers - - - 2.1.1 - + + all runtime; build; native; contentfiles; analyzers + - - stylecop.json - + - - \ No newline at end of file + + + + + + + + + + diff --git a/src/Tgstation.Server.Host.Watchdog/Tgstation.Server.Host.Watchdog.csproj b/src/Tgstation.Server.Host.Watchdog/Tgstation.Server.Host.Watchdog.csproj index 6bd413819f..eaf7347e67 100644 --- a/src/Tgstation.Server.Host.Watchdog/Tgstation.Server.Host.Watchdog.csproj +++ b/src/Tgstation.Server.Host.Watchdog/Tgstation.Server.Host.Watchdog.csproj @@ -1,10 +1,11 @@ + netstandard2.0 Full false - 4.0.1.4 + $(TgsCoreVersion) ../../build/analyzers.ruleset latest diff --git a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs index 9fce44bfbf..9f72e17de5 100644 --- a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs @@ -29,6 +29,32 @@ namespace Tgstation.Server.Host.Watchdog this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); } + string GetDotnetPath(bool isWindows) + { + var enviromentPath = Environment.GetEnvironmentVariable("PATH"); + var paths = enviromentPath.Split(';'); + + var exeName = "dotnet"; + IEnumerable enumerator; + if (isWindows) + { + exeName += ".exe"; + enumerator = paths; + } + else + enumerator = paths.Select(x => x.Split(':')).SelectMany(x => x); + + enumerator = enumerator.Select(x => Path.Combine(x, exeName)); + + return enumerator + .Where(x => + { + logger.LogTrace("Checking for dotnet at {0}", x); + return File.Exists(x); + }) + .FirstOrDefault(); + } + /// #pragma warning disable CA1502 // TODO: Decomplexify public async Task RunAsync(bool runConfigure, string[] args, CancellationToken cancellationToken) @@ -38,30 +64,8 @@ namespace Tgstation.Server.Host.Watchdog string updateDirectory = null; try { - var enviromentPath = Environment.GetEnvironmentVariable("PATH"); - var paths = enviromentPath.Split(';'); var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - - var exeName = "dotnet"; - IEnumerable enumerator; - if (isWindows) - { - exeName += ".exe"; - enumerator = paths; - } - else - enumerator = paths.Select(x => x.Split(':')).SelectMany(x => x); - - enumerator = enumerator.Select(x => Path.Combine(x, exeName)); - - var dotnetPath = enumerator - .Where(x => - { - logger.LogTrace("Checking for dotnet at {0}", x); - return File.Exists(x); - }) - .FirstOrDefault(); - + var dotnetPath = GetDotnetPath(isWindows); if (dotnetPath == default) { logger.LogCritical("Unable to locate dotnet executable in PATH! Please ensure the .NET Core runtime is installed and is in your PATH!"); @@ -126,7 +130,7 @@ namespace Tgstation.Server.Host.Watchdog '"' + updateDirectory + '"' }; - if (Environment.GetCommandLineArgs().Any(x => x == "--attach-host-debugger")) + if (Environment.GetCommandLineArgs().Any(x => x.Equals("--attach-host-debugger", StringComparison.OrdinalIgnoreCase))) arguments.Add("--attach-debugger"); if (runConfigure) diff --git a/src/Tgstation.Server.Host/ClientApp/package.json b/src/Tgstation.Server.Host/ClientApp/package.json index fc8ab6e698..407902f50f 100644 --- a/src/Tgstation.Server.Host/ClientApp/package.json +++ b/src/Tgstation.Server.Host/ClientApp/package.json @@ -5,7 +5,7 @@ "tgstation-server-control-panel": "0.1.6" }, "scripts": { - "build": "npm run clean && tslint -p tsconfig.json && react-scripts build && cp-cli node_modules/tgstation-server-control-panel/build/public/ build/ && cp-cli ../../../build/tgs.ico build/favicon.ico && minify-json build && rimraf ../wwwroot && move-cli build ../wwwroot", + "msbuild": "npm run clean && tslint -p tsconfig.json && react-scripts build && cp-cli node_modules/tgstation-server-control-panel/build/public/ build/ && cp-cli ../../../build/tgs.ico build/favicon.ico && minify-json build && rimraf ../wwwroot && move-cli build ../wwwroot", "clean": "rimraf build" }, "devDependencies": { diff --git a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs index 605be61107..61198121f6 100644 --- a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs +++ b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs @@ -98,6 +98,58 @@ namespace Tgstation.Server.Host.Controllers return StatusCode(429); } + /// + /// Try to download and apply an update with a given . + /// + /// The version of the server to update to. + /// The for the operation. + /// A resulting in the of the operation. + async Task CheckReleasesAndApplyUpdate(Version newVersion, CancellationToken cancellationToken) + { + Logger.LogDebug("Looking for GitHub releases version {0}...", newVersion); + IEnumerable releases; + try + { + var gitHubClient = GetGitHubClient(); + releases = await gitHubClient + .Repository + .Release + .GetAll(updatesConfiguration.GitHubRepositoryId) + .WithToken(cancellationToken) + .ConfigureAwait(false); + } + catch (RateLimitExceededException e) + { + return RateLimit(e); + } + catch (ApiException e) + { + Logger.LogWarning(OctokitException, e); + return StatusCode((int)HttpStatusCode.FailedDependency); + } + + releases = releases.Where(x => x.TagName.StartsWith(updatesConfiguration.GitTagPrefix, StringComparison.InvariantCulture)); + + Logger.LogTrace("Release query complete!"); + + foreach (var release in releases) + if (Version.TryParse(release.TagName.Replace(updatesConfiguration.GitTagPrefix, String.Empty, StringComparison.Ordinal), out var version) && version == newVersion) + { + var asset = release.Assets.Where(x => x.Name.Equals(updatesConfiguration.UpdatePackageAssetName, StringComparison.Ordinal)).FirstOrDefault(); + if (asset == default) + continue; + + if (!serverUpdater.ApplyUpdate(version, new Uri(asset.BrowserDownloadUrl), ioManager)) + return Conflict(new ErrorMessage + { + Message = "An update operation is already in progress!" + }); + return Accepted(); // gtfo of here before all the cancellation tokens fire + } + + return StatusCode((int)HttpStatusCode.Gone); + } + IGitHubClient GetGitHubClient() => String.IsNullOrEmpty(generalConfiguration.GitHubAccessToken) ? gitHubClientFactory.CreateClient() : gitHubClientFactory.CreateClient(generalConfiguration.GitHubAccessToken); /// @@ -163,41 +215,7 @@ namespace Tgstation.Server.Host.Controllers Message = RestartNotSupportedException }); - Logger.LogDebug("Looking for GitHub releases version {0}...", model.NewVersion); - IEnumerable releases; - try - { - var gitHubClient = GetGitHubClient(); - releases = (await gitHubClient.Repository.Release.GetAll(updatesConfiguration.GitHubRepositoryId).ConfigureAwait(false)).Where(x => x.TagName.StartsWith(updatesConfiguration.GitTagPrefix, StringComparison.InvariantCulture)); - cancellationToken.ThrowIfCancellationRequested(); - } - catch (RateLimitExceededException e) - { - return RateLimit(e); - } - catch (ApiException e) - { - Logger.LogWarning(OctokitException, e); - return StatusCode((int)HttpStatusCode.FailedDependency); - } - - Logger.LogTrace("Release query complete!"); - foreach (var release in releases) - if (Version.TryParse(release.TagName.Replace(updatesConfiguration.GitTagPrefix, String.Empty, StringComparison.Ordinal), out var version) && version == model.NewVersion) - { - var asset = release.Assets.Where(x => x.Name == updatesConfiguration.UpdatePackageAssetName).FirstOrDefault(); - if (asset == default) - continue; - - if (!serverUpdater.ApplyUpdate(version, new Uri(asset.BrowserDownloadUrl), ioManager)) - return Conflict(new ErrorMessage - { - Message = "An update operation is already in progress!" - }); - return Accepted(); // gtfo of here before all the cancellation tokens fire - } - - return StatusCode((int)HttpStatusCode.Gone); + return await CheckReleasesAndApplyUpdate(model.NewVersion, cancellationToken).ConfigureAwait(false); } /// diff --git a/src/Tgstation.Server.Host/Core/TaskExtensions.cs b/src/Tgstation.Server.Host/Core/TaskExtensions.cs new file mode 100644 index 0000000000..fb1b825313 --- /dev/null +++ b/src/Tgstation.Server.Host/Core/TaskExtensions.cs @@ -0,0 +1,52 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Tgstation.Server.Host.Core +{ + /// + /// Extensions for the . + /// + static class TaskExtensions + { + /// + /// Create a that can be awaited while respecting a given . + /// + /// The to add cancel support to. + /// The for the operation. + /// A representing the running operation. + public static Task WithToken(this Task task, CancellationToken cancellationToken) + { + if (task == null) + throw new ArgumentNullException(nameof(task)); + + async Task Wrap() + { + await task.ConfigureAwait(false); + return null; + } + + return Wrap().WithToken(cancellationToken); + } + + /// + /// Create a that can be awaited while respecting a given . + /// + /// The result of the . + /// The to add cancel support to. + /// The for the operation. + /// A resulting in the result of . + public static async Task WithToken(this Task task, CancellationToken cancellationToken) + { + if (task == null) + throw new ArgumentNullException(nameof(task)); + + var cancelTcs = new TaskCompletionSource(); + using (cancellationToken.Register(() => cancelTcs.SetCanceled())) + await Task.WhenAny(task, cancelTcs.Task).ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); + + return await task.ConfigureAwait(false); + } + } +} diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index 199655af18..241f135433 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -1,9 +1,10 @@ - + + netcoreapp2.1 Full - 4.0.1.4 + $(TgsCoreVersion) latest ../../build/analyzers.ruleset @@ -15,7 +16,7 @@ - 1701;1702;SA1652 + 1701;1702;SA1652;CA1063 bin\Debug\netcoreapp2.1\Tgstation.Server.Host.xml @@ -36,11 +37,11 @@ - + - + @@ -97,7 +98,6 @@ - diff --git a/tests/Tgstation.Server.Host.Service.Tests/Properties/AssemblyInfo.cs b/tests/Tgstation.Server.Host.Service.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 0158cb9bbb..0000000000 --- a/tests/Tgstation.Server.Host.Service.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Tgstation.Server.Host.Service.Tests")] -[assembly: ComVisible(false)] - -[assembly: Guid("aa80a190-52e2-4be3-bfeb-1f148d9e9007")] - -[assembly: AssemblyVersion("4.0.0.0")] -[assembly: AssemblyFileVersion("4.0.0.0")] -[assembly: AssemblyInformationalVersion("4.0.0.0")] diff --git a/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj b/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj index a0327b8d0c..0c829771c4 100644 --- a/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj +++ b/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj @@ -1,81 +1,29 @@ - - + + - Debug - AnyCPU - {AA80A190-52E2-4BE3-BFEB-1F148D9E9007} - Library - Properties - Tgstation.Server.Host.Service.Tests - Tgstation.Server.Host.Service.Tests - v4.7.1 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest + net471 + + false latest - prompt - 4 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - - - pdbonly - true - bin\Release\ - TRACE + + + false + + + - - - - - - - - - - + + + + + - - + + - - - {29927416-3b78-49a7-a560-5ccaa638b6b4} - Tgstation.Server.Host.Service - - - {5d2d682c-6bf0-439c-850b-6ab945bbeaea} - Tgstation.Server.Host.Watchdog - - - - - 2.1.1 - - - 4.10.0 - - - 1.3.2 - - - 1.3.2 - - - - - \ No newline at end of file + + diff --git a/tgstation-server.sln b/tgstation-server.sln index 6c2a38cc3a..f77e1fe534 100644 --- a/tgstation-server.sln +++ b/tgstation-server.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2036 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29613.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DA32568D-1D8D-4A4C-9943-BFD3CE796B3F}" ProjectSection(SolutionItems) = preProject @@ -31,6 +31,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{6FF654E6 build\tgs.docker.sh = build\tgs.docker.sh build\tgs.ico = build\tgs.ico build\UploadCoverage.ps1 = build\UploadCoverage.ps1 + build\Version.props = build\Version.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tgstation.Server.Host", "src\Tgstation.Server.Host\Tgstation.Server.Host.csproj", "{2B69AD6D-2B5A-4023-8EAD-0BD1B18E028A}"