Skip to content

Commit dd9b8ad

Browse files
authored
[+] Build with cake and commit id in version (#11)
* [+] Build with cake * ci * ci * fetch-tags * fetch-depth: 0 * melonloader 显示 Git 版本 * remove ci build alert * set FileVersion to git version * add describe to tg * fix
1 parent 0487dd4 commit dd9b8ad

File tree

16 files changed

+147
-44
lines changed

16 files changed

+147
-44
lines changed

.config/dotnet-tools.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"cake.tool": {
6+
"version": "5.0.0",
7+
"commands": [
8+
"dotnet-cake"
9+
],
10+
"rollForward": false
11+
}
12+
}
13+
}

.github/workflows/aquamai.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ name: AquaMai Build
33
on:
44
workflow_dispatch:
55
push:
6-
branches:
7-
- main
86
pull_request_target:
9-
branches:
10-
- main
117

128
jobs:
139
build:
@@ -19,6 +15,11 @@ jobs:
1915
git config --global core.eol lf
2016
2117
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Get Git Describe
22+
run: echo "GIT_DESCRIBE=$(git describe --tags --always)" >> $env:GITHUB_ENV
2223

2324
- name: Checkout Assets
2425
uses: clansty/checkout@main
@@ -34,7 +35,7 @@ jobs:
3435
shell: cmd
3536
run: |
3637
copy /y build-assets\SDEZ\* Libs
37-
dotnet build -c Release /p:DefineConstants="CI"
38+
powershell ./build.ps1
3839
3940
- name: Prepare artifact
4041
shell: cmd
@@ -50,13 +51,13 @@ jobs:
5051
path: Output\Upload
5152

5253
- name: Send to Telegram
53-
if: github.event_name != 'pull_request_target'
54+
# if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/main'
5455
run: |
5556
$Uri = "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMediaGroup"
5657
$Form = @{
57-
chat_id = "-1002231087502"
58+
chat_id = "351768429"
5859
media = @(
59-
@{ type = "document"; media = "attach://aquamai_main"; caption = "${{ github.event.commits[0].message }}" },
60+
@{ type = "document"; media = "attach://aquamai_main"; caption = "${{ env.GIT_DESCRIBE }}`n${{ github.event.commits[0].message }}" },
6061
@{ type = "document"; media = "attach://aquamai_zh" }
6162
@{ type = "document"; media = "attach://aquamai_en" }
6263
) | ConvertTo-Json

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,5 @@ MigrationBackup/
371371
# End of https://www.toptal.com/developers/gitignore/api/git,visualstudio
372372

373373
Output
374-
.idea
374+
tools
375+
AquaMai/BuildInfo.g.cs

.idea/.idea.AquaMai/.idea/.gitignore

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.AquaMai/.idea/encodings.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.AquaMai/.idea/indexLayout.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.AquaMai/.idea/inspectionProfiles/Project_Default.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.AquaMai/.idea/runConfigurations/build_cake__Build.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.AquaMai/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AquaMai.Core/BuildInfo.cs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public static class BuildInfo
1010
public static string Author;
1111
public static string Company;
1212
public static string Version;
13+
public static string GitVersion;
14+
public static string BuildDate;
1315
public static string DownloadLink;
1416
}
1517

AquaMai.Mods/UX/CiBuildAlert.cs

-26
This file was deleted.

AquaMai/BuildInfo.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
namespace AquaMai;
22

3-
public static class BuildInfo
3+
public static partial class BuildInfo
44
{
55
public const string Name = "AquaMai";
66
public const string Description = "Mod for Sinmai";
77
public const string Author = "Aza ft. Clansty ft. Menci";
88
public const string Company = null;
9-
public const string Version = "1.3.3";
109
public const string DownloadLink = null;
1110
}
1211

