Fix NuGet publish workflow: handle invalid/missing API key gracefully #41
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: Publish NuGet Package | ||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' # Trigger on version tags like v1.0.0 | ||
| jobs: | ||
| build: | ||
| runs-on: windows-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Setup .NET SDK | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: '6.0.x' | ||
| - name: Restore dependencies | ||
| run: dotnet restore CADability/CADability.csproj | ||
| - name: Build | ||
| run: dotnet build CADability/CADability.csproj -c Release --no-restore | ||
| - name: List build output | ||
| run: dir CADability\bin\Release\netstandard2.0 | ||
| - name: Pack | ||
| run: dotnet pack CADability/CADability.csproj -c Release --no-build -o ./nupkgs | ||
| - name: List nupkg | ||
| run: dir .\nupkgs | ||
| - name: Push NuGet package | ||
| if: ${{ secrets.NUGET_API_KEY }} | ||
| env: | ||
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | ||
| run: | | ||
| $version = "${{ github.ref_name }}" -replace '^v', '' | ||
| $pkg = Get-ChildItem -Path ./nupkgs -Filter "*$version.nupkg" | Select-Object -First 1 | ||
| dotnet nuget push $pkg.FullName --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json --skip-duplicate | ||