name: .NET on: push: branches: [ dev ] paths: - "versions/release.md" pull_request: branches: [ dev ] jobs: # Windows 和 Linux 构建(保持在 Ubuntu 上) build-linux-windows: runs-on: ubuntu-latest steps: - name: Get build version id: date run: echo "date=$(date +'%Y%m%d')${{github.run_number}}" >> $GITHUB_OUTPUT - name: Checkout Code uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 10.0.x - name: Publish Windows and Linux working-directory: ./src/ZonyLrcTools.Cli run: | for platform in win-x64 linux-x64 win-arm64 linux-arm64; do dotnet publish -r "$platform" -c Release -p:PublishSingleFile=true -p:UseAppHost=true -p:DebugType=none --self-contained true cd ./bin/Release/net10.0/"$platform"/publish/ zip -r ./ZonyLrcTools_"$platform"_"${{ steps.date.outputs.date }}".zip ./ cd ../../../../../ mkdir -p ./TempFiles mv ./bin/Release/net10.0/"$platform"/publish/*.zip ./TempFiles/ done shell: bash - name: Upload artifact uses: actions/upload-artifact@v4 with: retention-days: 90 name: release-files-linux-windows path: ./src/ZonyLrcTools.Cli/TempFiles outputs: version: ${{ steps.date.outputs.date }} # 桌面端构建(目前只发布 Windows,见 README 的说明) build-desktop: runs-on: windows-latest steps: - name: Get build version id: date run: echo "date=$(Get-Date -Format 'yyyyMMdd')${{github.run_number}}" >> $env:GITHUB_OUTPUT shell: pwsh - name: Checkout Code uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 10.0.x - name: Publish Desktop (win-x64) working-directory: ./src/ZonyLrcTools.Desktop run: | dotnet publish -r win-x64 -c Release -p:PublishSingleFile=true -p:UseAppHost=true -p:DebugType=none --self-contained true if ($LASTEXITCODE -ne 0) { throw '桌面端发布失败' } shell: pwsh # 单文件发布仍需附带 SQLite 原生库、配置模板及第三方许可声明。 - name: Verify Desktop publish output working-directory: ./src/ZonyLrcTools.Desktop run: | $publish = './bin/Release/net10.0/win-x64/publish' $exe = Join-Path $publish 'ZonyLrcTools.Desktop.exe' $sqlite = Join-Path $publish 'e_sqlite3.dll' if (-not (Test-Path $exe)) { throw "缺少主程序: $exe" } if (-not (Test-Path $sqlite)) { throw "缺少 SQLite 原生库: $sqlite(.kgg 解密依赖它)" } if (-not (Test-Path (Join-Path $publish 'config.yaml'))) { throw '缺少 config.yaml 模板' } if (-not (Test-Path (Join-Path $publish 'THIRD-PARTY-NOTICES.md'))) { throw '缺少第三方许可声明' } $totalMb = [math]::Round(((Get-ChildItem $publish -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB), 1) Write-Host "publish 目录校验通过:$((Get-ChildItem $publish -File).Count) 个文件,共 $totalMb MB" if ($totalMb -gt 90) { throw "publish 目录有 $totalMb MB,超过 90 MB 上限;这通常意味着 PublishTrimmed 被关掉了" } shell: pwsh - name: Package Desktop working-directory: ./src/ZonyLrcTools.Desktop run: | New-Item -ItemType Directory -Force -Path ./TempFiles | Out-Null Compress-Archive -Path ./bin/Release/net10.0/win-x64/publish/* -DestinationPath ./TempFiles/ZonyLrcTools.Desktop_win-x64_${{ steps.date.outputs.date }}.zip -Force shell: pwsh - name: Upload artifact uses: actions/upload-artifact@v4 with: retention-days: 90 name: release-files-desktop path: ./src/ZonyLrcTools.Desktop/TempFiles outputs: version: ${{ steps.date.outputs.date }} # macOS 构建(在 macOS runner 上,支持 ad-hoc 签名) build-macos: runs-on: macos-latest steps: - name: Get build version id: date run: echo "date=$(date +'%Y%m%d')${{github.run_number}}" >> $GITHUB_OUTPUT - name: Checkout Code uses: actions/checkout@v4 - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 10.0.x - name: Publish macOS working-directory: ./src/ZonyLrcTools.Cli run: | for platform in osx-x64 osx-arm64; do dotnet publish -r "$platform" -c Release -p:PublishSingleFile=true -p:DebugType=none --self-contained true # Ad-hoc 签名,解决 macOS Gatekeeper/XProtect 问题 codesign -s - --force --deep ./bin/Release/net10.0/"$platform"/publish/ZonyLrcTools.Cli cd ./bin/Release/net10.0/"$platform"/publish/ zip -r ./ZonyLrcTools_"$platform"_"${{ steps.date.outputs.date }}".zip ./ cd ../../../../../ mkdir -p ./TempFiles mv ./bin/Release/net10.0/"$platform"/publish/*.zip ./TempFiles/ done shell: bash - name: Upload artifact uses: actions/upload-artifact@v4 with: retention-days: 90 name: release-files-macos path: ./src/ZonyLrcTools.Cli/TempFiles outputs: version: ${{ steps.date.outputs.date }} # Release Job - 合并所有平台的构建产物 release: if: github.event_name == 'push' needs: [build-linux-windows, build-macos, build-desktop] runs-on: ubuntu-latest steps: - name: Checkout for release notes uses: actions/checkout@v4 - name: Download Linux/Windows artifacts uses: actions/download-artifact@v4 with: name: release-files-linux-windows path: ./TempFiles - name: Download macOS artifacts uses: actions/download-artifact@v4 with: name: release-files-macos path: ./TempFiles - name: Download Desktop artifacts uses: actions/download-artifact@v4 with: name: release-files-desktop path: ./TempFiles - name: Upload Release uses: ncipollo/release-action@v1 with: artifacts: "./TempFiles/*.zip" token: ${{ secrets.GITHUBACTIONS }} tag: ZonyLrcToolsX_Alpha.${{ needs.build-linux-windows.outputs.version }} commit: dev bodyFile: ./versions/release.md