Build & Release (x64+arm64, FD + SelfContained SingleFile) #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build & Release (x64+arm64, FD + SelfContained SingleFile) | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| precheck: | |
| name: Read version & check release exists | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.ver.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Read AssemblyVersion from csproj | |
| id: ver | |
| shell: pwsh | |
| run: | | |
| $csproj = "src/FileWatcherForEmby.csproj" | |
| if (!(Test-Path $csproj)) { throw "Not found: $csproj" } | |
| [xml]$xml = Get-Content $csproj | |
| $version = @($xml.Project.PropertyGroup.AssemblyVersion | Where-Object { $_ -and $_.Trim() -ne "" })[0] | |
| if (-not $version) { throw "AssemblyVersion not found in $csproj" } | |
| "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| Write-Host "AssemblyVersion=$version" | |
| - name: Fail if GitHub Release already exists | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG: ${{ steps.ver.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| if gh api "/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" >/dev/null 2>&1; then | |
| echo "Release with tag '${TAG}' already exists. Abort." | |
| exit 1 | |
| fi | |
| echo "Release tag '${TAG}' does not exist. Continue." | |
| build: | |
| name: Build zips (${{ matrix.rid }} / ${{ matrix.flavor }}) | |
| needs: precheck | |
| runs-on: windows-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| rid: [win-x64, win-arm64] | |
| flavor: [fd, sc-singlefile] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup .NET (net10) | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: "10.0.x" | |
| # 若你使用 net10 预览版 SDK,可启用: | |
| # include-prerelease: true | |
| - name: Restore | |
| run: dotnet restore src/FileWatcherForEmby.csproj | |
| - name: Publish | |
| shell: pwsh | |
| run: | | |
| $rid = "${{ matrix.rid }}" | |
| $flavor = "${{ matrix.flavor }}" | |
| $outDir = "out\$flavor-$rid" | |
| if ($flavor -eq "fd") { | |
| dotnet publish src/FileWatcherForEmby.csproj ` | |
| -c Release -f net10.0 -r $rid ` | |
| --self-contained false ` | |
| -o $outDir | |
| } else { | |
| dotnet publish src/FileWatcherForEmby.csproj ` | |
| -c Release -f net10.0 -r $rid ` | |
| --self-contained true ` | |
| -p:PublishSingleFile=true ` | |
| -p:IncludeNativeLibrariesForSelfExtract=true ` | |
| -o $outDir | |
| } | |
| - name: Delete PDB files | |
| shell: pwsh | |
| run: | | |
| Get-ChildItem -Path out -Recurse -Filter *.pdb | Remove-Item -Force | |
| - name: Create zip | |
| shell: pwsh | |
| env: | |
| TAG: ${{ needs.precheck.outputs.version }} | |
| run: | | |
| $rid = "${{ matrix.rid }}" | |
| $flavor = "${{ matrix.flavor }}" | |
| $src = "out\$flavor-$rid\*" | |
| $zipName = if ($flavor -eq "fd") { | |
| "FileWatcherForEmby-$env:TAG-$rid-framework-dependent.zip" | |
| } else { | |
| "FileWatcherForEmby-$env:TAG-$rid-self-contained-singlefile.zip" | |
| } | |
| if (Test-Path $zipName) { Remove-Item $zipName -Force } | |
| Compress-Archive -Path $src -DestinationPath $zipName | |
| - name: Upload zip artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.flavor }}-${{ matrix.rid }} | |
| path: | | |
| FileWatcherForEmby-*.zip | |
| release: | |
| name: Create GitHub Release | |
| needs: [precheck, build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| - name: Create Release and upload assets | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG: ${{ needs.precheck.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| ls -la dist || true | |
| gh release create "${TAG}" dist/**/FileWatcherForEmby-*.zip \ | |
| --title "${TAG}" \ | |
| --notes "Automated release ${TAG}" |