From 6c580b18f8e9b8cfea9ac62ffeef45270f9c6c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Sat, 10 May 2025 02:01:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BA=A7=E5=93=81=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=EF=BC=8C=E6=9C=AC=E5=9C=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E6=94=B9=E6=88=900.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 369 ++++++++++++++++++ .../BetterGenshinImpact.csproj | 6 +- BetterGenshinImpact/Core/Config/Global.cs | 11 +- BetterGenshinImpact/Service/UpdateService.cs | 7 +- 4 files changed, 384 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..201a4d79 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,369 @@ +name: BetterGI Publish + +on: + workflow_dispatch: + inputs: + version: + description: 'BetterGI Version (eg: v0.35.1, v0.36.5-alpha.1)' + required: true + type: string + kachina-channel: + type: choice + description: 'Kachina Installer Channel' + required: true + default: 'release' + options: + - release + - dev + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' + +jobs: + # Add validation job to check version format + validate: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.set-version.outputs.version }} + steps: + - name: Set version from input or tag + id: set-version + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + # Validate manual input version format + if ! [[ "${{ github.event.inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then + echo "Error: Version must follow semantic versioning (e.g., 1.2.3, 1.2.3-alpha, 1.2.3+build.123)" + exit 1 + fi + echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT + else + # Extract version from tag name (remove 'v' prefix) + VERSION=${GITHUB_REF#refs/tags/v} + echo "version=${VERSION}" >> $GITHUB_OUTPUT + fi + + build_web_map_editor: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + repository: huiyadanli/bettergi-map + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + - run: npm install + - run: npm run build:single + - uses: actions/upload-artifact@v4 + with: + name: web_map_editor + path: dist/ + + build_web_scripts_list: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + repository: huiyadanli/bettergi-scripts-web + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + - run: npm install + - run: npm run build:single + - uses: actions/upload-artifact@v4 + with: + name: web_scripts_list + path: dist/ + + build_dist: + runs-on: windows-latest + needs: [validate, build_web_map_editor, build_web_scripts_list] + steps: + - uses: actions/checkout@v4 + with: + repository: babalae/better-genshin-impact + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + - name: Cache NuGet packages + uses: actions/cache@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/BetterGenshinImpact.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget- + - name: 🛠️ Build application + run: dotnet publish BetterGenshinImpact/BetterGenshinImpact.csproj -c Release -p:PublishProfile=FolderProfile -p:Version=${{ needs.validate.outputs.version }} + continue-on-error: true + - name: 🧹 Clear & Move Files + run: | + $sourceDir = ".\BetterGenshinImpact\bin\x64\Release\net8.0-windows10.0.22621.0\publish\win-x64" + Get-ChildItem -Path $sourceDir -Recurse -Filter "*.lib" | Remove-Item -Force + Get-ChildItem -Path $sourceDir -Recurse -Filter "*ffmpeg*.dll" | Remove-Item -Force + Get-ChildItem -Path $sourceDir -Recurse -Filter "*.pdb" | Remove-Item -Force + New-Item -Path "dist/BetterGI" -ItemType Directory + xcopy "$sourceDir\*" ".\dist\BetterGI\" /E /H /I /Y + # 下载前面构建好的web内容 + - uses: actions/download-artifact@v4 + with: + name: web_map_editor + path: dist/BetterGI/Assets/Map/Editor + - uses: actions/download-artifact@v4 + with: + name: web_scripts_list + path: dist/BetterGI/Assets/Web/ScriptRepo + # 下载构建 repo 的内容补充数据 + - uses: actions/checkout@v4 + with: + repository: babalae/bettergi-publish + path: publish + - name: 🗜️ Extract Map + run: | + cd publish + # Extract zst files + Get-ChildItem -Filter *.zst | ForEach-Object { + if ($_.PSIsContainer -eq $false) { + $file = $_.Name + $output_file = "..\dist\BetterGI\Assets\Map\$($file -replace '.zst$', '')" + & zstd -d $file -o $output_file + Write-Host "$file -> $output_file" + } + } + # Extract zip files + Get-ChildItem -Filter *.zip | ForEach-Object { + if ($_.PSIsContainer -eq $false) { + $file = $_.FullName + $destination = "..\dist\BetterGI\Assets\Map" + Expand-Archive -Path $file -DestinationPath $destination -Force + Write-Host "$file -> $destination" + } + } + # 生成更新器 + - name: 📥 Download kachina-builder release + if: ${{ github.event.inputs.kachina-channel == 'release' }} + uses: robinraju/release-downloader@v1.8 + with: + repository: "YuehaiTeam/kachina-installer" + latest: true + fileName: "kachina-builder.exe" + + - name: 📥 Download kachina-builder dev + if: ${{ github.event.inputs.kachina-channel == 'dev' }} + uses: dawidd6/action-download-artifact@v8 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + repo: "YuehaiTeam/kachina-installer" + workflow: "build.yml" + name: artifact + branch: main + event: push + workflow_conclusion: success + - name: 📦 Gen Updater by kachina-builder + run: | + cd dist + ..\kachina-builder.exe pack -c ..\publish\kachina.config.json -o BetterGI/BetterGI.update.exe + # 打包上传 + - name: 📦 Generate archive + run: | + cd dist + 7z a "BetterGI_v${{ needs.validate.outputs.version }}.7z" BetterGI -t7z -mx=5 -mf=BCJ2 -r -y + - uses: actions/upload-artifact@v4 + with: + name: BetterGI_7z + path: dist/BetterGI_*.7z + + build_installer: + runs-on: windows-latest + needs: [build_dist] + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: BetterGI_7z + path: dist + - name: Unpack BetterGI_*.7z + run: | + cd dist + 7z x "BetterGI_v${{ needs.validate.outputs.version }}.7z" + - name: 📥 Download kachina-builder release + if: ${{ github.event.inputs.kachina-channel == 'release' }} + uses: robinraju/release-downloader@v1.8 + with: + repository: "YuehaiTeam/kachina-installer" + latest: true + fileName: "kachina-builder.exe" + - name: 📥 Download kachina-builder dev + if: ${{ github.event.inputs.kachina-channel == 'dev' }} + uses: dawidd6/action-download-artifact@v8 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + repo: "YuehaiTeam/kachina-installer" + workflow: "build.yml" + name: artifact + branch: main + event: push + workflow_conclusion: success + - name: 📥 Download last release + uses: robinraju/release-downloader@v1.8 + with: + repository: "babalae/better-genshin-impact" + latest: true + fileName: "BetterGI_v*.7z" + out-file-path: 'last' + - name: 📥 Get 2nd and 3rd release + id: release_tags + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + $releasesUrl = "https://api.github.com/repos/babalae/better-genshin-impact/releases" + $headers = @{ + "Authorization" = "Bearer $env:GITHUB_TOKEN" + "Accept" = "application/vnd.github.v3+json" + } + $releases = Invoke-RestMethod -Uri $releasesUrl -Headers $headers -Method Get + $validReleases = $releases | + Where-Object { -not $_.draft -and -not $_.prerelease } | + Sort-Object { [DateTime]$_.published_at } -Descending + if ($validReleases.Count -lt 3) { + Write-Error "至少需要 3 个正式 Release(当前找到 $($validReleases.Count) 个)" + exit 1 + } + "second_release_tag=$($validReleases[1].tag_name)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + "third_release_tag=$($validReleases[2].tag_name)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + + - name: 📥 Download 2nd last release + uses: robinraju/release-downloader@v1.8 + with: + repository: "babalae/better-genshin-impact" + tag: ${{ steps.release_tags.outputs.second_release_tag }} + fileName: "BetterGI_v*.7z" + out-file-path: '2nd' + - name: 📥 Download 3rd last release + uses: robinraju/release-downloader@v1.8 + with: + repository: "babalae/better-genshin-impact" + tag: ${{ steps.release_tags.outputs.third_release_tag }} + fileName: "BetterGI_v*.7z" + out-file-path: '3rd' + - name: Unpack releases + run: | + cd last + 7z x "BetterGI*.7z" -otemp + if (Test-Path -Path ".\temp\BetterGI" -PathType Container) { + Move-Item -Path ".\temp\BetterGI" -Destination ".\BetterGI" + } else { + Rename-Item -Path ".\temp" -NewName ".\BetterGI" + } + cd .. + cd 2nd + 7z x "BetterGI*.7z" -otemp + if (Test-Path -Path ".\temp\BetterGI" -PathType Container) { + Move-Item -Path ".\temp\BetterGI" -Destination ".\BetterGI" + } else { + Rename-Item -Path ".\temp" -NewName ".\BetterGI" + } + cd .. + cd 3rd + 7z x "BetterGI*.7z" -otemp + if (Test-Path -Path ".\temp\BetterGI" -PathType Container) { + Move-Item -Path ".\temp\BetterGI" -Destination ".\BetterGI" + } else { + Rename-Item -Path ".\temp" -NewName ".\BetterGI" + } + cd .. + ls .\last + ls .\2nd + ls .\3rd + - name: 📦 Pack kachina-builder + run: | + cd dist + ..\kachina-builder.exe gen -j 6 -i BetterGI -m metadata.json -o hashed -r babalae/bettergi -t ${{ needs.validate.outputs.version }} --diff-vers ..\last\BetterGI --diff-vers ..\2nd\BetterGI --diff-vers ..\3rd\BetterGI --diff-ignore *[.txt,.onnx] -u .\BetterGI\BetterGI.update.exe + ..\kachina-builder.exe pack -c ../kachina.config.json -m metadata.json -d hashed -o BetterGI.Install.${{ needs.validate.outputs.version }}.exe + - uses: actions/upload-artifact@v4 + with: + name: BetterGI_Install + path: dist/BetterGI.Install.*.exe + - uses: actions/upload-artifact@v4 + with: + name: BetterGI_Metadata + path: dist/metadata.json + + build_setup: + runs-on: windows-latest + needs: [build_dist] + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: BetterGI_7z + path: dist + - name: Unpack BetterGI_*.7z & Repack + run: | + cd dist + 7z x "BetterGI_v${{ needs.validate.outputs.version }}.7z" + cd BetterGI + 7z a -t7z "..\..\publish.7z" * + - name: 📥 Download MicaSetup + uses: robinraju/release-downloader@v1.8 + with: + repository: "lemutec/MicaSetup" + latest: true + fileName: "MicaSetup_v*.7z" + - name: 📦 Pack MicaSetup + run: | + $archiveFiles = Get-ChildItem -Path . -Filter "MicaSetup_v*.7z" + foreach ($archive in $archiveFiles) { + & 7z x $archive.FullName + } + .\makemica.exe micasetup.json + ren BetterGI_Setup.exe BetterGI_Setup_v${{ needs.validate.outputs.version }}.exe + - uses: actions/upload-artifact@v4 + with: + name: BetterGI_Setup + path: BetterGI_Setup*.exe + + mirrorchyan_uploading: + if: github.repository_owner == 'babalae' + needs: [build_dist, build_installer] + runs-on: macos-latest + steps: + + - uses: actions/download-artifact@v4 + with: + path: downloads + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract 7z + shell: bash + run: | + cd downloads/BetterGI_7z + 7z x BetterGI_v*.7z -oun7z + mv ../BetterGI_Metadata/metadata.json ./un7z/BetterGI/.metadata.json + + - name: Upload Zip + uses: MirrorChyan/uploading-action@v1 + with: + filetype: local + mirrorchyan_rid: BGI + working-directory: downloads/BetterGI_7z/un7z/ + pick_files: '["BetterGI"]' + version_name: ${{ needs.validate.outputs.version }} + upload_token: ${{ secrets.MirrorChyanUploadToken }} + auto_channel: false + channel: beta + + - name: Upload Install.exe + uses: MirrorChyan/uploading-action@v1 + with: + filetype: local + mirrorchyan_rid: BGI + working-directory: downloads/BetterGI_Install/ + filename: "BetterGI.Install.*.exe" + extra_zip: true + version_name: ${{ needs.validate.outputs.version }} + upload_token: ${{ secrets.MirrorChyanUploadToken }} + auto_channel: false + channel: beta + os: win + arch: x64 \ No newline at end of file diff --git a/BetterGenshinImpact/BetterGenshinImpact.csproj b/BetterGenshinImpact/BetterGenshinImpact.csproj index 050df9db..352aad2e 100644 --- a/BetterGenshinImpact/BetterGenshinImpact.csproj +++ b/BetterGenshinImpact/BetterGenshinImpact.csproj @@ -1,6 +1,9 @@  + BetterGI + 0.0.1 + false WinExe net8.0-windows10.0.22621.0 enable @@ -9,8 +12,6 @@ 12.0 true Assets\Images\logo.ico - BetterGI - 0.45.0 x64 embedded @@ -67,6 +68,7 @@ + diff --git a/BetterGenshinImpact/Core/Config/Global.cs b/BetterGenshinImpact/Core/Config/Global.cs index 2d33d336..0223f639 100644 --- a/BetterGenshinImpact/Core/Config/Global.cs +++ b/BetterGenshinImpact/Core/Config/Global.cs @@ -3,12 +3,15 @@ using System.IO; using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; +using Semver; namespace BetterGenshinImpact.Core.Config; public class Global { - public static string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3); + public static string Version { get; } = Assembly.GetEntryAssembly()?. + GetCustomAttribute()?. + InformationalVersion!; public static string StartUpPath { get; set; } = AppContext.BaseDirectory; @@ -59,10 +62,10 @@ public class Global { try { - Version oldVersionX = new(oldVersion); - Version currentVersionX = new(currentVersion); + var oldVersionX = SemVersion.Parse(oldVersion); + var currentVersionX = SemVersion.Parse(currentVersion); - if (currentVersionX > oldVersionX) + if (currentVersionX.CompareSortOrderTo(oldVersionX) > 0) // 需要更新 return true; } diff --git a/BetterGenshinImpact/Service/UpdateService.cs b/BetterGenshinImpact/Service/UpdateService.cs index 138589f2..aae45524 100644 --- a/BetterGenshinImpact/Service/UpdateService.cs +++ b/BetterGenshinImpact/Service/UpdateService.cs @@ -47,11 +47,12 @@ public class UpdateService : IUpdateService { try { +#if DEBUG && true + return; +#endif string newVersion = await GetLatestVersionAsync(); -// #if DEBUG && true -// newVersion = "256.256.256.256"; -// #endif + if (string.IsNullOrWhiteSpace(newVersion)) {