Make release packaging tolerate optional files #2
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup MSBuild | |
| uses: microsoft/setup-msbuild@v2 | |
| - name: Setup NuGet | |
| uses: NuGet/setup-nuget@v2 | |
| - name: Restore dependencies | |
| run: nuget restore NetStatusSharp.sln | |
| - name: Build solution | |
| run: msbuild NetStatusSharp.sln /p:Configuration=Release /p:Platform="Any CPU" | |
| - name: Package release files | |
| shell: pwsh | |
| run: | | |
| $tag = "${{ github.ref_name }}" | |
| $staging = Join-Path $env:RUNNER_TEMP "NetStatusSharp-$tag" | |
| $asset = Join-Path $env:RUNNER_TEMP "NetStatusSharp-$tag.zip" | |
| $releaseDir = "NetStatusSharp\bin\Release" | |
| $filesToInclude = @( | |
| "NetStatusSharp.exe", | |
| "NetStatusSharp.exe.config", | |
| "NetStatusSharp.exe.manifest", | |
| "NetStatusAPI.dll" | |
| ) | |
| $requiredFiles = @( | |
| "NetStatusSharp.exe", | |
| "NetStatusSharp.exe.config", | |
| "NetStatusAPI.dll" | |
| ) | |
| New-Item -ItemType Directory -Force -Path $staging | Out-Null | |
| foreach ($file in $requiredFiles) { | |
| $path = Join-Path $releaseDir $file | |
| if (-not (Test-Path $path)) { | |
| throw "Required release file not found: $path" | |
| } | |
| } | |
| foreach ($file in $filesToInclude) { | |
| $path = Join-Path $releaseDir $file | |
| if (Test-Path $path) { | |
| Copy-Item -Path $path -Destination $staging -Force | |
| } | |
| } | |
| if (Test-Path $asset) { | |
| Remove-Item -LiteralPath $asset -Force | |
| } | |
| Compress-Archive -Path (Join-Path $staging "*") -DestinationPath $asset | |
| "ASSET_PATH=$asset" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| - name: Publish GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: ${{ env.ASSET_PATH }} | |
| generate_release_notes: true |