Skip to content

GH actions for build and nuget release #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .github/workflows/buildandpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Publish to NuGet

on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-*' # Trigger on tags matching vX.Y.Z or vX.Y.Z-prerelease

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release

# - name: Test
# run: dotnet test --configuration Release --no-build --verbosity normal

pack:
name: Pack
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x' # Ensure this matches the build job

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release

- name: Determine version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Pack
run: dotnet pack --configuration Release --output . --include-symbols /p:Version=${{ steps.version.outputs.VERSION }}

- name: Upload NuGet package artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: '*.nupkg'

publish:
name: Publish to NuGet.org
needs: pack
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Download NuGet package artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: .

- name: Determine if prerelease
id: prerelease
run: |
VERSION="${GITHUB_REF#refs/tags/}"
if [[ "$VERSION" == *"-"* ]]; then
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
else
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
fi

- name: Publish to NuGet.org
if: steps.prerelease.outputs.IS_PRERELEASE == 'true'
run: dotnet nuget push "*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --prerelease

- name: Publish release to NuGet.org
if: steps.prerelease.outputs.IS_PRERELEASE == 'false'
run: dotnet nuget push "*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}