Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 17 additions & 27 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,50 +113,44 @@ jobs:
retention-days: 90

publish:
name: Publish to GitHub Packages
name: Publish to NuGet.org
runs-on: windows-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'release'

steps:
- name: Download NuGet packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: packages

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to GitHub Packages

- name: Publish to NuGet.org
run: |
$hasError = $false
# GitHub Packages does not support symbol packages (.symbols.nupkg)
# Only push main packages (.nupkg) and exclude symbol packages
Get-ChildItem -Path packages -Filter *.nupkg -Recurse | Where-Object { $_.Name -notlike "*.symbols.nupkg" } | ForEach-Object {
Write-Host "Publishing $($_.Name)..."
dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
dotnet nuget push $_.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate
if ($LASTEXITCODE -ne 0) {
$hasError = $true
Write-Error "Failed to publish $($_.Name)"
}
}
if ($hasError) {
Write-Error "One or more packages failed to publish. This may indicate duplicate versions."
Write-Error "One or more packages failed to publish."
exit 1
}
shell: pwsh

- name: Publish Summary
run: |
# Only list main packages (not symbol packages)
$packages = Get-ChildItem -Path packages -Filter *.nupkg -Recurse | Where-Object { $_.Name -notlike "*.symbols.nupkg" }
Write-Output "## 馃摝 Published Packages" >> $env:GITHUB_STEP_SUMMARY
Write-Output "## Published Packages" >> $env:GITHUB_STEP_SUMMARY
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
Write-Output "| Package | Version |" >> $env:GITHUB_STEP_SUMMARY
Write-Output "|---------|---------|" >> $env:GITHUB_STEP_SUMMARY
Expand All @@ -168,44 +162,40 @@ jobs:
shell: pwsh

publish-release:
name: Publish Release to GitHub Packages
name: Publish Release to NuGet.org
runs-on: windows-latest
needs: build
if: github.event_name == 'release'

steps:
- name: Download NuGet packages
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: packages

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to GitHub Packages

- name: Publish to NuGet.org
run: |
$hasError = $false
# GitHub Packages does not support symbol packages (.symbols.nupkg)
# Only push main packages (.nupkg) and exclude symbol packages
Get-ChildItem -Path packages -Filter *.nupkg -Recurse | Where-Object { $_.Name -notlike "*.symbols.nupkg" } | ForEach-Object {
Write-Host "Publishing release package $($_.Name)..."
dotnet nuget push $_.FullName --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
dotnet nuget push $_.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate
if ($LASTEXITCODE -ne 0) {
$hasError = $true
Write-Error "Failed to publish $($_.Name)"
}
}
if ($hasError) {
Write-Error "One or more packages failed to publish. This may indicate duplicate versions."
Write-Error "One or more packages failed to publish."
exit 1
}
shell: pwsh
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}


- name: Upload packages to release
uses: softprops/action-gh-release@v1
with:
Expand Down
Loading