diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..885c1c2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,63 @@ +name: Build and Test C# Project (Framework 4.7.2) + + +on: + push: + branches: [ master ] # 触发条件,当main分支有push时触发 + pull_request: + branches: [ master ] # 当向main分支发起pull request时也触发 + +jobs: + build: + + runs-on: windows-latest # 使用Windows环境,因为.NET Framework在Windows上运行 + + env: + MELONLOADER_REPO: https://api.github.com/repos/LavaGang/MelonLoader/releases/latest + MELONLOADER_ASSET_NAME: MelonLoader.x64.zip + OUTPUT_URL: ${{ secrets.OUTPUT_URL }} + OUTPUT_FILE: Output.7z + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: scripts + run: | + choco install 7zip.install -y + mkdir cache + Invoke-WebRequest -Uri https://github.com/LavaGang/MelonLoader/releases/download/v0.6.5/MelonLoader.x64.zip -OutFile "$(Get-Location)\cache\MelonLoader.x64.zip" + 7z x "$(Get-Location)\cache\MelonLoader.x64.zip" -o"$(Get-Location)\Out" + Invoke-WebRequest -Uri ${{ secrets.OUTPUT_URL }} -OutFile "$(Get-Location)\cache\Output.7z" + 7z x "$(Get-Location)\cache\Output.7z" -o"$(Get-Location)\Output" + + if (-not $(git --version 2>$null)) { + $commitHash = "NOT SET" + } else { + $commitHash = git rev-parse --short HEAD + } + + $timestamp = Get-Date -Format 'o' + + @" + namespace SinmaiAssist { + public static partial class BuildInfo { + public const string CommitHash = "$commitHash"; + public const string BuildDate = "$timestamp"; + } + } + "@ | Out-File -FilePath ".\BuildInfo.cs" -Encoding ascii + dotnet build + mkdir ".\Out\Mods\" + mkdir ".\Out\UserLibs\" + mkdir ".\Out\Sinmai-Assist\" + cmd /c copy /y ".\Output\Sinmai-Assist.dll" ".\Out\Mods\Sinmai-Assist.dll" + cmd /c copy /y ".\Output\YamlDotNet.dll" ".\Out\UserLibs\YamlDotNet.dll" + cmd /c copy /y ".\config - zh_CN.yml" ".\Out\Sinmai-Assist\config.yml" + Compress-Archive -Path "$(Get-Location)\Out\*" -DestinationPath "$(Get-Location)\Out.zip" -Update + + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: artifact + path: Out.zip diff --git a/PostBuild.bat b/PostBuild.bat new file mode 100644 index 0000000..455315c --- /dev/null +++ b/PostBuild.bat @@ -0,0 +1,25 @@ +@echo off + +where git >nul 2>nul +if errorlevel 1 ( + echo Git is not installed. Using default commit hash. + set COMMIT_HASH="NOT SET" +) else ( + for /f "tokens=1" %%i in ('git rev-parse --short HEAD') do set COMMIT_HASH=%%i +) + +for /f "usebackq delims=" %%t in (`powershell -Command "( Get-Date -Format 'yyyyMMddHHmmss')"`) do ( + set TIMESTAMP=%%t +) + +echo CommitHash="%COMMIT_HASH%" +echo BuildDate="%TIMESTAMP%" + +copy /y ".\Sinmai-Assist.dll" "..\Out\Mods\" +copy /y ".\YamlDotNet.dll" "..\Out\UserLibs\" +copy /y "..\config - zh_CN.yml" "..\Out\Sinmai-Assist\config.yml" +@REM 7z a -tzip "..\PostBuilds\Sinmai-Assist_%COMMIT_HASH%_%TIMESTAMP%".zip "..\Out\*" +@REM +@REM set GamePath="G:\maimai\maimai2024\Package\" +@REM copy /y ".\Sinmai-Assist.dll" "%GamePath%Mods\" +@REM copy /y ".\YamlDotNet.dll" "%GamePath%UserLibs\" \ No newline at end of file diff --git a/Sinmai-Assist.csproj b/Sinmai-Assist.csproj index 6a357e6..83804fd 100644 --- a/Sinmai-Assist.csproj +++ b/Sinmai-Assist.csproj @@ -524,6 +524,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +