Skip to content

Publish NuGet Packages #1

Publish NuGet Packages

Publish NuGet Packages #1

Workflow file for this run

name: Publish NuGet Packages
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Package version (e.g. 3.1.0, 3.1.0-preview.1). Leave empty to derive from tag or branch.'
required: false
permissions:
packages: write
contents: read
jobs:
publish:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x
- name: Determine version
id: version
shell: bash
run: |
if [[ -n "${{ github.event.inputs.version }}" ]]; then
VERSION="${{ github.event.inputs.version }}"
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
# Strip leading 'v' from tag (v3.1.0 -> 3.1.0)
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
else
# Fallback: use VersionPrefix from Global.props + short SHA for pre-release
VERSION="3.0.0-dev.${{ github.run_number }}"
fi
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "Resolved version: $VERSION"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore /p:Version=${{ steps.version.outputs.VERSION }}
- name: Run tests
run: dotnet test --configuration Release --no-build --verbosity normal
- name: Pack NuGet packages
run: dotnet pack --configuration Release --no-build --output ./nupkgs /p:Version=${{ steps.version.outputs.VERSION }}
- name: Push to GitHub Packages
run: dotnet nuget push "./nupkgs/*.nupkg" --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
env:
DOTNET_NOLOGO: true
- name: Upload packages as artifact
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ./nupkgs/
retention-days: 30