From f094f82fe7aeeab4e4a56e576ddb81b7420ce062 Mon Sep 17 00:00:00 2001 From: Jamie Read Date: Sun, 7 Aug 2022 19:55:12 +0100 Subject: [PATCH 1/3] Add cake build to replace build scripts Release task is partially implemented but will require more work to get in a good state --- .config/dotnet-tools.json | 12 ++ .props | 5 - .targets | 110 ------------- .version | 1 + DarkRift.Client/DarkRift.Client.csproj | 5 +- .../DarkRift.Server.Console.csproj | 6 - .../DarkRift.Server.Testing.csproj | 3 - DarkRift.Server/DarkRift.Server.csproj | 5 +- .../DarkRift.SystemTesting.csproj | 3 - DarkRift.Testing/DarkRift.Testing.csproj | 3 - DarkRift/DarkRift.csproj | 5 +- build.cake | 152 ++++++++++++++++++ 12 files changed, 168 insertions(+), 142 deletions(-) create mode 100644 .config/dotnet-tools.json delete mode 100644 .props delete mode 100644 .targets create mode 100644 .version create mode 100644 build.cake diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..7bd5f9f --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "2.2.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/.props b/.props deleted file mode 100644 index 6241879..0000000 --- a/.props +++ /dev/null @@ -1,5 +0,0 @@ - - - 2.10.1 - - \ No newline at end of file diff --git a/.targets b/.targets deleted file mode 100644 index b625248..0000000 --- a/.targets +++ /dev/null @@ -1,110 +0,0 @@ - - - - $(SolutionDir)Build/ - $(BuildArea)$(Configuration)/$(TargetFramework)/ - - - - - - - - - $(USERPROFILE)/.nuget/packages/msbuildtasks/1.5.0.235/tools - - - $(HOME)/.nuget/packages/msbuildtasks/1.5.0.235/tools - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $(Configuration.ToLower()) - pro - - core - framework - - - - - - diff --git a/.version b/.version new file mode 100644 index 0000000..b714ae9 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +2.12.0-prerelease diff --git a/DarkRift.Client/DarkRift.Client.csproj b/DarkRift.Client/DarkRift.Client.csproj index e6c0607..5169a62 100644 --- a/DarkRift.Client/DarkRift.Client.csproj +++ b/DarkRift.Client/DarkRift.Client.csproj @@ -1,7 +1,4 @@  - - - net3.5;netstandard2.0 netstandard2.0 @@ -26,4 +23,4 @@ - \ No newline at end of file + diff --git a/DarkRift.Server.Console/DarkRift.Server.Console.csproj b/DarkRift.Server.Console/DarkRift.Server.Console.csproj index a48bb2f..8ad77fc 100644 --- a/DarkRift.Server.Console/DarkRift.Server.Console.csproj +++ b/DarkRift.Server.Console/DarkRift.Server.Console.csproj @@ -1,7 +1,4 @@  - - - net4.0;netcoreapp2.0;netcoreapp3.1;net5.0;net6.0 netcoreapp2.0;netcoreapp3.1;net5.0;net6.0 @@ -39,7 +36,4 @@ - - - diff --git a/DarkRift.Server.Testing/DarkRift.Server.Testing.csproj b/DarkRift.Server.Testing/DarkRift.Server.Testing.csproj index ff0f490..455cc4f 100644 --- a/DarkRift.Server.Testing/DarkRift.Server.Testing.csproj +++ b/DarkRift.Server.Testing/DarkRift.Server.Testing.csproj @@ -1,7 +1,4 @@  - - - net4.5;net6.0 net6.0 diff --git a/DarkRift.Server/DarkRift.Server.csproj b/DarkRift.Server/DarkRift.Server.csproj index f138018..fac3e85 100644 --- a/DarkRift.Server/DarkRift.Server.csproj +++ b/DarkRift.Server/DarkRift.Server.csproj @@ -1,7 +1,4 @@  - - - net3.5;netstandard2.0 netstandard2.0 @@ -26,4 +23,4 @@ - \ No newline at end of file + diff --git a/DarkRift.SystemTesting/DarkRift.SystemTesting.csproj b/DarkRift.SystemTesting/DarkRift.SystemTesting.csproj index f626eb8..44bc694 100644 --- a/DarkRift.SystemTesting/DarkRift.SystemTesting.csproj +++ b/DarkRift.SystemTesting/DarkRift.SystemTesting.csproj @@ -1,7 +1,4 @@  - - - net6.0 Debug;Free;Pro diff --git a/DarkRift.Testing/DarkRift.Testing.csproj b/DarkRift.Testing/DarkRift.Testing.csproj index fb38d61..2142f7e 100644 --- a/DarkRift.Testing/DarkRift.Testing.csproj +++ b/DarkRift.Testing/DarkRift.Testing.csproj @@ -1,7 +1,4 @@  - - - net4.5;net6.0 net6.0 diff --git a/DarkRift/DarkRift.csproj b/DarkRift/DarkRift.csproj index 1648947..7c9a093 100644 --- a/DarkRift/DarkRift.csproj +++ b/DarkRift/DarkRift.csproj @@ -1,7 +1,4 @@  - - - net3.5;netstandard2.0 netstandard2.0 @@ -22,4 +19,4 @@ DEBUG;TRACE;PRO - \ No newline at end of file + diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..9c5e322 --- /dev/null +++ b/build.cake @@ -0,0 +1,152 @@ +var target = Argument("target", "Test"); +var configuration = Argument("configuration", "Debug"); + +var version = System.IO.File.ReadAllText(".version").Trim(); + +Task("Clean") + .Does(() => +{ + Information($"Cleaning ./Build/{configuration}"); + CleanDirectory($"./Build/{configuration}"); +}); + +Task("Build") + .IsDependentOn("Clean") + .Does(() => +{ + DotNetBuild("./DarkRift2.sln", new DotNetBuildSettings + { + Configuration = configuration, + MSBuildSettings = new DotNetMSBuildSettings + { + Properties = + { + { "Version", new List {version} } + } + } + }); + + var targetFrameworks = GetSubDirectories($"./DarkRift.Server.Console/bin/{configuration}") + .Select(d => MakeRelative(d, MakeAbsolute(Directory($"./DarkRift.Server.Console/bin/{configuration}")))); + foreach (var targetFramework in targetFrameworks) + { + var sourceDir = $"./DarkRift.Server.Console/bin/{configuration}/{targetFramework}"; + var buildDir = $"./Build/{configuration}/{targetFramework}"; + + Information($"Constructing {buildDir}"); + + CreateDirectory(buildDir); + + // Copy files into Build folder + CopyFiles($"{sourceDir}/*.*", buildDir); + + // .NET Framework needs a slightly different structure + if (targetFramework == "net4.0") + { + // Move library files into the Libs folder (except DarkRift.Server.Console.pdb) + CreateDirectory($"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.dll", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.pdb", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/Lib/DarkRift.Server.Console.pdb", $"{buildDir}"); + MoveFiles($"{buildDir}/*.xml", $"{buildDir}/Lib"); + } + else + { + // Move library files into the Libs folder + CreateDirectory($"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.dll", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.pdb", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.xml", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.deps.json", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.dll.config", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.runtimeconfig.dev.json", $"{buildDir}/Lib"); + MoveFiles($"{buildDir}/*.runtimeconfig.json", $"{buildDir}/Lib"); + } + + // Create zip of server build + // Zip(buildDir, $"{buildDir}/DarkRift Server.zip"); + } +}); + +Task("Test") + .IsDependentOn("Build") + .Does(() => +{ + DotNetTest("./DarkRift2.sln", new DotNetTestSettings + { + Configuration = configuration, + NoBuild = true, + }); +}); + +Task("InstallInCLITool") + .IsDependentOn("Build") + .Does(() => +{ + var homeDir = IsRunningOnWindows() ? EnvironmentVariable("HOMEDRIVE") + EnvironmentVariable("HOMEPATH") : EnvironmentVariable("HOME"); + var tier = configuration == "Debug" ? "pro" : configuration.ToLower(); // CLI doesn't support a 'debug' tier so remap to pro + + var targetFrameworks = GetSubDirectories($"./DarkRift.Server.Console/bin/{configuration}") + .Select(d => MakeRelative(d, MakeAbsolute(Directory($"./DarkRift.Server.Console/bin/{configuration}")))); + foreach (var targetFramework in targetFrameworks) + { + var buildDir = $"./Build/{configuration}/{targetFramework}"; + var cliDir = $"/{configuration}/{targetFramework}"; + var platform = targetFramework == "net4.0" ? "net40" : targetFramework; // TODO for some reason .NET 4.0 is under net40 in DR CLI + + Information($"Installing into ~/.darkrift/installed/{tier}/{platform}/dev"); + + EnsureDirectoryExists($"{homeDir}/.darkrift/installed/{tier}/{platform}/dev"); + CleanDirectory($"{homeDir}/.darkrift/installed/{tier}/{platform}/dev"); + CopyFiles($"{buildDir}/**/*.*", $"{homeDir}/.darkrift/installed/{tier}/{platform}/dev"); + } +}); + +// Task("Release") +// .Does(() => +// { +// #addin nuget:?package=Cake.Prompt&version=1.2.1 +// var versionRegex = "^[0-9]+.[0-9]+.[0-9]+$"; +// var releaseVersion = version; +// do +// releaseVersion = Prompt("Enter version for this release", version.Replace("-prerelease", "")).Trim(); +// while (!Regex.IsMatch(releaseVersion, versionRegex)); +// version = releaseVersion; +// +// if (StartProcess("git", new ProcessSettings { Arguments = "diff-index --quiet HEAD --" }) != 0) +// throw new Exception("You have uncommitted changes in your project. Commit the changes or reset them to release."); +// +// // TODO Port to C# +// // Information("DarkRift $version - $(date -I)"); +// // git log $(git describe --tags --abbrev=0)..HEAD --format='- %s' | grep -vF "[changelog.skip]" | grep -v "^Merge" +// +// RunTarget("Build"); +// +// do +// version = Prompt($"Enter prerelease version (previous was {version}) (-prerelease will be appended)") + "-prerelease"; +// while (!Regex.IsMatch(version, versionRegex)); +// +// System.IO.File.WriteAllText(".version", version); +// +// StartProcess("git", new ProcessSettings { Arguments = $"commit -a \"Update version number to {version}\"" }); +// StartProcess("git", new ProcessSettings { Arguments = $"tag V{version}" }); +// +// StartProcess("git", new ProcessSettings { Arguments = "push origin master --tags" }); +// +// RunTarget("CopyToUnity"); // TODO port editor script in Unity to cake +// +// #addin nuget:?package=Cake.Unity&version=0.9.0 +// UnityEditor( +// new UnityEditorArguments +// { +// ProjectPath = "./DarkRift.Unity", +// ExportPackage = new ExportPackage { AssetPaths = { "Assets/DarkRift" }, PackageName = "DarkRift.unitypackage"} +// } +// ); +// +// #addin nuget:?package=Cake.DocFx&version=1.0.0 +// DocFxBuild("./DarkRift.Documentation/docfx.json"); +// }); + +// Run a target when script is run +RunTarget(target); From 270f080ac65ac626565f8b678ca5e7e45c754c68 Mon Sep 17 00:00:00 2001 From: Jamie Read Date: Sun, 7 Aug 2022 20:13:54 +0100 Subject: [PATCH 2/3] Sort CI and documentation --- .github/workflows/build-and-test.yml | 7 +++---- .github/workflows/pack.yml | 8 ++++---- BUILDING.md | 30 ++++++++++++++++++++++++++-- build.cake | 4 +++- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 1b74953..ef7bbc9 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -12,8 +12,7 @@ jobs: with: # TODO install all targeted .NET versions then test against all of them dotnet-version: 6.0.104 - - name: Build - # MSBuildCommunityTasks doesn't play well with .NET 6 so skip all that - run: dotnet build --configuration Pro -p:DRBuildMode=coreonly -p:SkipCopyToBuild=true + - name: Restore + run: dotnet tool restore - name: Test - run: dotnet test -p:DRBuildMode=coreonly -p:SkipCopyToBuild=true + run: dotnet cake --target Test --configuration Pro --core-only diff --git a/.github/workflows/pack.yml b/.github/workflows/pack.yml index 9eb45c4..ac5b46b 100644 --- a/.github/workflows/pack.yml +++ b/.github/workflows/pack.yml @@ -13,9 +13,9 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 6.0.104 - - name: Build - run: dotnet build --configuration Pro -p:DRBuildMode=coreonly -p:SkipCopyToBuild=true + - name: Restore + run: dotnet tool restore - name: Test - run: dotnet test -p:DRBuildMode=coreonly -p:SkipCopyToBuild=true - # TODO create GitHub release, this might require moving away from MSBuildTasks due to no .NET Core support + run: dotnet cake --target Test --configuration Pro --core-only + # TODO create GitHub release # TODO pack unitypackage using somehting like https://github.com/FatihBAKIR/UnityPacker diff --git a/BUILDING.md b/BUILDING.md index 1634766..96f2826 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -1,4 +1,30 @@ -To build the DarkRift 2 solution *you must have Microsoft Visual Studio 2022* installed. The Community edition is fine for open source projects, and is easily attained from https://visualstudio.microsoft.com/vs/community/ +DarkRift is build using [Cake](https://cakebuild.net/). To create a full build of DarkRift run `dotnet cake` (you will need to run `dotnet tool restore` the first time). + +This command will: +- Build DarkRift +- Create neatly organized packages in `./Build` +- Test DR + +You will need the .NET 6 SDK to build DarkRift. + +For editing DarkRift we recommend using Microsoft Visual Studio 2022 although other editors will work. + +## Cake Tasks +The following tasks are defined in `build.cake`: +- `Clean` - Cleans the `./Build` directory +- `Build` - Builds DarkRift +- `Test` (default) - Builds and tests DarkRift +- `InstallInCLITool` - Builds and installs a dev version of DarkRift into the DarkRift CLI tool as version `dev`. This is useful for easy local testing + +The following arguments can be passed to the build script: +- `--target ` - choose the task to run (see list above) +- `--configuration ` - the configuration of DR to build (see below section) +- `--core-only` - only build for .NET Core, this can get around issues building .NET Framework applications such as on Linux + +For example: +```bash +dotnet cake --target InstallInCLITool --configuration Pro +``` ## Configurations @@ -25,4 +51,4 @@ If you're looking to manually copy assemblies into your Unity assets, you should If you're an existing DarkRift 2 user, there's a decent chance you will want to reproduce the Free or Pro .unitypackage DarkRift 2 used to ship with in order to stick with the way DR2 in your Assets folder is organized. Even as a new user, a .unitypackage can be a practical way install the typical DarkRift version into your Unity project if you don't intend to make changes. -*TODO: Fix package building in post_release.sh and write guide for how to export packages* \ No newline at end of file +*TODO: Fix package building in post_release.sh and write guide for how to export packages* diff --git a/build.cake b/build.cake index 9c5e322..d2c915c 100644 --- a/build.cake +++ b/build.cake @@ -1,5 +1,6 @@ var target = Argument("target", "Test"); var configuration = Argument("configuration", "Debug"); +var coreOnly = HasArgument("core-only"); var version = System.IO.File.ReadAllText(".version").Trim(); @@ -21,7 +22,8 @@ Task("Build") { Properties = { - { "Version", new List {version} } + { "Version", new List {version} }, + { "DRBuildMode", new List {coreOnly ? "coreonly" : "all"} } } } }); From e63bd4383970b065b58404043312b05c8e2698f2 Mon Sep 17 00:00:00 2001 From: Jamie Read Date: Sun, 7 Aug 2022 20:57:07 +0100 Subject: [PATCH 3/3] Reinstate commented out zipping task --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index d2c915c..c43abe5 100644 --- a/build.cake +++ b/build.cake @@ -66,7 +66,7 @@ Task("Build") } // Create zip of server build - // Zip(buildDir, $"{buildDir}/DarkRift Server.zip"); + Zip(buildDir, $"{buildDir}/DarkRift Server.zip"); } });