Skip to content

Fix NuGet publish workflow: handle invalid/missing API key gracefully #41

Fix NuGet publish workflow: handle invalid/missing API key gracefully

Fix NuGet publish workflow: handle invalid/missing API key gracefully #41

Workflow file for this run

name: Publish NuGet Package

Check failure on line 1 in .github/workflows/nuget.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/nuget.yml

Invalid workflow file

(Line: 27, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.NUGET_API_KEY
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