Skip to content

Commit 51f0394

Browse files
committed
Stopped the nuget-publish action from failing if the version already exists on NuGet
1 parent 84a53ca commit 51f0394

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

.github/workflows/nuget-publish.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ jobs:
3434

3535
- name: Publish to NuGet
3636
if: github.event_name == 'push'
37-
run: dotnet nuget push ./nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
37+
run: |
38+
set -e
39+
for pkg in ./nupkgs/*.nupkg; do
40+
echo "Pushing $pkg"
41+
output=$(dotnet nuget push "$pkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json 2>&1) && status=0 || status=$?
42+
if [ $status -eq 0 ]; then
43+
echo "Successfully pushed $pkg"
44+
elif echo "$output" | grep -q "Response status code does not indicate success: 409"; then
45+
echo "Package $pkg already exists on NuGet. Skipping."
46+
else
47+
echo "$output"
48+
echo "Failed to push $pkg for an unexpected reason."
49+
exit 1
50+
fi
51+
done

0 commit comments

Comments
 (0)