diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 13e684c..1bf573f 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -8,6 +8,13 @@ "tcli" ], "rollForward": true + }, + "cake.tool": { + "version": "5.0.0", + "commands": [ + "dotnet-cake" + ], + "rollForward": false } } } \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bed27b9..8e9521b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,20 +28,14 @@ jobs: - uses: actions/setup-dotnet@v4 with: dotnet-version: "9.0.x" - - name: Build - run: | - dotnet build -c Release - # Copy the built DLL to dist folder - mkdir -p ./bin/dist/ - cp ./RenderiteHook/bin/Release/RenderiteHook.dll ./bin/dist/ - - name: Create Thunderstore Package - run: | - dotnet tool restore - dotnet tcli build --package-version ${{ steps.info.outputs.version }} + - name: Install Cake Tool + run: dotnet tool restore + - name: Build with Cake + run: dotnet cake --target=Build --verbosity=normal - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: RenderiteHook-${{ steps.info.outputs.version }}-${{ steps.info.outputs.sha_short }} path: | - ./bin/dist/*.dll + ./RenderiteHook/bin/Release/*.dll ./build/*.zip \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8f8f46d..4fee356 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,13 +24,10 @@ jobs: - uses: actions/setup-dotnet@v4 with: dotnet-version: "9.0.x" - - name: Build - run: | - dotnet build -c Release - - name: Create Thunderstore Package - run: | - dotnet tool restore - dotnet tcli build --package-version $VERSION + - name: Install Cake Tool + run: dotnet tool restore + - name: Build with Cake + run: dotnet cake --target=Build --verbosity=normal - name: Publish to Thunderstore run: | ZIP_FILE=$(ls ./build/*.zip | head -1) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d2ff07d..e87fc4e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,16 +36,10 @@ jobs: - uses: actions/setup-dotnet@v4 with: dotnet-version: "9.0.x" - - name: Build - run: | - dotnet build -c Release - # Copy the built DLL to dist folder for release - mkdir -p ./bin/dist/ - cp ./RenderiteHook/bin/Release/RenderiteHook.dll ./bin/dist/ - - name: Create Thunderstore Package - run: | - dotnet tool restore - dotnet tcli build + - name: Install Cake Tool + run: dotnet tool restore + - name: Build with Cake + run: dotnet cake --target=Build --verbosity=normal - name: Create Git Tag (if needed) if: ${{ github.event_name == 'workflow_dispatch' }} run: | @@ -71,7 +65,7 @@ jobs: tag_name: v${{ steps.info.outputs.version }} target_commitish: ${{ github.sha }} files: | - ./bin/dist/*.dll + ./RenderiteHook/bin/Release/*.dll ./build/*.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/RenderiteHook/Plugin.cs b/RenderiteHook/Plugin.cs index 2ce03fb..30e71c7 100644 --- a/RenderiteHook/Plugin.cs +++ b/RenderiteHook/Plugin.cs @@ -13,7 +13,7 @@ namespace RenderiteHook; [BepInDependency(BepInExResoniteShim.PluginMetadata.GUID, BepInDependency.DependencyFlags.HardDependency)] public class Plugin : BasePlugin { - internal static new ManualLogSource Log; + internal static new ManualLogSource Log = null!; public override void Load() { @@ -31,7 +31,7 @@ public static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerableenable true false - true + false $(ResonitePath)/ $(MSBuildProgramFiles32)\Steam\steamapps\common\Resonite\ $(HOME)/.steam/steam/steamapps/common/Resonite/ diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..2e6f858 --- /dev/null +++ b/build.cake @@ -0,0 +1,114 @@ +var doorstopVersion = "4.4.1"; +var projectPath = "./RenderiteHook/RenderiteHook.csproj"; + +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); + +var packageVersion = XmlPeek(projectPath, "/Project/PropertyGroup/Version"); + +var distDir = Directory("./dist"); +var extractDir = distDir + Directory("Doorstop"); +var downloadUrl = $"https://github.com/NeighTools/UnityDoorstop/releases/download/v{doorstopVersion}/doorstop_win_release_{doorstopVersion}.zip"; +var zipFile = distDir + File($"doorstop_win_release_{doorstopVersion}.zip"); + +Task("Clean") + .Does(() => +{ + if (DirectoryExists(distDir)) + { + CleanDirectory(distDir); + } + else + { + CreateDirectory(distDir); + } +}); + +Task("DownloadDoorstop") + .IsDependentOn("Clean") + .Does(() => +{ + Information($"Downloading Doorstop v{doorstopVersion}..."); + + if (!FileExists(zipFile)) + { + DownloadFile(downloadUrl, zipFile); + Information($"Downloaded to: {zipFile}"); + } + else + { + Information("File already exists, skipping download."); + } +}); + +Task("ExtractDoorstop") + .IsDependentOn("DownloadDoorstop") + .Does(() => +{ + Information($"Extracting Doorstop to {extractDir}..."); + + if (!DirectoryExists(extractDir)) + { + CreateDirectory(extractDir); + } + + Unzip(zipFile, extractDir); + Information("Extraction completed."); + + // Update doorstop_config.ini to point to BepInEx + var configFile = extractDir + File("x64/doorstop_config.ini"); + if (FileExists(configFile)) + { + Information("Updating doorstop_config.ini..."); + var content = System.IO.File.ReadAllText(configFile); + content = content.Replace("target_assembly=Doorstop.dll", "target_assembly=BepInEx\\core\\BepInEx.Preloader.dll"); + System.IO.File.WriteAllText(configFile, content); + Information("Config file updated successfully."); + } + else + { + Warning($"Config file not found at: {configFile}"); + } +}); + +Task("BuildRenderiteHook") + .IsDependentOn("ExtractDoorstop") + .Does(() => +{ + Information($"Building RenderiteHook version {packageVersion}..."); + + // Build RenderiteHook project + DotNetBuild(projectPath, new DotNetBuildSettings + { + Configuration = configuration, + Verbosity = DotNetVerbosity.Minimal + }); + + Information("RenderiteHook build completed successfully."); +}); + +Task("Build") + .IsDependentOn("BuildRenderiteHook") + .Does(() => +{ + Information($"Building Thunderstore package with version {packageVersion}..."); + + // Run dotnet tcli build command + var exitCode = StartProcess("dotnet", new ProcessSettings + { + Arguments = $"tcli build --package-version {packageVersion}", + WorkingDirectory = Directory(".") + }); + + if (exitCode != 0) + { + throw new Exception($"dotnet tcli build failed with exit code {exitCode}"); + } + + Information("Thunderstore package build completed successfully."); +}); + +Task("Default") + .IsDependentOn("Build"); + +RunTarget(target); \ No newline at end of file diff --git a/thunderstore.toml b/thunderstore.toml index e32215e..2d7c4a2 100644 --- a/thunderstore.toml +++ b/thunderstore.toml @@ -29,6 +29,10 @@ target = "plugins/RenderiteHook/" source = "./RenderiteHook/bin/Release/RenderiteHook.pdb" target = "plugins/RenderiteHook/" +[[build.copy]] +source = "./dist/Doorstop/x64" +target = "plugins/RenderiteHook/Doorstop" + # [[build.copy]] # source = "./CHANGELOG.md" # target = "/"