From 6960525688060df94f96d73bd6f9faa044b9c2ed Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 13 Sep 2022 18:41:18 -0400 Subject: [PATCH 01/10] Update to .net-6.0. Fix errors and warnings - Address various IDE messages - Additional logging - Do not access DB in Watchdog's actual Dispose - Fix issue with legacy behaviour in PGSQL - Remove obsolete dotnet workaround - Update to v3 actions checkout/upload-artifact/download-artifact --- .github/CONTRIBUTING.md | 4 +- .github/workflows/ci-suite.yml | 96 +++++++++---------- .github/workflows/codeql-analysis.yml | 2 +- .vscode/launch.json | 2 +- README.md | 4 +- build/Dockerfile | 15 +-- build/Version.props | 8 +- .../Tgstation.Server.Api.csproj | 4 - .../Tgstation.Server.Client.csproj | 4 - .../Properties/launchSettings.json | 4 +- .../Tgstation.Server.Host.Console.csproj | 11 +-- .../Tgstation.Server.Host.Service.csproj | 4 +- .../Tgstation.Server.Host.Watchdog.csproj | 4 +- .../Watchdog.cs | 2 +- .../.config/dotnet-tools.json | 2 +- .../Components/Byond/ByondInstallerBase.cs | 3 +- .../Components/Byond/ByondManager.cs | 7 +- .../Components/Byond/IByondInstaller.cs | 5 +- .../Chat/Providers/DiscordProvider.cs | 16 +++- .../Components/Instance.cs | 1 + .../Components/InstanceManager.cs | 1 + .../Components/README.md | 2 +- .../Repository/LibGit2RepositoryFactory.cs | 10 +- .../Components/StaticFiles/Configuration.cs | 4 +- .../Components/Watchdog/WatchdogBase.cs | 1 + .../Controllers/ApiController.cs | 2 +- .../Controllers/ByondController.cs | 4 +- .../Controllers/DreamDaemonController.cs | 2 + src/Tgstation.Server.Host/Core/Application.cs | 17 ++-- src/Tgstation.Server.Host/Core/README.md | 4 +- .../Database/DatabaseConnectionFactory.cs | 4 +- .../Database/MySqlDatabaseContext.cs | 26 ++--- .../Database/PostgresSqlDatabaseContext.cs | 2 + src/Tgstation.Server.Host/Dockerfile | 24 ----- .../IO/DefaultIOManager.cs | 62 ++++++++---- src/Tgstation.Server.Host/IO/IIOManager.cs | 4 +- .../IO/SynchronousIOManager.cs | 4 +- src/Tgstation.Server.Host/README.md | 4 +- .../Security/CryptographySuite.cs | 2 +- .../Security/WindowsSystemIdentity.cs | 2 + .../Security/WindowsSystemIdentityFactory.cs | 2 + src/Tgstation.Server.Host/Server.cs | 19 ++-- .../Setup/SetupApplication.cs | 10 +- .../Setup/SetupWizard.cs | 4 +- .../System/AssemblyInformationProvider.cs | 2 +- .../System/WindowsProcessFeatures.cs | 2 + .../Tgstation.Server.Host.csproj | 50 +++++----- .../Tgstation.Server.Api.Tests.csproj | 10 +- .../Tgstation.Server.Client.Tests.csproj | 14 +-- ...Tgstation.Server.Host.Console.Tests.csproj | 2 +- .../Program.cs | 1 - ...Tgstation.Server.Host.Tests.Signals.csproj | 4 +- .../Byond/TestPosixByondInstaller.cs | 9 +- .../Database/TestDatabaseConnectionFactory.cs | 6 +- .../System/TestPosixSignalHandler.cs | 2 +- .../System/TestProcessFeatures.cs | 8 +- .../TestProgram.cs | 5 +- .../Tgstation.Server.Host.Tests.csproj | 14 +-- ...gstation.Server.Host.Watchdog.Tests.csproj | 12 +-- .../Instance/ByondTest.cs | 9 +- .../Instance/WatchdogTest.cs | 3 +- .../Tgstation.Server.Tests/IntegrationTest.cs | 7 +- .../Tgstation.Server.Tests.csproj | 12 +-- tools/ReleaseNotes/ReleaseNotes.csproj | 4 +- 64 files changed, 303 insertions(+), 287 deletions(-) delete mode 100644 src/Tgstation.Server.Host/Dockerfile diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b322d8425b..79ee3f7ac3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -34,7 +34,7 @@ You can of course, as always, ask for help at [#coderbus](irc://irc.rizon.net/co ### Development Environment -You need the Dotnet 3.1 SDK and npm>=v5.7 (in your PATH) to compile the server. In order to build the service version you also need a .NET 4.7.1 build chain +You need the Dotnet 6.0 SDK and npm>=v5.7 (in your PATH) to compile the server. In order to build the service version you also need a .NET 4.7.1 build chain The recommended IDE is Visual Studio 2019 which has installation options for both of these. @@ -174,7 +174,7 @@ Whenever you make a change to a model schema that must be reflected in the datab We have a script to do this. 1. Run `build/GenerateMigrations.sh NameOfMigration` from the project root. -1. You should now have MY/MS migration files generated in `/src/Tgstation.Server.Host/Models/Migrations`. Fix compiler warnings in the generated files. Ensure all classes are in the Tgstation.Server.Host.Models.Migrations namespace. +1. You should now have MY/MS/SL/PG migration files generated in `/src/Tgstation.Server.Host/Models/Migrations`. Fix compiler warnings in the generated files. Ensure all classes are in the Tgstation.Server.Host.Database.Migrations namespace. 1. Manually review what each migration does. 1. Run the server in both configurations to ensure the migrations work. diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index e91cc39de5..d6d35fb3e8 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -1,4 +1,4 @@ -name: 'CI' +name: 'CI' on: push: @@ -11,7 +11,7 @@ on: - master env: - TGS_DOTNET_VERSION: 3.1.x + TGS_DOTNET_VERSION: 6.0.x TGS_TEST_DISCORD_CHANNEL: ${{ secrets.DISCORD_CHANNEL_ID }} TGS_TEST_DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} TGS_TEST_IRC_CHANNEL: ${{ secrets.IRC_CHANNEL }} @@ -46,7 +46,7 @@ jobs: exit 0 - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Build DMAPI Test Project run: | @@ -73,7 +73,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Patch Doxyfile run: | @@ -114,7 +114,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Upgrade NPM run: sudo npm install -g npm @@ -130,12 +130,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup dotnet - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: dotnet-version: ${{ env.TGS_DOTNET_VERSION }} - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Upgrade NPM run: sudo npm install -g npm @@ -147,7 +147,7 @@ jobs: run: sudo dotnet test tgstation-server.sln --no-build --filter FullyQualifiedName!~IntegrationTest -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }}NoService --collect:"XPlat Code Coverage" --settings build/coverlet.runsettings -r ./TestResults - name: Store Code Coverage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: linux-unit-test-coverage-${{ matrix.configuration }} path: ./TestResults/ @@ -160,19 +160,16 @@ jobs: runs-on: windows-latest steps: - name: Setup dotnet - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: dotnet-version: ${{ env.TGS_DOTNET_VERSION }} - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Upgrade NPM run: npm install -g npm - - name: Clean package cache as a temporary workaround for actions/setup-dotnet#155 - run: dotnet clean && dotnet nuget locals all --clear - - name: Build run: dotnet build -c ${{ matrix.configuration }} @@ -180,7 +177,7 @@ jobs: run: dotnet test tgstation-server.sln --no-build --filter FullyQualifiedName!~IntegrationTest -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }} --collect:"XPlat Code Coverage" --settings build/coverlet.runsettings -r ./TestResults - name: Store Code Coverage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: windows-unit-test-coverage-${{ matrix.configuration }} path: ./TestResults/ @@ -198,7 +195,7 @@ jobs: runs-on: windows-latest steps: - name: Setup dotnet - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: dotnet-version: ${{ env.TGS_DOTNET_VERSION }} @@ -216,7 +213,7 @@ jobs: echo "TGS_TEST_CONNECTION_STRING=$(echo $TGS_CONNSTRING_VALUE)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Set TGS_TEST_PULL_REQUEST_NUMBER if: ${{ github.event_name == 'pull_request' }} @@ -233,9 +230,6 @@ jobs: TEMP_GITHUB_REF="${{ github.event.ref }}" echo "TGS_GITHUB_REF=${TEMP_GITHUB_REF##*/}" >> $GITHUB_ENV - - name: Clean package cache as a temporary workaround for actions/setup-dotnet#155 - run: dotnet clean && dotnet nuget locals all --clear - - name: Run Integration Test run: | cd tests/Tgstation.Server.Tests @@ -243,14 +237,14 @@ jobs: dotnet test -c ${{ matrix.configuration }} -l "console;verbosity=detailed;noprogress=true" --collect:"XPlat Code Coverage" --settings ../../build/coverlet.runsettings -r ./TestResults - name: Store Code Coverage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: windows-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }} path: tests/Tgstation.Server.Tests/TestResults/ - name: Store OpenAPI Spec if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'System' }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: openapi-spec path: C:/swagger.json @@ -266,7 +260,7 @@ jobs: - name: Store Server Service if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'Basic' }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: ServerService path: Artifacts/Service/ @@ -333,7 +327,7 @@ jobs: run: npm install -g npm - name: Setup dotnet - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: dotnet-version: ${{ env.TGS_DOTNET_VERSION }} @@ -367,7 +361,7 @@ jobs: run: echo "General__UseBasicWatchdog=true" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Set TGS_TEST_PULL_REQUEST_NUMBER if: ${{ github.event_name == 'pull_request' }} @@ -391,7 +385,7 @@ jobs: dotnet test -c ${{ matrix.configuration }}NoService -l "console;verbosity=detailed;noprogress=true" --collect:"XPlat Code Coverage" --settings ../../build/coverlet.runsettings -r ./TestResults - name: Store Code Coverage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: linux-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }}-${{ matrix.database-type }} path: tests/Tgstation.Server.Tests/TestResults/ @@ -414,14 +408,14 @@ jobs: - name: Store Server Console if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'System' && matrix.database-type == 'MariaDB' }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: ServerConsole path: Artifacts/Console/ - name: Store Server Update Package if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'System' && matrix.database-type == 'PostgresSql' }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: ServerUpdatePackage path: Artifacts/ServerUpdate/ @@ -440,10 +434,10 @@ jobs: run: npm i -g ibm-openapi-validator@0.51.3 - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Retrieve OpenAPI Spec - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: openapi-spec path: ./swagger @@ -457,70 +451,70 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout for .codecov.yml - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Retrieve Linux Unit Test Coverage (Debug) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: linux-unit-test-coverage-Debug path: ./code_coverage/unit_tests/linux_unit_tests_debug - name: Retrieve Linux Unit Test Coverage (Release) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: linux-unit-test-coverage-Release path: ./code_coverage/unit_tests/linux_unit_tests_release - name: Retrieve Linux Integration Test Coverage (Release, System, Sqlite) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: linux-integration-test-coverage-Release-System-Sqlite path: ./code_coverage/integration_tests/linux_integration_tests_release_system_sqlite - name: Retrieve Linux Integration Test Coverage (Release, System, PostgresSql) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: linux-integration-test-coverage-Release-System-PostgresSql path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mariadb - name: Retrieve Linux Integration Test Coverage (Release, System, MariaDB) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: linux-integration-test-coverage-Release-System-MariaDB path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mysql - name: Retrieve Linux Integration Test Coverage (Release, System, MySql) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: linux-integration-test-coverage-Release-System-MySql path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mysql - name: Retrieve Windows Unit Test Coverage (Release) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: windows-unit-test-coverage-Release path: ./code_coverage/unit_tests/windows_unit_tests_release - name: Retrieve Windows Integration Test Coverage (Debug, Basic) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: windows-integration-test-coverage-Debug-Basic path: ./code_coverage/integration_tests/windows_integration_tests_debug_basic - name: Retrieve Windows Integration Test Coverage (Release, Basic) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: windows-integration-test-coverage-Release-Basic path: ./code_coverage/integration_tests/windows_integration_tests_release_basic - name: Retrieve Windows Integration Test Coverage (Debug, System) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: windows-integration-test-coverage-Debug-System path: ./code_coverage/integration_tests/windows_integration_tests_debug_system - name: Retrieve Windows Integration Test Coverage (Release, System) - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: windows-integration-test-coverage-Release-System path: ./code_coverage/integration_tests/windows_integration_tests_release_system @@ -546,7 +540,7 @@ jobs: if: github.event_name == 'push' && contains(github.event.head_commit.message, '[APIDeploy]') steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Parse API version shell: powershell @@ -556,7 +550,7 @@ jobs: echo "TGS_API_VERSION=$apiVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append - name: Retrieve OpenAPI Spec - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: openapi-spec path: swagger @@ -590,7 +584,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Parse DMAPI version shell: powershell @@ -632,12 +626,12 @@ jobs: if: github.event_name == 'push' && contains(github.event.head_commit.message, '[NugetDeploy]') steps: - name: Setup dotnet - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: dotnet-version: ${{ env.TGS_DOTNET_VERSION }} - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Publish API to NuGet uses: rohith/publish-nuget@v2 @@ -662,7 +656,7 @@ jobs: if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[TGSDeploy]') steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Parse TGS version shell: powershell @@ -672,25 +666,25 @@ jobs: echo "TGS_VERSION=$tgsVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append - name: Retrieve Server Service - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: ServerService path: ServerService - name: Retrieve Server Console - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: ServerConsole path: ServerConsole - name: Retrieve Server Update Package - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: ServerUpdatePackage path: ServerUpdatePackage - name: Retrieve OpenAPI Spec - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: openapi-spec path: swagger diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 4bd92dbf36..68cf5debb5 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -21,7 +21,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: 12.x - + - name: Upgrade NPM run: npm install -g npm diff --git a/.vscode/launch.json b/.vscode/launch.json index bdda61f946..fadbf977fe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/Tgstation.Server.Host/bin/Debug/netcoreapp3.1/Tgstation.Server.Host.dll", + "program": "${workspaceFolder}/src/Tgstation.Server.Host/bin/Debug/net6.0/Tgstation.Server.Host.dll", "args": [], "cwd": "${workspaceFolder}/src/Tgstation.Server.Host", // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window diff --git a/README.md b/README.md index f27b33273f..448bf76ab0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Older server versions can be found in the V# branches of this repository. Note t ### Pre-Requisites -- [ASP .NET Core Runtime (>= v3.1, < v5.0)](https://dotnet.microsoft.com/download/dotnet/3.1) (Choose the option to `Run Server Apps` for your system) If you plan to install tgstation-server as a Windows service, you should also ensure that your .NET Framework runtime version is >= v4.7.2 (Download can be found on same page). Ensure that the `dotnet` executable file is in your system's `PATH` variable (or that of the user's that will be running the server). +- [ASP .NET Core Runtime (>= v6.0)](https://dotnet.microsoft.com/download/dotnet/6.0) (Choose the option to `Run Server Apps` for your system) If you plan to install tgstation-server as a Windows service, you should also ensure that your .NET Framework runtime version is >= v4.7.2 (Download can be found on same page). Ensure that the `dotnet` executable file is in your system's `PATH` variable (or that of the user's that will be running the server). - A [MariaDB](https://downloads.mariadb.org/), MySQL, [PostgresSQL](https://www.postgresql.org/download/), or [Microsoft SQL Server](https://www.microsoft.com/en-us/download/details.aspx?id=55994) database engine is required ### Installation @@ -101,7 +101,7 @@ There are 3 primary supported ways to configure TGS: - Set environment variables in the form `Section__Subsection=value` or `Section__ArraySubsection__0=value` for arrays. - Set command line arguments in the form `--Section:Subsection=value` or `--Section:ArraySubsection:0=value` for arrays. -The latter two are not recommended as they cannot be dynamically changed at runtime. See more on ASP.NET core configuration [here](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1). +The latter two are not recommended as they cannot be dynamically changed at runtime. See more on ASP.NET core configuration [here](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0). #### Manual Configuration diff --git a/build/Dockerfile b/build/Dockerfile index 7b6227ab71..48113a8414 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,8 +1,8 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build +FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build # install node and npm # replace shell with bash so we can source files -RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | sh +RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | sh ENV NODE_VERSION 14.18.1 @@ -60,18 +60,21 @@ RUN dotnet publish -c Release -o /app WORKDIR /repo/src/Tgstation.Server.Host RUN dotnet publish -c Release -o /app/lib/Default && mv /app/lib/Default/appsettings* /app -FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim +FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim #needed for byond RUN apt-get update \ && apt-get install -y \ gcc-multilib \ gdb \ - multiarch-support \ - && rm -rf /var/lib/apt/lists/* \ + curl \ + && curl http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/multiarch-support_2.27-3ubuntu1_amd64.deb --output multiarch-support_2.27.deb \ && curl http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u12_amd64.deb --output libssl1.0.0.deb \ + && dpkg -i multiarch-support_2.27.deb \ && dpkg -i libssl1.0.0.deb \ - && rm libssl1.0.0.deb + && rm multiarch-support_2.27.deb \ + && rm libssl1.0.0.deb \ + && rm -rf /var/lib/apt/lists/* EXPOSE 5000 diff --git a/build/Version.props b/build/Version.props index 4daa5090a3..228610bf21 100644 --- a/build/Version.props +++ b/build/Version.props @@ -3,14 +3,14 @@ - 4.19.1 + 5.0.0 4.2.0 9.6.0 - 9.6.0 - 10.7.0 + 9.6.1 + 10.7.1 6.0.5 5.3.0 - 1.1.1 + 1.1.2 1.2.0 diff --git a/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj b/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj index af11456dbd..50dc84135f 100644 --- a/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj +++ b/src/Tgstation.Server.Api/Tgstation.Server.Api.csproj @@ -47,10 +47,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all diff --git a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj index 72003fcec5..a401b13200 100644 --- a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj +++ b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj @@ -32,10 +32,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Tgstation.Server.Host.Console/Properties/launchSettings.json b/src/Tgstation.Server.Host.Console/Properties/launchSettings.json index d8bde381e4..90a907e416 100644 --- a/src/Tgstation.Server.Host.Console/Properties/launchSettings.json +++ b/src/Tgstation.Server.Host.Console/Properties/launchSettings.json @@ -3,11 +3,11 @@ "Tgstation.Server.Host.Console": { "commandName": "Project", "commandLineArgs": "--attach-host-debugger", - "workingDirectory": "bin\\Debug\\netcoreapp3.1", + "workingDirectory": "bin\\Debug\\net6.0", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } -} \ No newline at end of file +} 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 74f2670231..b76c2bcc1c 100644 --- a/src/Tgstation.Server.Host.Console/Tgstation.Server.Host.Console.csproj +++ b/src/Tgstation.Server.Host.Console/Tgstation.Server.Host.Console.csproj @@ -3,7 +3,7 @@ Exe - netcoreapp3.1 + net6.0 Full $(TgsCoreVersion) ../../build/analyzers.ruleset @@ -15,19 +15,16 @@ true - bin\Release\netcoreapp3.1\Tgstation.Server.Host.Console.xml + bin\Release\net6.0\Tgstation.Server.Host.Console.xml 1701;1702;SA1652 - bin\Debug\netcoreapp3.1\Tgstation.Server.Host.Console.xml + bin\Debug\net6.0\Tgstation.Server.Host.Console.xml - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + all 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 4496a5fb0a..4e6e211a4a 100644 --- a/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj +++ b/src/Tgstation.Server.Host.Service/Tgstation.Server.Host.Service.csproj @@ -1,4 +1,4 @@ - + @@ -25,7 +25,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive 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 40777997cc..763e986d9d 100644 --- a/src/Tgstation.Server.Host.Watchdog/Tgstation.Server.Host.Watchdog.csproj +++ b/src/Tgstation.Server.Host.Watchdog/Tgstation.Server.Host.Watchdog.csproj @@ -24,12 +24,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs index 233b273375..0e6c9eaae2 100644 --- a/src/Tgstation.Server.Host.Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host.Watchdog/Watchdog.cs @@ -64,7 +64,7 @@ namespace Tgstation.Server.Host.Watchdog Directory.Delete(assemblyStoragePath, true); Directory.CreateDirectory(defaultAssemblyPath); - var sourcePath = "../../../../Tgstation.Server.Host/bin/Debug/netcoreapp3.1"; + var sourcePath = "../../../../Tgstation.Server.Host/bin/Debug/net6.0"; foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) Directory.CreateDirectory(dirPath.Replace(sourcePath, defaultAssemblyPath)); diff --git a/src/Tgstation.Server.Host/.config/dotnet-tools.json b/src/Tgstation.Server.Host/.config/dotnet-tools.json index 071984940d..9504514167 100644 --- a/src/Tgstation.Server.Host/.config/dotnet-tools.json +++ b/src/Tgstation.Server.Host/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-ef": { - "version": "3.1.20", + "version": "6.0.8", "commands": [ "dotnet-ef" ] diff --git a/src/Tgstation.Server.Host/Components/Byond/ByondInstallerBase.cs b/src/Tgstation.Server.Host/Components/Byond/ByondInstallerBase.cs index 234e017939..aa3dded775 100644 --- a/src/Tgstation.Server.Host/Components/Byond/ByondInstallerBase.cs +++ b/src/Tgstation.Server.Host/Components/Byond/ByondInstallerBase.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.IO; using System.Threading; using System.Threading.Tasks; @@ -79,7 +80,7 @@ namespace Tgstation.Server.Host.Components.Byond public abstract Task InstallByond(string path, Version version, CancellationToken cancellationToken); /// - public Task DownloadVersion(Version version, CancellationToken cancellationToken) + public Task DownloadVersion(Version version, CancellationToken cancellationToken) { if (version == null) throw new ArgumentNullException(nameof(version)); diff --git a/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs b/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs index 8d44d9439f..3df1720f51 100644 --- a/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs +++ b/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; +using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -326,8 +326,7 @@ namespace Tgstation.Server.Host.Components.Byond Stream downloadedStream = null; if (customVersionStream == null) { - var bytes = await byondInstaller.DownloadVersion(version, cancellationToken).ConfigureAwait(false); - downloadedStream = new MemoryStream(bytes); + downloadedStream = await byondInstaller.DownloadVersion(version, cancellationToken).ConfigureAwait(false); versionZipStream = downloadedStream; } else @@ -349,7 +348,7 @@ namespace Tgstation.Server.Host.Components.Byond cancellationToken) .ConfigureAwait(false); } - catch (WebException e) + catch (HttpRequestException e) { // since the user can easily provide non-exitent version numbers, we'll turn this into a JobException throw new JobException(ErrorCode.ByondDownloadFail, e); diff --git a/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs b/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs index 398796c482..ad1edcc08f 100644 --- a/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Byond/IByondInstaller.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Threading; using System.Threading.Tasks; @@ -29,8 +30,8 @@ namespace Tgstation.Server.Host.Components.Byond /// /// The of BYOND to download. /// The for the operation. - /// A resulting in the s of the zipfile. - Task DownloadVersion(Version version, CancellationToken cancellationToken); + /// A resulting in a of the zipfile. + Task DownloadVersion(Version version, CancellationToken cancellationToken); /// /// Does actions necessary to get an extracted BYOND installation working. diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs index 88755dc418..9940fdf0d4 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs @@ -11,9 +11,9 @@ using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Objects; -using Remora.Discord.Core; using Remora.Discord.Gateway; using Remora.Discord.Gateway.Extensions; +using Remora.Rest.Core; using Remora.Results; using Tgstation.Server.Api.Models; @@ -320,9 +320,17 @@ namespace Tgstation.Server.Host.Components.Chat.Providers return; } - var unmappedTextChannels = currentGuildsResponse - .Entity - .SelectMany(x => x.Channels.Value); + var guildsClient = serviceProvider.GetRequiredService(); + + var guildsChannelsTasks = currentGuildsResponse.Entity.Select( + guild => guildsClient.GetGuildChannelsAsync(guild.ID.Value, cancellationToken)); + + await Task.WhenAll(guildsChannelsTasks).ConfigureAwait(false); + + var unmappedTextChannels = guildsChannelsTasks + .Select(task => task.Result) + .SelectMany(guildChannels => guildChannels.Entity) + .Where(guildChannel => guildChannel.Type == ChannelType.GuildText); lock (mappedChannels) unmappedTextChannels = unmappedTextChannels diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs index 5cd8306ceb..893763829e 100644 --- a/src/Tgstation.Server.Host/Components/Instance.cs +++ b/src/Tgstation.Server.Host/Components/Instance.cs @@ -188,6 +188,7 @@ namespace Tgstation.Server.Host.Components { using (LogContext.PushProperty("Instance", metadata.Id)) { + logger.LogDebug("Stopping instance..."); await SetAutoUpdateInterval(0).ConfigureAwait(false); await Watchdog.StopAsync(cancellationToken).ConfigureAwait(false); await Task.WhenAll( diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index 001fc823ac..52898c8535 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -459,6 +459,7 @@ namespace Tgstation.Server.Host.Components { try { + logger.LogDebug("Stopping instance manager..."); var instanceFactoryStopTask = instanceFactory.StopAsync(cancellationToken); await jobManager.StopAsync(cancellationToken).ConfigureAwait(false); await Task.WhenAll(instances.Select(x => x.Value.Instance.StopAsync(cancellationToken))).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Components/README.md b/src/Tgstation.Server.Host/Components/README.md index ff311c3f00..b916892356 100644 --- a/src/Tgstation.Server.Host/Components/README.md +++ b/src/Tgstation.Server.Host/Components/README.md @@ -20,6 +20,6 @@ While the database represents stored instance data, in component code an instanc `IInstance`s are created via the [IInstanceFactory](./IInstanceFactory.cs) ([implementation](./InstanceFactory.cs)) and are generally controlled via the [IInstanceManager](./IInstanceManager.cs) ([implementation](./InstanceManager.cs)). -Many classes in here implement [IHostedService](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio), `InstanceManager` being the only one that is called by the ASP.NET runtime. In the case of instances `StartAsync()` is called when an `Instance` is being brought online (from server startup or user request). The `Instance` handles calling `StartAsync()` on its various subcomponents that need it. When an `Instance` is being brought offline (from server shutdown/restart/update or user request) the same pattern is followed calling `StopAsync()`. +Many classes in here implement [IHostedService](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-6.0&tabs=visual-studio), `InstanceManager` being the only one that is called by the ASP.NET runtime. In the case of instances `StartAsync()` is called when an `Instance` is being brought online (from server startup or user request). The `Instance` handles calling `StartAsync()` on its various subcomponents that need it. When an `Instance` is being brought offline (from server shutdown/restart/update or user request) the same pattern is followed calling `StopAsync()`. `IInstanceManager` is the sole point where the controllers talk to component code. It also dispatches bridge requests to their relevant instances. diff --git a/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs b/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs index 2c26a74fcf..3a6dcc8b7f 100644 --- a/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs +++ b/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs @@ -46,7 +46,7 @@ namespace Tgstation.Server.Host.Components.Repository var repo = await Task.Factory.StartNew( () => { - logger.LogTrace("Creating libgit2 repostory at {0}...", path); + logger.LogTrace("Creating libgit2 repostory at {repoPath}...", path); return new LibGit2Sharp.Repository(path); }, cancellationToken, @@ -63,7 +63,7 @@ namespace Tgstation.Server.Host.Components.Repository { try { - logger.LogTrace("Cloning {0} into {1}...", url, path); + logger.LogTrace("Cloning {repoUrl} into {repoPath}...", url, path); LibGit2Sharp.Repository.Clone(url.ToString(), path, cloneOptions); } catch (UserCancelledException ex) @@ -88,7 +88,11 @@ namespace Tgstation.Server.Host.Components.Repository var supportsUserPass = supportedCredentialTypes.HasFlag(SupportedCredentialTypes.UsernamePassword); var supportsAnonymous = supportedCredentialTypes.HasFlag(SupportedCredentialTypes.Default); - logger.LogTrace("Credentials requested. Present: {0}. Supports anonymous: {1}. Supports user/pass: {2}", hasCreds, supportsAnonymous, supportsUserPass); + logger.LogTrace( + "Credentials requested. Present: {credentialsPresent}. Supports anonymous: {credentialsSupportAnon}. Supports user/pass: {credentialsSupportUserPass}", + hasCreds, + supportsAnonymous, + supportsUserPass); if (supportsUserPass && hasCreds) return new UsernamePasswordCredentials { diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index ca75e5d396..79c5152523 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -261,9 +261,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles string GetFileSha() { var content = synchronousIOManager.ReadFile(path); -#pragma warning disable CA5350 // Do not use insecure cryptographic algorithm SHA1. - using var sha1 = new SHA1Managed(); -#pragma warning restore CA5350 // Do not use insecure cryptographic algorithm SHA1. + using var sha1 = SHA1.Create(); return String.Join(String.Empty, sha1.ComputeHash(content).Select(b => b.ToString("x2", CultureInfo.InvariantCulture))); } diff --git a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs index 5b6bf0729f..f6e7768750 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/WatchdogBase.cs @@ -245,6 +245,7 @@ namespace Tgstation.Server.Host.Components.Watchdog restartRegistration.Dispose(); // DCT: None available, Operation must always run + releaseServers = false; // Server release should have been handled in StopAsync, this causes a DB access that can create ObjectDisposedExceptions await DisposeAndNullControllers(default).ConfigureAwait(false); controllerDisposeSemaphore.Dispose(); monitorCts?.Dispose(); diff --git a/src/Tgstation.Server.Host/Controllers/ApiController.cs b/src/Tgstation.Server.Host/Controllers/ApiController.cs index d75245ab3f..850da06601 100644 --- a/src/Tgstation.Server.Host/Controllers/ApiController.cs +++ b/src/Tgstation.Server.Host/Controllers/ApiController.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Query.Internal; +using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; using Octokit; diff --git a/src/Tgstation.Server.Host/Controllers/ByondController.cs b/src/Tgstation.Server.Host/Controllers/ByondController.cs index e313991fb3..73239d9732 100644 --- a/src/Tgstation.Server.Host/Controllers/ByondController.cs +++ b/src/Tgstation.Server.Host/Controllers/ByondController.cs @@ -149,7 +149,7 @@ namespace Tgstation.Server.Host.Controllers if (!uploadingZip && byondManager.InstalledVersions.Any(x => x == model.Version)) { Logger.LogInformation( - "User ID {0} changing instance ID {1} BYOND version to {2}", + "User ID {userId} changing instance ID {instanceId} BYOND version to {newByondVersion}", AuthenticationContext.User.Id, Instance.Id, model.Version); @@ -164,7 +164,7 @@ namespace Tgstation.Server.Host.Controllers : model.Version; Logger.LogInformation( - "User ID {0} installing BYOND version to {1} on instance ID {2}", + "User ID {userId} installing BYOND version to {newByondVersion} on instance ID {instanceId}", AuthenticationContext.User.Id, installingVersion, Instance.Id); diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 47822a2744..da67d2926b 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -21,6 +21,8 @@ using Tgstation.Server.Host.Jobs; using Tgstation.Server.Host.Models; using Tgstation.Server.Host.Security; +#pragma warning disable API1001 // Action method returns a success result without a corresponding ProducesResponseType. Somehow this happens ONLY IN THIS CONTROLLER??? + namespace Tgstation.Server.Host.Controllers { /// diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 8d068ef97a..90dd5d4566 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -24,7 +24,6 @@ using Serilog.Events; using Serilog.Formatting.Display; using Tgstation.Server.Api; -using Tgstation.Server.Api.Models; using Tgstation.Server.Host.Components; using Tgstation.Server.Host.Components.Byond; using Tgstation.Server.Host.Components.Chat; @@ -296,6 +295,7 @@ namespace Tgstation.Server.Host.Core services.AddSingleton, PasswordHasher>(); // configure platform specific services +#pragma warning disable CA1416 // Validate platform compatibility if (postSetupServices.PlatformIdentifier.IsWindows) { AddWatchdog(services, postSetupServices); @@ -325,6 +325,7 @@ namespace Tgstation.Server.Host.Core services.AddSingleton(); } +#pragma warning restore CA1416 // Validate platform compatibility // configure component/misc services services.AddScoped(); @@ -392,8 +393,8 @@ namespace Tgstation.Server.Host.Core if (logger == null) throw new ArgumentNullException(nameof(logger)); - logger.LogDebug("Content Root: {0}", hostingEnvironment.ContentRootPath); - logger.LogTrace("Web Root: {0}", hostingEnvironment.WebRootPath); + logger.LogDebug("Content Root: {contentRoot}", hostingEnvironment.ContentRootPath); + logger.LogTrace("Web Root: {webRoot}", hostingEnvironment.WebRootPath); // attempt to restart the server if the configuration changes if (serverControl.WatchdogPresent) @@ -437,7 +438,7 @@ namespace Tgstation.Server.Host.Core } else if (controlPanelConfiguration.AllowedOrigins?.Count > 0) { - logger.LogTrace("Access-Control-Allow-Origin: {0}", String.Join(',', controlPanelConfiguration.AllowedOrigins)); + logger.LogTrace("Access-Control-Allow-Origin: {allowedOrigins}", String.Join(',', controlPanelConfiguration.AllowedOrigins)); corsBuilder = builder => builder.WithOrigins(controlPanelConfiguration.AllowedOrigins.ToArray()); } @@ -478,11 +479,11 @@ namespace Tgstation.Server.Host.Core // 404 anything that gets this far // End of request pipeline setup var masterVersionsAttribute = MasterVersionsAttribute.Instance; - logger.LogTrace("Configuration version: {0}", masterVersionsAttribute.RawConfigurationVersion); - logger.LogTrace("DMAPI Interop version: {0}", masterVersionsAttribute.RawInteropVersion); - logger.LogTrace("Web control panel version: {0}", masterVersionsAttribute.RawControlPanelVersion); + logger.LogTrace("Configuration version: {configVersion}", masterVersionsAttribute.RawConfigurationVersion); + logger.LogTrace("DMAPI Interop version: {interopVersion}", masterVersionsAttribute.RawInteropVersion); + logger.LogTrace("Web control panel version: {webCPVersion}", masterVersionsAttribute.RawControlPanelVersion); - logger.LogDebug("Starting hosting on port {0}...", serverPortProvider.HttpApiPort); + logger.LogDebug("Starting hosting on port {httpApiPort}...", serverPortProvider.HttpApiPort); } /// diff --git a/src/Tgstation.Server.Host/Core/README.md b/src/Tgstation.Server.Host/Core/README.md index 98dd325743..b19f4b0a8f 100644 --- a/src/Tgstation.Server.Host/Core/README.md +++ b/src/Tgstation.Server.Host/Core/README.md @@ -9,5 +9,5 @@ This is a bag of classes used throughout TGS that don't quite belong anywhere el - [IServerControl](./IServerControl.cs) is an interface used to initiate a restart or update the server. - [IServerPortProvider](./IServerPortProvider.cs) and [implementation](./ServerPortProvider.cs) is used by services to determine the local TGS API port. Used mainly for telling DreamDaemon where to make bridge requests. - [OpenApiEnumVarNamesExtension](./OpenApiEnumVarNamesExtension) implements the [x-var-names OpenAPI 3.0 extension](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/templating.md#enum) in our generated API json. -- [SemaphoreSlimContext](./SemaphoreSlimContext.cs) is a helper class for working with [.NET asynchronous sempahores](https://docs.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim?view=netcore-3.1). -- [SwaggerConfiguration](./SwaggerConfiguration.cs) configures [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) to generate our OpenAPI specification. \ No newline at end of file +- [SemaphoreSlimContext](./SemaphoreSlimContext.cs) is a helper class for working with [.NET asynchronous sempahores](https://docs.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim?view=netcore-6.0). +- [SwaggerConfiguration](./SwaggerConfiguration.cs) configures [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) to generate our OpenAPI specification. diff --git a/src/Tgstation.Server.Host/Database/DatabaseConnectionFactory.cs b/src/Tgstation.Server.Host/Database/DatabaseConnectionFactory.cs index 2d4299e4fa..b5ae17e41f 100644 --- a/src/Tgstation.Server.Host/Database/DatabaseConnectionFactory.cs +++ b/src/Tgstation.Server.Host/Database/DatabaseConnectionFactory.cs @@ -3,7 +3,9 @@ using System.Data.Common; using System.Data.SqlClient; using Microsoft.Data.Sqlite; -using MySql.Data.MySqlClient; + +using MySqlConnector; + using Npgsql; using Tgstation.Server.Host.Configuration; diff --git a/src/Tgstation.Server.Host/Database/MySqlDatabaseContext.cs b/src/Tgstation.Server.Host/Database/MySqlDatabaseContext.cs index 72ed93188d..60c3cf3fc9 100644 --- a/src/Tgstation.Server.Host/Database/MySqlDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Database/MySqlDatabaseContext.cs @@ -1,6 +1,7 @@ using System; using Microsoft.EntityFrameworkCore; + using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using Tgstation.Server.Host.Configuration; @@ -38,19 +39,22 @@ namespace Tgstation.Server.Host.Database if (databaseConfiguration.DatabaseType != DatabaseType.MariaDB && databaseConfiguration.DatabaseType != DatabaseType.MySql) throw new InvalidOperationException($"Invalid DatabaseType for {nameof(MySqlDatabaseContext)}!"); + ServerVersion serverVersion; + if (!String.IsNullOrEmpty(databaseConfiguration.ServerVersion)) + { + serverVersion = ServerVersion.Parse( + databaseConfiguration.ServerVersion, + databaseConfiguration.DatabaseType == DatabaseType.MariaDB + ? ServerType.MariaDb + : ServerType.MySql); + } + else + serverVersion = ServerVersion.AutoDetect(databaseConfiguration.ConnectionString); + options.UseMySql( databaseConfiguration.ConnectionString, - mySqlOptions => - { - mySqlOptions.EnableRetryOnFailure(); - - if (!String.IsNullOrEmpty(databaseConfiguration.ServerVersion)) - mySqlOptions.ServerVersion( - Version.Parse(databaseConfiguration.ServerVersion), - databaseConfiguration.DatabaseType == DatabaseType.MariaDB - ? ServerType.MariaDb - : ServerType.MySql); - }); + serverVersion, + mySqlOptions => mySqlOptions.EnableRetryOnFailure()); } } } diff --git a/src/Tgstation.Server.Host/Database/PostgresSqlDatabaseContext.cs b/src/Tgstation.Server.Host/Database/PostgresSqlDatabaseContext.cs index c5f68e0cc3..64654ef4cc 100644 --- a/src/Tgstation.Server.Host/Database/PostgresSqlDatabaseContext.cs +++ b/src/Tgstation.Server.Host/Database/PostgresSqlDatabaseContext.cs @@ -39,6 +39,8 @@ namespace Tgstation.Server.Host.Database if (databaseConfiguration.DatabaseType != DatabaseType.PostgresSql) throw new InvalidOperationException($"Invalid DatabaseType for {nameof(PostgresSqlDatabaseContext)}!"); + // Why the fuck is this an AppContext switch + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); options.UseNpgsql(databaseConfiguration.ConnectionString, options => { options.EnableRetryOnFailure(); diff --git a/src/Tgstation.Server.Host/Dockerfile b/src/Tgstation.Server.Host/Dockerfile deleted file mode 100644 index 3138161af8..0000000000 --- a/src/Tgstation.Server.Host/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. - -# THIS SHOULD NOT BE USED TO CREATE THE PRODUCTION BUILD IT'S FOR DEBUGGING ONLY - -FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base -WORKDIR /app -EXPOSE 80 - -FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build -WORKDIR /src -COPY ["src/Tgstation.Server.Host/Tgstation.Server.Host.csproj", "src/Tgstation.Server.Host/"] -COPY ["src/Tgstation.Server.Api/Tgstation.Server.Api.csproj", "src/Tgstation.Server.Api/"] -RUN dotnet restore "src/Tgstation.Server.Host/Tgstation.Server.Host.csproj" -COPY . . -WORKDIR "/src/src/Tgstation.Server.Host" -RUN dotnet build "Tgstation.Server.Host.csproj" -c Debug -o /app/build - -FROM build AS publish -RUN dotnet publish "Tgstation.Server.Host.csproj" -c Debug -o /app/publish - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Tgstation.Server.Host.dll"] diff --git a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs index 6f2d11c3f1..6a0edff7bb 100644 --- a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs +++ b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; -using System.Net; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Tgstation.Server.Host.System; + namespace Tgstation.Server.Host.IO { /// @@ -29,6 +31,11 @@ namespace Tgstation.Server.Host.IO /// public const TaskCreationOptions BlockingTaskCreationOptions = TaskCreationOptions.None; + /// + /// The for the . + /// + readonly IAssemblyInformationProvider assemblyInformationProvider; + /// /// Recursively empty a directory. /// @@ -64,6 +71,22 @@ namespace Tgstation.Server.Host.IO dir.Delete(true); } + /// + /// Initializes a new instance of the class. + /// + /// The value of . + public DefaultIOManager(IAssemblyInformationProvider assemblyInformationProvider) + { + this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider)); + } + + /// + /// Initializes a new instance of the class. + /// + protected DefaultIOManager() + { + } + /// public async Task CopyDirectory(string src, string dest, IEnumerable ignore, CancellationToken cancellationToken) { @@ -270,27 +293,26 @@ namespace Tgstation.Server.Host.IO TaskScheduler.Current); /// - public async Task DownloadFile(Uri url, CancellationToken cancellationToken) + public async Task DownloadFile(Uri url, CancellationToken cancellationToken) { - // DownloadDataTaskAsync can't be cancelled and is shittily written, don't use it - using var wc = new WebClient(); - var tcs = new TaskCompletionSource(); - wc.DownloadDataCompleted += (a, b) => + using var httpClient = new HttpClient(); + httpClient.DefaultRequestHeaders.UserAgent.Add(assemblyInformationProvider.ProductInfoHeaderValue); + var webRequestTask = httpClient.GetAsync(url, cancellationToken); + using var response = await webRequestTask.ConfigureAwait(false); + response.EnsureSuccessStatusCode(); + using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); + var memoryStream = new MemoryStream(); + try { - if (b.Error != null) - tcs.TrySetException(b.Error); - else if (b.Cancelled) - tcs.TrySetCanceled(); - else - tcs.TrySetResult(b.Result); - }; - wc.DownloadDataAsync(url); - using (cancellationToken.Register(() => + await responseStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false); + memoryStream.Seek(0, SeekOrigin.Begin); + return memoryStream; + } + catch { - wc.CancelAsync(); - tcs.TrySetCanceled(); - })) - return await tcs.Task.ConfigureAwait(false); + memoryStream.Dispose(); + throw; + } } /// @@ -332,7 +354,7 @@ namespace Tgstation.Server.Host.IO TaskScheduler.Current); /// - public FileStream GetFileStream(string path, bool shareWrite) => new FileStream( + public FileStream GetFileStream(string path, bool shareWrite) => new ( ResolvePath(path), FileMode.Open, FileAccess.Read, diff --git a/src/Tgstation.Server.Host/IO/IIOManager.cs b/src/Tgstation.Server.Host/IO/IIOManager.cs index 13b360d130..6f7dd75bbf 100644 --- a/src/Tgstation.Server.Host/IO/IIOManager.cs +++ b/src/Tgstation.Server.Host/IO/IIOManager.cs @@ -184,8 +184,8 @@ namespace Tgstation.Server.Host.IO /// /// The URL to download. /// A for the operation. - /// A resulting in the s of the downloaded file. - Task DownloadFile(Uri url, CancellationToken cancellationToken); + /// A resulting in a of the downloaded file. + Task DownloadFile(Uri url, CancellationToken cancellationToken); /// /// Extract a set of to a given . diff --git a/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs index cf076297cd..9d474a474f 100644 --- a/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs +++ b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs @@ -95,9 +95,7 @@ namespace Tgstation.Server.Host.IO return false; // suppressed due to only using for consistency checks -#pragma warning disable CA5350 // Do not use insecure cryptographic algorithm SHA1. - using (var sha1 = new SHA1Managed()) -#pragma warning restore CA5350 // Do not use insecure cryptographic algorithm SHA1. + using (var sha1 = SHA1.Create()) { string GetSha1(Stream dataToHash) => dataToHash != null && dataToHash.Length != 0 ? String.Join(String.Empty, sha1.ComputeHash(dataToHash).Select(b => b.ToString("x2", CultureInfo.InvariantCulture))) : null; var originalSha1 = GetSha1(file); diff --git a/src/Tgstation.Server.Host/README.md b/src/Tgstation.Server.Host/README.md index 5f1aeca63c..8730677035 100644 --- a/src/Tgstation.Server.Host/README.md +++ b/src/Tgstation.Server.Host/README.md @@ -12,8 +12,8 @@ Server startup can be a bit complicated so here's a walkthrough 1. `CreateServer()` is called on the `IServerFactory` to get the `IServer` instance. - The factory pattern is used throughout TGS to construct implementations where the composition root is not sufficient. `ServerFactory` is somewhat of an exception to this because it exists outside of the dependency injection umbrella. 1. Inside `CreateServer()` we run the [setup code](./Setup) if need be. - - This is implemented as a separate [dotnet host](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.1) to the main server. -1. Still inside `CreateServer()` we configure the main [dotnet host (IHostBuilder)](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.1) using the application [Application](./Core/Application.cs) class as the [Startup class](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-3.1#the-startup-class). + - This is implemented as a separate [dotnet host](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-6.0) to the main server. +1. Still inside `CreateServer()` we configure the main [dotnet host (IHostBuilder)](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-6.0) using the application [Application](./Core/Application.cs) class as the [Startup class](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-6.0#the-startup-class). 1. The `IHostBuilder` is used to construct the return `Server` implementation. 1. `Run()` is called on the `IServer` instance. 1. The DI container is built using the [Application](./Core/Application.cs) class. diff --git a/src/Tgstation.Server.Host/Security/CryptographySuite.cs b/src/Tgstation.Server.Host/Security/CryptographySuite.cs index 7ad8c61adb..27a780453e 100644 --- a/src/Tgstation.Server.Host/Security/CryptographySuite.cs +++ b/src/Tgstation.Server.Host/Security/CryptographySuite.cs @@ -33,7 +33,7 @@ namespace Tgstation.Server.Host.Security /// public byte[] GetSecureBytes(uint amount) { - using var rng = new RNGCryptoServiceProvider(); + using var rng = RandomNumberGenerator.Create(); // uses RNGCryptoServiceProvider under the hood https://khalidabuhakmeh.com/creating-random-numbers-with-dotnet-core var byt = new byte[amount]; rng.GetBytes(byt); return byt; diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs index 6c76bdb650..0d48cc62fc 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs @@ -1,5 +1,6 @@ using System; using System.DirectoryServices.AccountManagement; +using System.Runtime.Versioning; using System.Security.Principal; using System.Threading; using System.Threading.Tasks; @@ -11,6 +12,7 @@ namespace Tgstation.Server.Host.Security /// /// for windows systems. /// + [SupportedOSPlatform("windows")] sealed class WindowsSystemIdentity : ISystemIdentity { /// diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs index e183c720d8..78f74eb434 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs @@ -1,5 +1,6 @@ using System; using System.DirectoryServices.AccountManagement; +using System.Runtime.Versioning; using System.Security.Principal; using System.Threading; using System.Threading.Tasks; @@ -15,6 +16,7 @@ namespace Tgstation.Server.Host.Security /// /// for windows systems. Uses long running tasks due to potential networked domains. /// + [SupportedOSPlatform("windows")] sealed class WindowsSystemIdentityFactory : ISystemIdentityFactory { /// diff --git a/src/Tgstation.Server.Host/Server.cs b/src/Tgstation.Server.Host/Server.cs index a3ab5d3c42..b03c64bcad 100644 --- a/src/Tgstation.Server.Host/Server.cs +++ b/src/Tgstation.Server.Host/Server.cs @@ -132,6 +132,11 @@ namespace Tgstation.Server.Host await host.RunAsync(cancellationTokenSource.Token).ConfigureAwait(false); } } + catch (OperationCanceledException ex) + { + if (logger != null) + logger.LogDebug(ex, "Server run cancelled!"); + } catch (Exception ex) { CheckExceptionPropagation(ex); @@ -171,7 +176,7 @@ namespace Tgstation.Server.Host { try { - logger.LogInformation("Updating server to version {0} ({1})...", version, updateZipUrl); + logger.LogInformation("Updating server to version {version} ({zipUrl})...", version, updateZipUrl); if (cancellationTokenSource == null) throw new InvalidOperationException("Tried to update a non-running Server!"); @@ -185,11 +190,7 @@ namespace Tgstation.Server.Host try { logger.LogTrace("Downloading zip package..."); - updateZipData = new MemoryStream( - await ioManager.DownloadFile( - updateZipUrl, - cancellationToken) - .ConfigureAwait(false)); + updateZipData = await ioManager.DownloadFile(updateZipUrl, cancellationToken).ConfigureAwait(false); } catch (Exception e1) { @@ -216,7 +217,7 @@ namespace Tgstation.Server.Host try { - logger.LogTrace("Extracting zip package to {0}...", updatePath); + logger.LogTrace("Extracting zip package to {extractPath}...", updatePath); await ioManager.ZipToDirectory(updatePath, updateZipData, cancellationToken).ConfigureAwait(false); } catch (Exception e) @@ -267,7 +268,7 @@ namespace Tgstation.Server.Host lock (restartLock) if (!shutdownInProgress) { - logger.LogTrace("Registering restart handler {0}...", handler); + logger.LogTrace("Registering restart handler {handlerImplementationName}...", handler); restartHandlers.Add(handler); return new RestartRegistration(() => { @@ -331,7 +332,7 @@ namespace Tgstation.Server.Host // if the watchdog isn't required and there's no issue, this is just a graceful shutdown bool isGracefulShutdown = !requireWatchdog && exception == null; logger.LogTrace( - "Begin {0}...", + "Begin {restartType}...", isGracefulShutdown ? "graceful shutdown" : "restart"); diff --git a/src/Tgstation.Server.Host/Setup/SetupApplication.cs b/src/Tgstation.Server.Host/Setup/SetupApplication.cs index 9ab9a8256b..98b46c4e20 100644 --- a/src/Tgstation.Server.Host/Setup/SetupApplication.cs +++ b/src/Tgstation.Server.Host/Setup/SetupApplication.cs @@ -19,16 +19,16 @@ namespace Tgstation.Server.Host.Setup /// class SetupApplication { - /// - /// The for the . - /// - protected static readonly IIOManager IOManager = new DefaultIOManager(); - /// /// The for the . /// protected static readonly IAssemblyInformationProvider AssemblyInformationProvider = new AssemblyInformationProvider(); + /// + /// The for the . + /// + protected static readonly IIOManager IOManager = new DefaultIOManager(AssemblyInformationProvider); + /// /// The for the . /// diff --git a/src/Tgstation.Server.Host/Setup/SetupWizard.cs b/src/Tgstation.Server.Host/Setup/SetupWizard.cs index 0690e02050..2d1994782c 100644 --- a/src/Tgstation.Server.Host/Setup/SetupWizard.cs +++ b/src/Tgstation.Server.Host/Setup/SetupWizard.cs @@ -15,7 +15,9 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using MySql.Data.MySqlClient; + +using MySqlConnector; + using Npgsql; using Tgstation.Server.Host.Configuration; diff --git a/src/Tgstation.Server.Host/System/AssemblyInformationProvider.cs b/src/Tgstation.Server.Host/System/AssemblyInformationProvider.cs index 115ad60ba8..b2462fc64a 100644 --- a/src/Tgstation.Server.Host/System/AssemblyInformationProvider.cs +++ b/src/Tgstation.Server.Host/System/AssemblyInformationProvider.cs @@ -25,7 +25,7 @@ namespace Tgstation.Server.Host.System public string VersionString { get; } /// - public ProductInfoHeaderValue ProductInfoHeaderValue => new ProductInfoHeaderValue( + public ProductInfoHeaderValue ProductInfoHeaderValue => new ( VersionPrefix, Version.ToString()); diff --git a/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs b/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs index 81fd20217f..1657fcbd50 100644 --- a/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs +++ b/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Management; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -16,6 +17,7 @@ using Tgstation.Server.Host.Jobs; namespace Tgstation.Server.Host.System { /// + [SupportedOSPlatform("windows")] sealed class WindowsProcessFeatures : IProcessFeatures { /// diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index ca41829846..9fb2673dfd 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -2,16 +2,16 @@ - netcoreapp3.1 + net6.0 Full $(TgsCoreVersion) latest ../../build/analyzers.ruleset false true - bin\$(Configuration)\netcoreapp3.1\Tgstation.Server.Host.xml + bin\$(Configuration)\net6.0\Tgstation.Server.Host.xml true - API1000,IDE0004 + API1000 @@ -35,7 +35,7 @@ - + @@ -69,41 +69,37 @@ - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + - - - - - - + + + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - - - + + + + diff --git a/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj b/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj index b2d545340b..f4de4dd7e9 100644 --- a/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj +++ b/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj @@ -1,21 +1,21 @@  - netcoreapp3.1 + net6.0 false latest - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj b/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj index c1b0d91af7..36ce37ced8 100644 --- a/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj +++ b/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj @@ -1,21 +1,21 @@ - + - netcoreapp3.1 + net6.0 false latest - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj b/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj index 0048170d0c..3951c22c4e 100644 --- a/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj +++ b/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net6.0 false latest diff --git a/tests/Tgstation.Server.Host.Tests.Signals/Program.cs b/tests/Tgstation.Server.Host.Tests.Signals/Program.cs index 180ca55408..34b8c9e5de 100644 --- a/tests/Tgstation.Server.Host.Tests.Signals/Program.cs +++ b/tests/Tgstation.Server.Host.Tests.Signals/Program.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Mono.Unix.Native; using Moq; using Tgstation.Server.Host.Core; diff --git a/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj b/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj index f83dcb3bf1..0bce7cc3aa 100644 --- a/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj +++ b/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net6.0 Exe false @@ -9,7 +9,7 @@ - + diff --git a/tests/Tgstation.Server.Host.Tests/Components/Byond/TestPosixByondInstaller.cs b/tests/Tgstation.Server.Host.Tests/Components/Byond/TestPosixByondInstaller.cs index c73d8aa050..bef06618b2 100644 --- a/tests/Tgstation.Server.Host.Tests/Components/Byond/TestPosixByondInstaller.cs +++ b/tests/Tgstation.Server.Host.Tests/Components/Byond/TestPosixByondInstaller.cs @@ -1,7 +1,8 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; +using System.IO; using System.Threading.Tasks; using Tgstation.Server.Host.IO; @@ -21,7 +22,7 @@ namespace Tgstation.Server.Host.Components.Byond.Tests Assert.ThrowsException(() => new PosixByondInstaller(mockPostWriteHandler.Object, mockIOManager.Object, null)); var mockLogger = new Mock>(); - new PosixByondInstaller(mockPostWriteHandler.Object, mockIOManager.Object, mockLogger.Object); + _ = new PosixByondInstaller(mockPostWriteHandler.Object, mockIOManager.Object, mockLogger.Object); } [TestMethod] @@ -46,11 +47,11 @@ namespace Tgstation.Server.Host.Components.Byond.Tests await Assert.ThrowsExceptionAsync(() => installer.DownloadVersion(null, default)).ConfigureAwait(false); var ourArray = Array.Empty(); - mockIOManager.Setup(x => x.DownloadFile(It.Is(uri => uri == new Uri("https://secure.byond.com/download/build/511/511.1385_byond_linux.zip")), default)).Returns(Task.FromResult(ourArray)).Verifiable(); + mockIOManager.Setup(x => x.DownloadFile(It.Is(uri => uri == new Uri("https://secure.byond.com/download/build/511/511.1385_byond_linux.zip")), default)).Returns(Task.FromResult(new MemoryStream(ourArray))).Verifiable(); var result = await installer.DownloadVersion(new Version(511, 1385), default).ConfigureAwait(false); - Assert.AreSame(ourArray, result); + Assert.AreSame(ourArray, result.ToArray()); mockIOManager.Verify(); } diff --git a/tests/Tgstation.Server.Host.Tests/Database/TestDatabaseConnectionFactory.cs b/tests/Tgstation.Server.Host.Tests/Database/TestDatabaseConnectionFactory.cs index 76d5f2683a..3ebd02a56c 100644 --- a/tests/Tgstation.Server.Host.Tests/Database/TestDatabaseConnectionFactory.cs +++ b/tests/Tgstation.Server.Host.Tests/Database/TestDatabaseConnectionFactory.cs @@ -1,5 +1,7 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using MySql.Data.MySqlClient; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using MySqlConnector; + using System; using System.Data.SqlClient; diff --git a/tests/Tgstation.Server.Host.Tests/System/TestPosixSignalHandler.cs b/tests/Tgstation.Server.Host.Tests/System/TestPosixSignalHandler.cs index bab768b6a8..c816b44041 100644 --- a/tests/Tgstation.Server.Host.Tests/System/TestPosixSignalHandler.cs +++ b/tests/Tgstation.Server.Host.Tests/System/TestPosixSignalHandler.cs @@ -57,7 +57,7 @@ namespace Tgstation.Server.Host.System.Tests processExecutor = new ProcessExecutor( new PosixProcessFeatures( new Lazy(() => processExecutor), - new DefaultIOManager(), + new DefaultIOManager(new AssemblyInformationProvider()), loggerFactory.CreateLogger()), loggerFactory.CreateLogger(), loggerFactory); diff --git a/tests/Tgstation.Server.Host.Tests/System/TestProcessFeatures.cs b/tests/Tgstation.Server.Host.Tests/System/TestProcessFeatures.cs index d3ac6aaab0..ae205ffaec 100644 --- a/tests/Tgstation.Server.Host.Tests/System/TestProcessFeatures.cs +++ b/tests/Tgstation.Server.Host.Tests/System/TestProcessFeatures.cs @@ -1,8 +1,8 @@ -using Castle.Core.Logging; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Tgstation.Server.Host.IO; @@ -20,9 +20,9 @@ namespace Tgstation.Server.Host.System.Tests [TestInitialize] public void Init() { - features = new PlatformIdentifier().IsWindows + features = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (IProcessFeatures)new WindowsProcessFeatures(Mock.Of>()) - : new PosixProcessFeatures(new Lazy(() => null), new DefaultIOManager(), Mock.Of>()); + : new PosixProcessFeatures(new Lazy(() => null), new DefaultIOManager(new AssemblyInformationProvider()), Mock.Of>()); } [TestMethod] diff --git a/tests/Tgstation.Server.Host.Tests/TestProgram.cs b/tests/Tgstation.Server.Host.Tests/TestProgram.cs index cbeabc011e..776cde8dc9 100644 --- a/tests/Tgstation.Server.Host.Tests/TestProgram.cs +++ b/tests/Tgstation.Server.Host.Tests/TestProgram.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.IO; @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.IO; +using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Tests { @@ -70,7 +71,7 @@ namespace Tgstation.Server.Host.Tests mockServer.Setup(x => x.Run(It.IsAny())).Throws(exception); mockServer.SetupGet(x => x.RestartRequested).Returns(true); var mockServerFactory = new Mock(); - mockServerFactory.SetupGet(x => x.IOManager).Returns(new DefaultIOManager()); + mockServerFactory.SetupGet(x => x.IOManager).Returns(new DefaultIOManager(new AssemblyInformationProvider())); mockServerFactory.Setup(x => x.CreateServer(It.IsNotNull(), It.IsAny(), It.IsAny())).ReturnsAsync(mockServer.Object); Program.ServerFactory = mockServerFactory.Object; diff --git a/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj b/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj index 849ee940f7..009d63ee6c 100644 --- a/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj +++ b/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj @@ -1,21 +1,21 @@ - + - netcoreapp3.1 + net6.0 false latest - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj b/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj index 239f423803..6c3a4ff601 100644 --- a/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj +++ b/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net6.0 false latest @@ -14,14 +14,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/tests/Tgstation.Server.Tests/Instance/ByondTest.cs b/tests/Tgstation.Server.Tests/Instance/ByondTest.cs index 1c9c715816..cc04f114e0 100644 --- a/tests/Tgstation.Server.Tests/Instance/ByondTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/ByondTest.cs @@ -20,7 +20,7 @@ namespace Tgstation.Server.Tests.Instance { sealed class ByondTest : JobsRequiredTest { - public static readonly Version TestVersion = new Version(513, 1536); + public static readonly Version TestVersion = new (513, 1536); readonly IByondClient byondClient; @@ -90,16 +90,15 @@ namespace Tgstation.Server.Tests.Instance var byondInstaller = new PlatformIdentifier().IsWindows ? (IByondInstaller)new WindowsByondInstaller( Mock.Of(), - new DefaultIOManager(), + new DefaultIOManager(new AssemblyInformationProvider()), Mock.Of>()) : new PosixByondInstaller( Mock.Of(), - new DefaultIOManager(), + new DefaultIOManager(new AssemblyInformationProvider()), Mock.Of>()); // get the bytes for stable - using var stableBytesMs = new MemoryStream( - await byondInstaller.DownloadVersion(TestVersion, cancellationToken)); + using var stableBytesMs = await byondInstaller.DownloadVersion(TestVersion, cancellationToken); var test = await byondClient.SetActiveVersion( new ByondVersionRequest diff --git a/tests/Tgstation.Server.Tests/Instance/WatchdogTest.cs b/tests/Tgstation.Server.Tests/Instance/WatchdogTest.cs index 2551be345f..fd40f18149 100644 --- a/tests/Tgstation.Server.Tests/Instance/WatchdogTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/WatchdogTest.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -228,7 +229,7 @@ namespace Tgstation.Server.Tests.Instance using var ddProc = ddProcs.Single(); IProcessExecutor executor = null; executor = new ProcessExecutor( - new PlatformIdentifier().IsWindows + RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (IProcessFeatures)new WindowsProcessFeatures(Mock.Of>()) : new PosixProcessFeatures(new Lazy(() => executor), Mock.Of(), Mock.Of>()), Mock.Of>(), diff --git a/tests/Tgstation.Server.Tests/IntegrationTest.cs b/tests/Tgstation.Server.Tests/IntegrationTest.cs index fa0d2c3e3b..dd87211580 100644 --- a/tests/Tgstation.Server.Tests/IntegrationTest.cs +++ b/tests/Tgstation.Server.Tests/IntegrationTest.cs @@ -826,9 +826,10 @@ namespace Tgstation.Server.Tests { // Dump swagger to disk // This is purely for CI - var webRequest = WebRequest.Create(server.Url.ToString() + "swagger/v1/swagger.json"); - using var response = webRequest.GetResponse(); - using var content = response.GetResponseStream(); + using var httpClient = new HttpClient(); + var webRequestTask = httpClient.GetAsync(server.Url.ToString() + "swagger/v1/swagger.json"); + using var response = await webRequestTask; + using var content = await response.Content.ReadAsStreamAsync(); using var output = new FileStream(@"C:\swagger.json", FileMode.Create); await content.CopyToAsync(output); } diff --git a/tests/Tgstation.Server.Tests/Tgstation.Server.Tests.csproj b/tests/Tgstation.Server.Tests/Tgstation.Server.Tests.csproj index d2ac1d3319..9e691a9a5d 100644 --- a/tests/Tgstation.Server.Tests/Tgstation.Server.Tests.csproj +++ b/tests/Tgstation.Server.Tests/Tgstation.Server.Tests.csproj @@ -1,21 +1,21 @@  - netcoreapp3.1 + net6.0 false latest - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/tools/ReleaseNotes/ReleaseNotes.csproj b/tools/ReleaseNotes/ReleaseNotes.csproj index b0fc22da50..58f1201eb0 100644 --- a/tools/ReleaseNotes/ReleaseNotes.csproj +++ b/tools/ReleaseNotes/ReleaseNotes.csproj @@ -2,12 +2,12 @@ Exe - netcoreapp3.1 + net6.0 latest - + From 59afcf04dafb963191dba3e30a789352798c1b95 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 13 Sep 2022 20:55:31 -0400 Subject: [PATCH 02/10] Migrate to codecov-action@v3 --- .github/workflows/ci-suite.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index d6d35fb3e8..2cd8eb4e0a 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -520,14 +520,14 @@ jobs: path: ./code_coverage/integration_tests/windows_integration_tests_release_system - name: Upload Unit Test Coverage to CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: directory: ./code_coverage/unit_tests flags: unittests fail_ci_if_error: true - name: Upload Integration Test Coverage to CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: directory: ./code_coverage/integration_tests flags: integration From 8434db9f8024a1b4a5492b674e7ebc33e372b867 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 14 Sep 2022 18:21:06 -0400 Subject: [PATCH 03/10] Cleanup coverlet.runsettings --- build/coverlet.runsettings | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/coverlet.runsettings b/build/coverlet.runsettings index 783e8323cc..8c93320207 100644 --- a/build/coverlet.runsettings +++ b/build/coverlet.runsettings @@ -2,9 +2,8 @@ - + - opencover false From 6368c8339f3d6f236321f4a064e3178cfb44d1b6 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 14 Sep 2022 20:12:05 -0400 Subject: [PATCH 04/10] Try removing IncludeTestAssembly --- build/coverlet.runsettings | 1 - 1 file changed, 1 deletion(-) diff --git a/build/coverlet.runsettings b/build/coverlet.runsettings index 8c93320207..669f849d06 100644 --- a/build/coverlet.runsettings +++ b/build/coverlet.runsettings @@ -4,7 +4,6 @@ - false From 4bb600c82c37f7b5e178e3db4dbdb690cd9f58a1 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 15 Sep 2022 20:21:02 -0400 Subject: [PATCH 05/10] Try modified coveralls action --- .codecov.yml | 9 --- .github/workflows/ci-suite.yml | 131 +++++++++------------------------ build/coverlet.runsettings | 2 + 3 files changed, 35 insertions(+), 107 deletions(-) delete mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 6f6f55798a..0000000000 --- a/.codecov.yml +++ /dev/null @@ -1,9 +0,0 @@ -coverage: - status: - project: - default: - target: auto - threshold: 3% - patch: off -comment: - layout: "header, diff, changes" diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index 2cd8eb4e0a..ccddce963b 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -125,6 +125,7 @@ jobs: linux-unit-tests: name: Linux Unit Tests strategy: + fail-fast: false matrix: configuration: [ 'Debug', 'Release' ] runs-on: ubuntu-latest @@ -146,15 +147,18 @@ jobs: - name: Run Unit Tests run: sudo dotnet test tgstation-server.sln --no-build --filter FullyQualifiedName!~IntegrationTest -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }}NoService --collect:"XPlat Code Coverage" --settings build/coverlet.runsettings -r ./TestResults - - name: Store Code Coverage - uses: actions/upload-artifact@v3 + - name: Coveralls Upload + uses: Cyberboss/coveralls-action@master with: - name: linux-unit-test-coverage-${{ matrix.configuration }} - path: ./TestResults/ + github-token: ${{ secrets.github_token }} + path-to-lcov: ./TestResults/**/coverage.info + flag-name: linux-unit-test-coverage-${{ matrix.configuration }} + parallel: true windows-unit-tests: name: Windows Unit Tests strategy: + fail-fast: false matrix: configuration: [ 'Release' ] runs-on: windows-latest @@ -176,11 +180,13 @@ jobs: - name: Run Unit Tests run: dotnet test tgstation-server.sln --no-build --filter FullyQualifiedName!~IntegrationTest -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }} --collect:"XPlat Code Coverage" --settings build/coverlet.runsettings -r ./TestResults - - name: Store Code Coverage - uses: actions/upload-artifact@v3 + - name: Coveralls Upload + uses: coverallsapp/github-action@master with: - name: windows-unit-test-coverage-${{ matrix.configuration }} - path: ./TestResults/ + github-token: ${{ secrets.github_token }} + path-to-lcov: ./TestResults/**/coverage.info + flag-name: windows-unit-test-coverage-${{ matrix.configuration }} + parallel: true windows-integration-test: name: Windows Integration Test @@ -189,6 +195,7 @@ jobs: TGS_TEST_DATABASE_TYPE: SqlServer TGS_TEST_DUMP_API_SPEC: yes strategy: + fail-fast: false matrix: watchdog-type: [ 'Basic', 'System' ] configuration: [ 'Debug', 'Release' ] @@ -236,11 +243,13 @@ jobs: Start-Sleep -Seconds 10 dotnet test -c ${{ matrix.configuration }} -l "console;verbosity=detailed;noprogress=true" --collect:"XPlat Code Coverage" --settings ../../build/coverlet.runsettings -r ./TestResults - - name: Store Code Coverage - uses: actions/upload-artifact@v3 + - name: Coveralls Upload + uses: coverallsapp/github-action@master with: - name: windows-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }} - path: tests/Tgstation.Server.Tests/TestResults/ + github-token: ${{ secrets.github_token }} + path-to-lcov: ./TestResults/**/coverage.info + flag-name: windows-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }} + parallel: true - name: Store OpenAPI Spec if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'System' }} @@ -303,6 +312,7 @@ jobs: --health-timeout=5s --health-retries=3 strategy: + fail-fast: false matrix: database-type: [ 'Sqlite', 'PostgresSql', 'MariaDB', 'MySql' ] watchdog-type: [ 'System' ] @@ -384,11 +394,13 @@ jobs: sleep 10 dotnet test -c ${{ matrix.configuration }}NoService -l "console;verbosity=detailed;noprogress=true" --collect:"XPlat Code Coverage" --settings ../../build/coverlet.runsettings -r ./TestResults - - name: Store Code Coverage - uses: actions/upload-artifact@v3 + - name: Coveralls Upload + uses: coverallsapp/github-action@master with: - name: linux-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }}-${{ matrix.database-type }} - path: tests/Tgstation.Server.Tests/TestResults/ + github-token: ${{ secrets.github_token }} + path-to-lcov: ./TestResults/**/coverage.info + flag-name: linux-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }}-${{ matrix.database-type }} + parallel: true - name: Package Server Console if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'System' && matrix.database-type == 'MariaDB' }} @@ -446,92 +458,15 @@ jobs: run: npx lint-openapi -v -p -c build/OpenApiValidationSettings.json ./swagger/swagger.json upload-code-coverage: - name: Upload Code Coverage + name: Complete Code Coverage Upload needs: [linux-unit-tests, linux-integration-tests, windows-unit-tests, windows-integration-test] runs-on: ubuntu-latest steps: - - name: Checkout for .codecov.yml - uses: actions/checkout@v3 - - - name: Retrieve Linux Unit Test Coverage (Debug) - uses: actions/download-artifact@v3 + - name: Coveralls Finished + uses: coverallsapp/github-action@master with: - name: linux-unit-test-coverage-Debug - path: ./code_coverage/unit_tests/linux_unit_tests_debug - - - name: Retrieve Linux Unit Test Coverage (Release) - uses: actions/download-artifact@v3 - with: - name: linux-unit-test-coverage-Release - path: ./code_coverage/unit_tests/linux_unit_tests_release - - - name: Retrieve Linux Integration Test Coverage (Release, System, Sqlite) - uses: actions/download-artifact@v3 - with: - name: linux-integration-test-coverage-Release-System-Sqlite - path: ./code_coverage/integration_tests/linux_integration_tests_release_system_sqlite - - - name: Retrieve Linux Integration Test Coverage (Release, System, PostgresSql) - uses: actions/download-artifact@v3 - with: - name: linux-integration-test-coverage-Release-System-PostgresSql - path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mariadb - - - name: Retrieve Linux Integration Test Coverage (Release, System, MariaDB) - uses: actions/download-artifact@v3 - with: - name: linux-integration-test-coverage-Release-System-MariaDB - path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mysql - - - name: Retrieve Linux Integration Test Coverage (Release, System, MySql) - uses: actions/download-artifact@v3 - with: - name: linux-integration-test-coverage-Release-System-MySql - path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mysql - - - name: Retrieve Windows Unit Test Coverage (Release) - uses: actions/download-artifact@v3 - with: - name: windows-unit-test-coverage-Release - path: ./code_coverage/unit_tests/windows_unit_tests_release - - - name: Retrieve Windows Integration Test Coverage (Debug, Basic) - uses: actions/download-artifact@v3 - with: - name: windows-integration-test-coverage-Debug-Basic - path: ./code_coverage/integration_tests/windows_integration_tests_debug_basic - - - name: Retrieve Windows Integration Test Coverage (Release, Basic) - uses: actions/download-artifact@v3 - with: - name: windows-integration-test-coverage-Release-Basic - path: ./code_coverage/integration_tests/windows_integration_tests_release_basic - - - name: Retrieve Windows Integration Test Coverage (Debug, System) - uses: actions/download-artifact@v3 - with: - name: windows-integration-test-coverage-Debug-System - path: ./code_coverage/integration_tests/windows_integration_tests_debug_system - - - name: Retrieve Windows Integration Test Coverage (Release, System) - uses: actions/download-artifact@v3 - with: - name: windows-integration-test-coverage-Release-System - path: ./code_coverage/integration_tests/windows_integration_tests_release_system - - - name: Upload Unit Test Coverage to CodeCov - uses: codecov/codecov-action@v3 - with: - directory: ./code_coverage/unit_tests - flags: unittests - fail_ci_if_error: true - - - name: Upload Integration Test Coverage to CodeCov - uses: codecov/codecov-action@v3 - with: - directory: ./code_coverage/integration_tests - flags: integration - fail_ci_if_error: true + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true deploy-http: name: Deploy HTTP API diff --git a/build/coverlet.runsettings b/build/coverlet.runsettings index 669f849d06..ba6d10346e 100644 --- a/build/coverlet.runsettings +++ b/build/coverlet.runsettings @@ -4,6 +4,8 @@ + lcov + false From 9d7db1bc7816931412a3ae12571d9710b9ef3f5a Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 15 Sep 2022 20:21:58 -0400 Subject: [PATCH 06/10] Merge Code Scanning into CI Suit --- .github/workflows/ci-suite.yml | 34 ++++++++++++++++++++++ .github/workflows/codeql-analysis.yml | 42 --------------------------- 2 files changed, 34 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index ccddce963b..9fbffa2c25 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -20,6 +20,40 @@ env: TGS_RELEASE_NOTES_TOKEN: ${{ secrets.DEV_PUSH_TOKEN }} jobs: + analyze: + name: Code Scanning + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: ['csharp'] + + steps: + - name: Install Node 12.X + uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Upgrade NPM + run: npm install -g npm + + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 2 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 + dmapi-build: name: Build DMAPI env: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 68cf5debb5..0000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: "Code Scanning" - -on: - push: - branches: [dev, master] - pull_request: - branches: [dev, master] - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: ['csharp'] - - steps: - - name: Install Node 12.X - uses: actions/setup-node@v1 - with: - node-version: 12.x - - - name: Upgrade NPM - run: npm install -g npm - - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 From 44bdbd4ca384595e8e129e6dd11a3e9cd13d2b9c Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 15 Sep 2022 20:23:59 -0400 Subject: [PATCH 07/10] Cleanup bad matricies --- .github/workflows/ci-suite.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index 9fbffa2c25..24950be773 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -23,12 +23,6 @@ jobs: analyze: name: Code Scanning runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: ['csharp'] - steps: - name: Install Node 12.X uses: actions/setup-node@v1 @@ -46,7 +40,7 @@ jobs: - name: Initialize CodeQL uses: github/codeql-action/init@v2 with: - languages: ${{ matrix.language }} + languages: csharp - name: Autobuild uses: github/codeql-action/autobuild@v1 @@ -194,7 +188,7 @@ jobs: strategy: fail-fast: false matrix: - configuration: [ 'Release' ] + configuration: [ 'Debug', 'Release' ] runs-on: windows-latest steps: - name: Setup dotnet From dd8cb3e2168ae6e382d6bbea6737a4971fdb0175 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 15 Sep 2022 20:29:13 -0400 Subject: [PATCH 08/10] Update tags for various CI actions --- .github/workflows/ci-suite.yml | 20 ++++++++++---------- .github/workflows/stable-merge.yml | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index 24950be773..9198293d45 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Node 12.X - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 12.x @@ -33,7 +33,7 @@ jobs: run: npm install -g npm - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 2 @@ -43,10 +43,10 @@ jobs: languages: csharp - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 dmapi-build: name: Build DMAPI @@ -357,7 +357,7 @@ jobs: sudo apt-get install -y -o APT::Immediate-Configure=0 libc6-i386 libstdc++6:i386 gdb - name: Install Node 12.X - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 12.x @@ -466,7 +466,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Node 12.X - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 12.x @@ -597,7 +597,7 @@ jobs: uses: actions/checkout@v3 - name: Publish API to NuGet - uses: rohith/publish-nuget@v2 + uses: brandedoutcast/publish-nuget@v2 with: PROJECT_FILE_PATH: src/Tgstation.Server.Api/Tgstation.Server.Api.csproj TAG_COMMIT: false @@ -605,7 +605,7 @@ jobs: NUGET_KEY: ${{ secrets.NUGET_API_KEY }} - name: Publish Client to NuGet - uses: rohith/publish-nuget@v2 + uses: brandedoutcast/publish-nuget@v2 with: PROJECT_FILE_PATH: src/Tgstation.Server.Client/Tgstation.Server.Client.csproj TAG_COMMIT: false @@ -730,7 +730,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Parse TGS version run: | @@ -739,7 +739,7 @@ jobs: echo "TGS_VERSION=$(xmlstarlet sel -N X="http://schemas.microsoft.com/developer/msbuild/2003" --template --value-of /X:Project/X:PropertyGroup/X:TgsCoreVersion build/Version.props)" >> $GITHUB_ENV - name: Docker Build and Push - uses: elgohr/Publish-Docker-Github-Action@master + uses: elgohr/Publish-Docker-Github-Action@v4 with: name: tgstation/server username: ${{ secrets.DOCKER_USERNAME }} diff --git a/.github/workflows/stable-merge.yml b/.github/workflows/stable-merge.yml index e70a60b577..3f905ab1e4 100644 --- a/.github/workflows/stable-merge.yml +++ b/.github/workflows/stable-merge.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Merge master into dev uses: robotology/gh-action-nightly-merge@v1.3.3 From af618943935301af874e38740e5d84bbe49d7066 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 15 Sep 2022 20:36:50 -0400 Subject: [PATCH 09/10] Back to CodeCov --- .codecov.yml | 9 +++ .github/workflows/ci-suite.yml | 120 +++++++++++++++++++++++++-------- 2 files changed, 100 insertions(+), 29 deletions(-) create mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000000..6f6f55798a --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,9 @@ +coverage: + status: + project: + default: + target: auto + threshold: 3% + patch: off +comment: + layout: "header, diff, changes" diff --git a/.github/workflows/ci-suite.yml b/.github/workflows/ci-suite.yml index 9198293d45..eb013f6126 100644 --- a/.github/workflows/ci-suite.yml +++ b/.github/workflows/ci-suite.yml @@ -175,13 +175,11 @@ jobs: - name: Run Unit Tests run: sudo dotnet test tgstation-server.sln --no-build --filter FullyQualifiedName!~IntegrationTest -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }}NoService --collect:"XPlat Code Coverage" --settings build/coverlet.runsettings -r ./TestResults - - name: Coveralls Upload - uses: Cyberboss/coveralls-action@master + - name: Store Code Coverage + uses: actions/upload-artifact@v3 with: - github-token: ${{ secrets.github_token }} - path-to-lcov: ./TestResults/**/coverage.info - flag-name: linux-unit-test-coverage-${{ matrix.configuration }} - parallel: true + name: linux-unit-test-coverage-${{ matrix.configuration }} + path: ./TestResults/ windows-unit-tests: name: Windows Unit Tests @@ -208,13 +206,11 @@ jobs: - name: Run Unit Tests run: dotnet test tgstation-server.sln --no-build --filter FullyQualifiedName!~IntegrationTest -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }} --collect:"XPlat Code Coverage" --settings build/coverlet.runsettings -r ./TestResults - - name: Coveralls Upload - uses: coverallsapp/github-action@master + - name: Store Code Coverage + uses: actions/upload-artifact@v3 with: - github-token: ${{ secrets.github_token }} - path-to-lcov: ./TestResults/**/coverage.info - flag-name: windows-unit-test-coverage-${{ matrix.configuration }} - parallel: true + name: windows-unit-test-coverage-${{ matrix.configuration }} + path: ./TestResults/ windows-integration-test: name: Windows Integration Test @@ -271,13 +267,11 @@ jobs: Start-Sleep -Seconds 10 dotnet test -c ${{ matrix.configuration }} -l "console;verbosity=detailed;noprogress=true" --collect:"XPlat Code Coverage" --settings ../../build/coverlet.runsettings -r ./TestResults - - name: Coveralls Upload - uses: coverallsapp/github-action@master + - name: Store Code Coverage + uses: actions/upload-artifact@v3 with: - github-token: ${{ secrets.github_token }} - path-to-lcov: ./TestResults/**/coverage.info - flag-name: windows-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }} - parallel: true + name: windows-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }} + path: tests/Tgstation.Server.Tests/TestResults/ - name: Store OpenAPI Spec if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'System' }} @@ -422,13 +416,11 @@ jobs: sleep 10 dotnet test -c ${{ matrix.configuration }}NoService -l "console;verbosity=detailed;noprogress=true" --collect:"XPlat Code Coverage" --settings ../../build/coverlet.runsettings -r ./TestResults - - name: Coveralls Upload - uses: coverallsapp/github-action@master + - name: Store Code Coverage + uses: actions/upload-artifact@v3 with: - github-token: ${{ secrets.github_token }} - path-to-lcov: ./TestResults/**/coverage.info - flag-name: linux-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }}-${{ matrix.database-type }} - parallel: true + name: linux-integration-test-coverage-${{ matrix.configuration }}-${{ matrix.watchdog-type }}-${{ matrix.database-type }} + path: tests/Tgstation.Server.Tests/TestResults/ - name: Package Server Console if: ${{ matrix.configuration == 'Release' && matrix.watchdog-type == 'System' && matrix.database-type == 'MariaDB' }} @@ -486,15 +478,85 @@ jobs: run: npx lint-openapi -v -p -c build/OpenApiValidationSettings.json ./swagger/swagger.json upload-code-coverage: - name: Complete Code Coverage Upload + name: Upload Code Coverage needs: [linux-unit-tests, linux-integration-tests, windows-unit-tests, windows-integration-test] runs-on: ubuntu-latest steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master + - name: Checkout for .codecov.yml + uses: actions/checkout@v3 + + - name: Retrieve Linux Unit Test Coverage (Debug) + uses: actions/download-artifact@v3 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - parallel-finished: true + name: linux-unit-test-coverage-Debug + path: ./code_coverage/unit_tests/linux_unit_tests_debug + + - name: Retrieve Linux Unit Test Coverage (Release) + uses: actions/download-artifact@v3 + with: + name: linux-unit-test-coverage-Release + path: ./code_coverage/unit_tests/linux_unit_tests_release + + - name: Retrieve Linux Integration Test Coverage (Release, System, Sqlite) + uses: actions/download-artifact@v3 + with: + name: linux-integration-test-coverage-Release-System-Sqlite + path: ./code_coverage/integration_tests/linux_integration_tests_release_system_sqlite + + - name: Retrieve Linux Integration Test Coverage (Release, System, PostgresSql) + uses: actions/download-artifact@v3 + with: + name: linux-integration-test-coverage-Release-System-PostgresSql + path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mariadb + + - name: Retrieve Linux Integration Test Coverage (Release, System, MariaDB) + uses: actions/download-artifact@v3 + with: + name: linux-integration-test-coverage-Release-System-MariaDB + path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mysql + + - name: Retrieve Linux Integration Test Coverage (Release, System, MySql) + uses: actions/download-artifact@v3 + with: + name: linux-integration-test-coverage-Release-System-MySql + path: ./code_coverage/integration_tests/linux_integration_tests_release_system_mysql + + - name: Retrieve Windows Unit Test Coverage (Release) + uses: actions/download-artifact@v3 + with: + name: windows-unit-test-coverage-Release + path: ./code_coverage/unit_tests/windows_unit_tests_release + + - name: Retrieve Windows Integration Test Coverage (Debug, Basic) + uses: actions/download-artifact@v3 + with: + name: windows-integration-test-coverage-Debug-Basic + path: ./code_coverage/integration_tests/windows_integration_tests_debug_basic + + - name: Retrieve Windows Integration Test Coverage (Release, Basic) + uses: actions/download-artifact@v3 + with: + name: windows-integration-test-coverage-Release-Basic + path: ./code_coverage/integration_tests/windows_integration_tests_release_basic + + - name: Retrieve Windows Integration Test Coverage (Debug, System) + uses: actions/download-artifact@v3 + with: + name: windows-integration-test-coverage-Debug-System + path: ./code_coverage/integration_tests/windows_integration_tests_debug_system + + - name: Retrieve Windows Integration Test Coverage (Release, System) + uses: actions/download-artifact@v3 + with: + name: windows-integration-test-coverage-Release-System + path: ./code_coverage/integration_tests/windows_integration_tests_release_system + + - name: Upload Coverage to CodeCov + uses: codecov/codecov-action@v3 + with: + directory: ./code_coverage + fail_ci_if_error: true + deploy-http: name: Deploy HTTP API From 28829fafbdb5d4addae247cc2cbcacde8ce48b86 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Fri, 16 Sep 2022 11:03:04 -0400 Subject: [PATCH 10/10] Round of package updates --- .../Tgstation.Server.Host.csproj | 16 ++++++++-------- .../Tgstation.Server.Host.Console.Tests.csproj | 10 +++++----- .../Tgstation.Server.Host.Service.Tests.csproj | 8 ++++---- .../Tgstation.Server.Host.Tests.Signals.csproj | 2 +- tools/ReleaseNotes/ReleaseNotes.csproj | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index 9fb2673dfd..079d76fe2c 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -69,19 +69,19 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - + @@ -99,7 +99,7 @@ - + diff --git a/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj b/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj index 3951c22c4e..8578ea3810 100644 --- a/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj +++ b/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj @@ -8,14 +8,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + 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 4223f1f549..53762c51f3 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 @@ -14,13 +14,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj b/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj index 0bce7cc3aa..047a98ec03 100644 --- a/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj +++ b/tests/Tgstation.Server.Host.Tests.Signals/Tgstation.Server.Host.Tests.Signals.csproj @@ -10,7 +10,7 @@ - + diff --git a/tools/ReleaseNotes/ReleaseNotes.csproj b/tools/ReleaseNotes/ReleaseNotes.csproj index 58f1201eb0..6c05dd6101 100644 --- a/tools/ReleaseNotes/ReleaseNotes.csproj +++ b/tools/ReleaseNotes/ReleaseNotes.csproj @@ -7,7 +7,7 @@ - +