Skip to content

Publish NuGet Package #2

Publish NuGet Package

Publish NuGet Package #2

Workflow file for this run

name: Publish NuGet Package
on:
push:
tags:
- 'v*.*.*' # Triggers on version tags like v1.0.0, v2.1.3, etc.
workflow_dispatch: # Allows manual triggering from GitHub UI
inputs:
version:
description: 'Package version (e.g., 1.0.0)'
required: true
type: string
env:
DOTNET_VERSION: '10.0.x'
PROJECT_PATH: 'WebNet.LiteGraphExtensions.GraphRepositories.csproj'
NUGET_SOURCE: 'https://api.nuget.org/v3/index.json'
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Get full history for versioning
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Extract version from tag
id: get_version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/v}
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Package version: $VERSION"
- name: Restore dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}
- name: Build
run: dotnet build ${{ env.PROJECT_PATH }} --configuration Release --no-restore
- name: Run tests
run: dotnet test --configuration Release --no-build --verbosity normal
- name: Pack NuGet package
run: |
dotnet pack ${{ env.PROJECT_PATH }} \
--configuration Release \
--no-build \
--output ./artifacts \
-p:PackageVersion=${{ steps.get_version.outputs.VERSION }} \
-p:RepositoryUrl=${{ github.server_url }}/${{ github.repository }} \
-p:RepositoryCommit=${{ github.sha }}
- name: List artifacts
run: ls -la ./artifacts
- name: NuGet login (OIDC → temp API key)
uses: NuGet/login@v1
id: login
with:
user: makutamiserix
- name: Publish to NuGet.org
run: |
dotnet nuget push ./artifacts/*.nupkg \
--api-key ${{steps.login.outputs.NUGET_API_KEY}} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: ./artifacts/*.nupkg
retention-days: 30
- name: Create GitHub Release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: ./artifacts/*.nupkg
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}