Single file publish support, test project and simple build CI

This also adds remote raspberry pi debugging with default install details. More testing is required as MonoMod may not be working for arm64 still

CI might not work yet either
This commit is contained in:
Luke 2021-12-03 00:07:11 +10:00
parent c159f2b388
commit 2c36dacfd2
8 changed files with 241 additions and 29 deletions

39
.github/workflows/ci-otapi3.yml vendored Normal file
View file

@ -0,0 +1,39 @@
name: CI(OTAPI3)
on: [push]
jobs:
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.100'
- name: MonoMod dev build
run: dotnet nuget add source https://pkgs.dev.azure.com/MonoMod/MonoMod/_packaging/DevBuilds%40Local/nuget/v3/index.json -n DevBuilds@Local
- name: Run tests
run: dotnet test
build:
runs-on: windows-latest
strategy:
matrix:
arch: ["win-x64", "osx-x64", "linux-x64", "linux-arm64", "linux-arm"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.100'
- name: MonoMod dev build
run: dotnet nuget add source https://pkgs.dev.azure.com/MonoMod/MonoMod/_packaging/DevBuilds%40Local/nuget/v3/index.json -n DevBuilds@Local
- name: Produce build
run: dotnet publish -r ${{ matrix.mode }} -f net6.0 -c Release -p:PublishSingleFile=true --self-contained true

66
.vscode/launch.json vendored
View file

@ -9,9 +9,12 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TShockAPI/bin/Debug/net5.0/TerrariaServerAPI.dll",
"program": "${workspaceFolder}/TShockLauncher/bin/Debug/net6.0/TShock.Run.dll",
"windows": {
"program": "${workspaceFolder}/TShockLauncher/bin/Debug/net6.0/TShock.dll",
},
"args": [],
"cwd": "${workspaceFolder}/TShockAPI/bin/Debug/net5.0/",
"cwd": "${workspaceFolder}/TShockLauncher/bin/Debug/net6.0/",
"console": "integratedTerminal",
"stopAtEntry": false
},
@ -19,6 +22,65 @@
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
},
{
// this command assumes you have:
// raspberry pi 4 b with default user/pass, SSH enabled & connected to a reliable connection
// dotnet sdk 6.0.100 (needed for breakpoints to hit)
// windows with putty installed
// vsdbg
// follow this for other OS's: https://docs.microsoft.com/en-us/dotnet/iot/debugging?tabs=self-contained&pivots=vscode
// TODO: ability to chmod +x TShock.sh && chmod +x bin/TShock.Run
"name": ".NET Remote Launch - Self-contained",
"type": "coreclr",
"request": "launch",
"program": "/home/pi/dotnet/dotnet",
"args": [
"bin/TShock.Run.dll"
],
"cwd": "/home/pi/tshockdev/publish",
"stopAtEntry": false,
"console": "integratedTerminal",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "C:\\Program Files\\PuTTY\\PLINK.EXE",
"pipeArgs": [
"-pw",
"raspberry",
"pi@raspberrypi"
],
"debuggerPath": "/home/pi/vsdbg/vsdbg"
}
},
{
// this command assumes you have:
// raspberry pi 4 b with default user/pass, SSH enabled & connected to a reliable connection
// dotnet sdk 6.0.100 (needed for breakpoints to hit)
// windows with putty installed
// vsdbg
// follow this for other OS's: https://docs.microsoft.com/en-us/dotnet/iot/debugging?tabs=self-contained&pivots=vscode
// TODO: ability to chmod +x TShock.sh && chmod +x bin/TShock.Run
"name": ".NET Remote Publish & Launch - Self-contained",
"type": "coreclr",
"request": "launch",
"program": "/home/pi/dotnet/dotnet",
"args": [
"bin/TShock.Run.dll"
],
"cwd": "/home/pi/tshockdev/publish",
"stopAtEntry": false,
"console": "integratedTerminal",
"preLaunchTask": "Remote Publish",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "C:\\Program Files\\PuTTY\\PLINK.EXE",
"pipeArgs": [
"-pw",
"raspberry",
"pi@raspberrypi"
],
"debuggerPath": "/home/pi/vsdbg/vsdbg"
}
}
]
}

39
.vscode/tasks.json vendored
View file

