diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..af5df57 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,34 @@ +name: Tests + +# The mod builds against the game's own assemblies, which cannot be redistributed, so it is not built here. Run with no +# arguments, tests/Checks.csproj compiles only the mod's game-free sources (source/PinSet.cs), references no game or +# package DLLs, runs the pin-logic checks and reports the game checks as skipped. build.ps1 runs all of them locally. +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 15 + env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_NOLOGO: 1 + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-dotnet@v6 + id: dotnet + with: + dotnet-version: 8.0.x + # NuGet.Config clears every package source, so the build must use the net8.0 targeting pack that comes with a + # .NET 8 SDK. The runner may also have newer SDKs, and without a global.json the dotnet CLI picks the newest, so + # pin the one just installed, on the runner only (a global.json in the repository would also pin mod builds). + - name: Pin the .NET 8 SDK + run: dotnet new globaljson --sdk-version ${{ steps.dotnet.outputs.dotnet-version }} --force + - name: Game-free checks + run: dotnet run --project tests/Checks.csproj -c Release diff --git a/README.md b/README.md index 80011e5..1ca34dc 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ Install the .NET 8 SDK and have Timberborn installed, then run: The script builds the mod, runs checks, and creates `dist\PersistentWorkAreas-v1.0.0.zip`. No game, Unity, Harmony, or BeaverBuddies DLLs are redistributed. The game DLLs are used only as build references. +Without the game, `dotnet run --project tests/Checks.csproj -c Release` runs only the pin-logic checks and reports the rest as skipped. GitHub Actions runs them for pull requests and pushes to `main`. + ## License MIT. See [LICENSE](LICENSE). diff --git a/tests/Program.cs b/tests/Program.cs index 1355807..da77cc6 100644 --- a/tests/Program.cs +++ b/tests/Program.cs @@ -27,6 +27,22 @@ void Check(bool ok, string name) Check(pins.Set(forester, false) && pins.Count == 0, "Deleting last pinned building empties collection"); Check(new PinSet().Count == 0, "New map begins without pins"); +// The checks above use only the mod's game-free sources, so CI runs them without arguments on a machine without +// Timberborn. The rest need the installed game, the built mod DLL and its package folder. Add checks that need no game +// files above this block, or CI never runs them: the count guard at the end cannot tell where a check was placed. +const int GameChecks = 27; // A full run fails if this stops matching the checks below. +int gameFreeChecks = checks; +if (args.Length == 0) +{ + Console.WriteLine($"{checks} checks passed; {GameChecks} checks that need the game were skipped (pass to run them)."); + return 0; +} +if (args.Length != 3) +{ + Console.Error.WriteLine("Usage: Checks [ ]. With no arguments only the game-free checks run."); + return 2; +} + var game = Path.GetFullPath(args[0]); var modPath = Path.GetFullPath(args[1]); var managed = Path.Combine(game, "Timberborn_Data", "Managed"); @@ -91,7 +107,10 @@ void Method(Type type, string name, Type returns, params Type[] args) Check(manifest.RootElement.GetProperty("Version").GetString() == mod.GetName().Version!.ToString(3), "Manifest version matches assembly version"); using var binding = JsonDocument.Parse(File.ReadAllText(Path.Combine(packaging, "KeyBindings", "PersistentWorkAreas.Clear.blueprint.json"))); Check(binding.RootElement.GetProperty("KeyBindingSpec").GetProperty("Id").GetString() == (string)service.GetField("ClearKey")!.GetRawConstantValue()!, "Clear key binding matches input handler"); +if (checks - gameFreeChecks != GameChecks) + throw new Exception($"FAIL: {checks - gameFreeChecks} checks ran after the game-free block but GameChecks says {GameChecks}; move any new check that needs no game files above that block, then set GameChecks to the number that still needs the game"); Console.WriteLine($"{checks} checks passed. Unity rendering and multiplayer playtesting still require the game."); +return 0; sealed class EqualBuilding {