From 2bd03722c6586638a564dd5f0c865b9bd29fdb8e Mon Sep 17 00:00:00 2001 From: Clansty Date: Mon, 20 Jan 2025 23:21:27 +0800 Subject: [PATCH] [+] Build with cake --- .config/dotnet-tools.json | 13 +++++ .github/workflows/aquamai.yaml | 6 +- .gitignore | 3 +- .idea/.idea.AquaMai/.idea/.gitignore | 13 +++++ .idea/.idea.AquaMai/.idea/encodings.xml | 4 ++ .idea/.idea.AquaMai/.idea/indexLayout.xml | 8 +++ .../inspectionProfiles/Project_Default.xml | 6 ++ .../runConfigurations/build_cake__Build.xml | 7 +++ .idea/.idea.AquaMai/.idea/vcs.xml | 6 ++ AquaMai.Core/BuildInfo.cs | 2 + AquaMai/BuildInfo.cs | 3 +- README.md | 9 ++- build.cake | 57 +++++++++++++++++++ build.ps1 | 13 +++++ 14 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 .config/dotnet-tools.json create mode 100644 .idea/.idea.AquaMai/.idea/.gitignore create mode 100644 .idea/.idea.AquaMai/.idea/encodings.xml create mode 100644 .idea/.idea.AquaMai/.idea/indexLayout.xml create mode 100644 .idea/.idea.AquaMai/.idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/.idea.AquaMai/.idea/runConfigurations/build_cake__Build.xml create mode 100644 .idea/.idea.AquaMai/.idea/vcs.xml create mode 100644 build.cake create mode 100644 build.ps1 diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..b6554f30 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "5.0.0", + "commands": [ + "dotnet-cake" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/.github/workflows/aquamai.yaml b/.github/workflows/aquamai.yaml index 5030d9d3..a9bf5f2a 100644 --- a/.github/workflows/aquamai.yaml +++ b/.github/workflows/aquamai.yaml @@ -3,11 +3,7 @@ name: AquaMai Build on: workflow_dispatch: push: - branches: - - main pull_request_target: - branches: - - main jobs: build: @@ -50,7 +46,7 @@ jobs: path: Output\Upload - name: Send to Telegram - if: github.event_name != 'pull_request_target' + if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/main' run: | $Uri = "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMediaGroup" $Form = @{ diff --git a/.gitignore b/.gitignore index df21fd82..979398c4 100644 --- a/.gitignore +++ b/.gitignore @@ -371,4 +371,5 @@ MigrationBackup/ # End of https://www.toptal.com/developers/gitignore/api/git,visualstudio Output -.idea +tools +AquaMai/BuildInfo.g.cs diff --git a/.idea/.idea.AquaMai/.idea/.gitignore b/.idea/.idea.AquaMai/.idea/.gitignore new file mode 100644 index 00000000..6f6061ea --- /dev/null +++ b/.idea/.idea.AquaMai/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/contentModel.xml +/projectSettingsUpdater.xml +/.idea.AquaMai.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.AquaMai/.idea/encodings.xml b/.idea/.idea.AquaMai/.idea/encodings.xml new file mode 100644 index 00000000..df87cf95 --- /dev/null +++ b/.idea/.idea.AquaMai/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.AquaMai/.idea/indexLayout.xml b/.idea/.idea.AquaMai/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/.idea/.idea.AquaMai/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.AquaMai/.idea/inspectionProfiles/Project_Default.xml b/.idea/.idea.AquaMai/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..e00071e6 --- /dev/null +++ b/.idea/.idea.AquaMai/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.AquaMai/.idea/runConfigurations/build_cake__Build.xml b/.idea/.idea.AquaMai/.idea/runConfigurations/build_cake__Build.xml new file mode 100644 index 00000000..004a687e --- /dev/null +++ b/.idea/.idea.AquaMai/.idea/runConfigurations/build_cake__Build.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.AquaMai/.idea/vcs.xml b/.idea/.idea.AquaMai/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/.idea.AquaMai/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AquaMai.Core/BuildInfo.cs b/AquaMai.Core/BuildInfo.cs index 709ce367..47cb4199 100644 --- a/AquaMai.Core/BuildInfo.cs +++ b/AquaMai.Core/BuildInfo.cs @@ -10,6 +10,8 @@ public static class BuildInfo public static string Author; public static string Company; public static string Version; + public static string GitVersion; + public static string BuildDate; public static string DownloadLink; } diff --git a/AquaMai/BuildInfo.cs b/AquaMai/BuildInfo.cs index 7cdbf41d..96d4d10b 100644 --- a/AquaMai/BuildInfo.cs +++ b/AquaMai/BuildInfo.cs @@ -1,12 +1,11 @@ namespace AquaMai; -public static class BuildInfo +public static partial class BuildInfo { public const string Name = "AquaMai"; public const string Description = "Mod for Sinmai"; public const string Author = "Aza ft. Clansty ft. Menci"; public const string Company = null; - public const string Version = "1.3.3"; public const string DownloadLink = null; } diff --git a/README.md b/README.md index 3c5c1fec..10c08d25 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,10 @@ This mod is heavily WIP. More details will be added as the development progresse ## Development 1. Copy `Assembly-CSharp.dll` to `Libs` folder. -2. Install [.NET Framework 4.7.2 Developer Pack](https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net472-developer-pack-offline-installer) -3. Open `AquaMai.sln` in JetBrains Rider. -4. Build the solution. -5. Copy `Output/AquaMai.dll` to `Mods` folder. -6. Configure and copy `AquaMai.toml` to the same folder as your game executable: `Sinmai.exe` +1. Install [.NET Framework 4.7.2 Developer Pack](https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net472-developer-pack-offline-installer) +1. Run `build.ps1`. +1. Copy `Output/AquaMai.dll` to `Mods` folder. +1. Configure and copy `AquaMai.toml` to the same folder as your game executable: `Sinmai.exe` ## Relevant Links diff --git a/build.cake b/build.cake new file mode 100644 index 00000000..90f2320b --- /dev/null +++ b/build.cake @@ -0,0 +1,57 @@ +#addin nuget:?package=Cake.Git&version=5.0.1 +#addin nuget:?package=Cake.FileHelpers&version=7.0.0 + +var target = Argument("target", "Build"); +var configuration = Argument("configuration", "Release"); + +Task("Restore") + .Does(() => +{ + // 运行 dotnet restore + DotNetRestore("./AquaMai.sln"); +}); + +Task("PreBuild") + .Does(() => +{ + var gitDescribe = GitDescribe(".", GitDescribeStrategy.Tags); // 获取 git describe 的输出 + var buildDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); + + var shortVers = gitDescribe.Substring(1).Split('-'); + string shortVer; + if (shortVers.Length > 1) + { + shortVer = $"{shortVers[0]}.{shortVers[1]}"; + } + else + { + shortVer = shortVers[0]; + } + + var versionContent = $@" + // Auto-generated file. Do not modify manually. + namespace AquaMai; + + public static partial class BuildInfo + {{ + public const string Version = ""{shortVer}""; + public const string GitVersion = ""{gitDescribe}""; + public const string BuildDate = ""{buildDate}""; + }} + "; + FileWriteText("./AquaMai/BuildInfo.g.cs", versionContent); +}); + +Task("Build") + .IsDependentOn("Restore") + .IsDependentOn("PreBuild") + .Does(() => +{ + // 使用 dotnet build 进行构建 + DotNetBuild("./AquaMai.sln", new DotNetBuildSettings + { + Configuration = configuration + }); +}); + +RunTarget(target); diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 00000000..21821d29 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,13 @@ +$ErrorActionPreference = 'Stop' + +Set-Location -LiteralPath $PSScriptRoot + +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1' +$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1' +$env:DOTNET_NOLOGO = '1' + +dotnet tool restore +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +dotnet cake @args +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }