Skip to content

Build and Publish to NuGet #41

Build and Publish to NuGet

Build and Publish to NuGet #41

Workflow file for this run

name: Build and Publish to NuGet
on:
push:
branches: [main]
pull_request:
branches: [main]
release:
types: [created]
workflow_dispatch:
inputs:
publish_to_nuget:
description: "Publish to NuGet?"
required: true
type: boolean
default: false
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Setup .NET 9
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: Test
run: dotnet test
- name: Pack
run: dotnet pack --configuration Release --no-build --output ./nupkgs
publish-nuget:
needs: build-and-test
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_to_nuget == 'true')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"
- name: Publish to NuGet
run: |
for f in ./nupkgs/*.nupkg
do
dotnet nuget push $f --api-key ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
done