AquaMai/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
[assembly: AssemblyCopyright("Created by " + AquaMai.BuildInfo.Author)]
99
[assembly: AssemblyTrademark(AquaMai.BuildInfo.Company)]
1010
[assembly: AssemblyVersion(AquaMai.BuildInfo.Version)]
11-
[assembly: AssemblyFileVersion(AquaMai.BuildInfo.Version)]
12-
[assembly: MelonInfo(typeof(AquaMai.AquaMai), AquaMai.BuildInfo.Name, AquaMai.BuildInfo.Version, AquaMai.BuildInfo.Author, AquaMai.BuildInfo.DownloadLink)]
11+
[assembly: AssemblyFileVersion(AquaMai.BuildInfo.GitVersion)]
12+
[assembly: MelonInfo(typeof(AquaMai.AquaMai), AquaMai.BuildInfo.Name, AquaMai.BuildInfo.GitVersion, AquaMai.BuildInfo.Author, AquaMai.BuildInfo.DownloadLink)]
1313
[assembly: MelonColor()]
1414
[assembly: HarmonyDontPatchAll]
1515

README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ This mod is heavily WIP. More details will be added as the development progresse
4141
## Development
4242

4343
1. Copy `Assembly-CSharp.dll` to `Libs` folder.
44-
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)
45-
3. Open `AquaMai.sln` in JetBrains Rider.
46-
4. Build the solution.
47-
5. Copy `Output/AquaMai.dll` to `Mods` folder.
48-
6. Configure and copy `AquaMai.toml` to the same folder as your game executable: `Sinmai.exe`
44+
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)
45+
1. Run `build.ps1`.
46+
1. Copy `Output/AquaMai.dll` to `Mods` folder.
47+
1. Configure and copy `AquaMai.toml` to the same folder as your game executable: `Sinmai.exe`
4948

5049
## Relevant Links
5150

build.cake

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#addin nuget:?package=Cake.Git&version=5.0.1
2+
#addin nuget:?package=Cake.FileHelpers&version=7.0.0
3+
4+
var target = Argument("target", "Build");
5+
var configuration = Argument("configuration", "Release");
6+
7+
Task("Restore")
8+
.Does(() =>
9+
{
10+
// 运行 dotnet restore
11+
DotNetRestore("./AquaMai.sln");
12+
});
13+
14+
Task("PreBuild")
15+
.Does(() =>
16+
{
17+
var gitDescribe = GitDescribe(".", GitDescribeStrategy.Tags).Substring(1); // 获取 git describe 的输出
18+
var buildDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
19+
20+
var shortVers = gitDescribe.Split('-');
21+
string shortVer;
22+
if (shortVers.Length > 1)
23+
{
24+
shortVer = $"{shortVers[0]}.{shortVers[1]}";
25+
}
26+
else
27+
{
28+
shortVer = shortVers[0];
29+
}
30+
31+
var versionContent = $@"
32+
// Auto-generated file. Do not modify manually.
33+
namespace AquaMai;
34+
35+
public static partial class BuildInfo
36+
{{
37+
public const string Version = ""{shortVer}"";
38+
public const string GitVersion = ""{gitDescribe}"";
39+
public const string BuildDate = ""{buildDate}"";
40+
}}
41+
";
42+
FileWriteText("./AquaMai/BuildInfo.g.cs", versionContent);
43+
});
44+
45+
Task("Build")
46+
.IsDependentOn("PreBuild")
47+
.IsDependentOn("Restore")
48+
.Does(() =>
49+
{
50+
// 使用 dotnet build 进行构建
51+
DotNetBuild("./AquaMai.sln", new DotNetBuildSettings
52+
{
53+
Configuration = configuration
54+
});
55+
});
56+
57+
RunTarget(target);

build.ps1

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
Set-Location -LiteralPath $PSScriptRoot
4+
5+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
6+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
7+
$env:DOTNET_NOLOGO = '1'
8+
9+
dotnet tool restore
10+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
11+
12+
dotnet cake @args
13+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

0 commit comments

Comments
 (0)