Skip to content

Stopped the nuget-publish action from failing if the version already … #6

Stopped the nuget-publish action from failing if the version already …

Stopped the nuget-publish action from failing if the version already … #6

Workflow file for this run

name: Build and Publish NuGet Packages
on:
push:
branches: [ master ]
paths:
- 'Linq/*.csproj'
- 'Types/*.csproj'
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Pack System.Management.Types
run: dotnet pack Types/System.Management.Types.csproj --configuration Release --output ./nupkgs
- name: Pack System.Management.Linq
run: dotnet pack Linq/System.Management.Linq.csproj --configuration Release --output ./nupkgs
- name: Publish to NuGet
if: github.event_name == 'push'
run: |
set -e
for pkg in ./nupkgs/*.nupkg; do
echo "Pushing $pkg"
output=$(dotnet nuget push "$pkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json 2>&1) && status=0 || status=$?
if [ $status -eq 0 ]; then
echo "Successfully pushed $pkg"
elif echo "$output" | grep -q "Response status code does not indicate success: 409"; then
echo "Package $pkg already exists on NuGet. Skipping."
else
echo "$output"
echo "Failed to push $pkg for an unexpected reason."
exit 1
fi
done