@ -12,6 +12,45 @@
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "Publish",
"options": {
"cwd": "TShockLauncher"
},
"command": "dotnet",
"type": "process",
"args": [
"publish",
"-c",
"Debug",
"--self-contained",
"true",
"-r",
"linux-arm64",
"/nowarn:CS1591",
"/nowarn:CS1587"
],
},
{
"label": "Remote Publish",
"options": {
"cwd": "TShockLauncher/bin/Debug/net6.0/linux-arm64"
},
"command": "C:\\Program Files\\PuTTY\\pscp.exe",
"type": "process",
"args": [
"-pw",
"raspberry",
"-sftp",
"-p",
"-r",
"publish",
"pi@raspberrypi:/home/pi/tshockdev"
],
"dependsOn": [
"Publish"
]
}
]
}

View file

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockAPI", "TShockAPI\TSho
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TerrariaServerAPI", "TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj", "{6877506E-ADC6-4142-98A6-79E4FA02855A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockLauncher", "TShockLauncher\TShockLauncher.csproj", "{2A312452-A43F-43E3-8AEB-E22F9A35C210}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockLauncher", "TShockLauncher\TShockLauncher.csproj", "{2A312452-A43F-43E3-8AEB-E22F9A35C210}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockLauncher.Tests", "TShockLauncher.Tests\TShockLauncher.Tests.csproj", "{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -71,6 +73,22 @@ Global
{2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|x64.Build.0 = Release|Any CPU
{2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|x86.ActiveCfg = Release|Any CPU
{2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|x86.Build.0 = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|x64.ActiveCfg = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|x64.Build.0 = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|x86.ActiveCfg = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Debug|x86.Build.0 = Debug|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|Any CPU.Build.0 = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x64.ActiveCfg = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x64.Build.0 = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x86.ActiveCfg = Release|Any CPU
{90AB47F3-8220-48FC-BDAB-D6E97BFDA51B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -0,0 +1,31 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;
using System.Threading;
namespace TShockLauncher.Tests
{
[TestClass]
public class ServerInitTests
{
[TestMethod]
public void EnsureBoots()
{
var are = new AutoResetEvent(false);
On.Terraria.Main.hook_DedServ cb = (On.Terraria.Main.orig_DedServ orig, Terraria.Main instance) =>
{
are.Set();
Debug.WriteLine("Server init process successful");
};
On.Terraria.Main.DedServ += cb;
new Thread(() => TerrariaApi.Server.Program.Main(new string[] { })).Start();
var hit = are.WaitOne(TimeSpan.FromSeconds(10));
On.Terraria.Main.DedServ -= cb;
Assert.AreEqual(true, hit);
}
}
}

View file

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TShockLauncher\TShockLauncher.csproj" />
</ItemGroup>
</Project>

View file

@ -5,18 +5,18 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName Condition="$([MSBuild]::IsOSPlatform('Windows'))">TShock</AssemblyName>
<AssemblyName Condition="$([MSBuild]::IsOSPlatform('Windows')) == false">TShock.Run</AssemblyName>
<AssemblyName Condition="'$(RuntimeIdentifier)' == 'win-x64' Or '$(RuntimeIdentifier)' == ''">TShock</AssemblyName>
<AssemblyName Condition="'$(RuntimeIdentifier)' != 'win-x64' And '$(RuntimeIdentifier)' != ''">TShock.Run</AssemblyName>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<DebugType>embedded</DebugType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj">
<!-- dont put TShockAPI in the dependencies -->
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<Reference Include="HttpServer">
<ProjectReference Include="..\TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj" ExcludeFromSingleFile="true" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ExcludeFromSingleFile="true" Condition="'$(PublishSingleFile)' == 'true'" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ReferenceOutputAssembly="false" Condition="'$(PublishSingleFile)' != 'true'" />
<Reference Include="HttpServer" ExcludeFromSingleFile="true" >
<HintPath>..\prebuilts\HttpServer.dll</HintPath>
</Reference>
</ItemGroup>
@ -28,23 +28,27 @@
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
</ItemGroup>
<Target Name="MoveToBinFolderDebug" AfterTargets="FinalCleanup;PostBuildEvent">
<ItemGroup>
<MoveBinariesForDebug Include="$(TargetDir)*" Exclude="$(TargetDir)TShock.Run*;$(TargetDir)TShock*" />
<TShockPluginFiles Include="$(ProjectDir)../TShockAPI/bin/$(Configuration)/$(TargetFramework)/TShockAPI*" />
</ItemGroup>
<Move SourceFiles="@(MoveBinariesForDebug)" DestinationFolder="$(TargetDir)bin" ContinueOnError="true" />
<Copy SourceFiles="@(TShockPluginFiles)" DestinationFolder="$(TargetDir)ServerPlugins" ContinueOnError="true" />
</Target>
<Target Name="MoveToBinFolderPublish" AfterTargets="Publish">
<Target Name="MoveTShockDebug" AfterTargets="FinalCleanup;PostBuildEvent">
<ItemGroup>
<MoveBinariesForPublish Include="$(PublishDir)*" Exclude="$(PublishDir)\TShock.exe;$(PublishDir)\TShockAPI*" />
<TShockPluginFilesForPublish Include="$(ProjectDir)../TShockAPI/bin/$(Configuration)/$(TargetFramework)/TShockAPI*" />
<TShockPluginFilesDebug Include="$(TargetDir)/TShockAPI*" />
</ItemGroup>
<Move SourceFiles="@(MoveBinariesForPublish)" DestinationFolder="$(PublishDir)bin" ContinueOnError="true" />
<Copy SourceFiles="@(TShockPluginFilesForPublish)" DestinationFolder="$(PublishDir)ServerPlugins" ContinueOnError="true" />
<Move SourceFiles="@(TShockPluginFilesDebug)" DestinationFolder="$(TargetDir)ServerPlugins" ContinueOnError="true" />
</Target>
<Target Name="MoveTShockPublish" AfterTargets="Publish">
<ItemGroup>
<TShockPluginFilesPublish Include="$(PublishDir)/TShockAPI*" />
<TShockPluginFilesForPublish Include="$(ProjectDir)../TShockAPI/bin/$(Configuration)/$(TargetFramework)/TShockAPI*" Condition="'$(PublishSingleFile)' != 'true'" />
</ItemGroup>
<Move SourceFiles="@(TShockPluginFilesPublish)" DestinationFolder="$(PublishDir)ServerPlugins" ContinueOnError="true" />
<Copy SourceFiles="@(TShockPluginFilesForPublish)" DestinationFolder="$(PublishDir)ServerPlugins" ContinueOnError="true" Condition="'$(PublishSingleFile)' != 'true'" />
</Target>
<Target Name="MoveBin" AfterTargets="Publish">
<ItemGroup>
<MoveBinaries Include="$(PublishDir)*" Exclude="$(PublishDir)\TShock.exe;$(PublishDir)\TShockAPI*" />
</ItemGroup>
<Move SourceFiles="@(MoveBinaries)" DestinationFolder="$(PublishDir)bin" ContinueOnError="true" />
</Target>
<UsingTask TaskName="PatchAppHost" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
@ -83,9 +87,8 @@
<PatchAppHost HostExe="$(PublishDir)TShock.exe" />
<Message Text="Patched TShock.exe host for ./bin redirect" Importance="High" />
</Target>
<Target Name="CreateOsxLauncherAfterPublish" AfterTargets="Publish" Condition="'$(RuntimeIdentifier)' == 'osx-x64' Or '$(RuntimeIdentifier)' == 'ubuntu.16.04-x64' Or '$(RuntimeIdentifier)' == 'linux-arm64'">
<Target Name="CreateScriptAfterPublish" AfterTargets="Publish" Condition="'$(RuntimeIdentifier)' != 'win-x64'">
<Copy SourceFiles="$(ProjectDir)TShock.sh" DestinationFolder="$(PublishDir)" />
<!-- <Message Text="Run the launcher with chmod u+x TShock.exe &amp;&amp; ./TShock.exe" Importance="High" /> -->
<Message Text="Run the launcher with chmod +x TShock.sh &amp;&amp; ./TShock.sh" Importance="High" />
</Target>
</Project>

@ -1 +1 @@
Subproject commit a0b3dacfeea710cc62c8be43dc607678908f9fc8
Subproject commit a7949a2cee98e43e321ed9981c92d08334156f79