Skip to content

Build and Publish to NuGet #12

Build and Publish to NuGet

Build and Publish to NuGet #12

Workflow file for this run

name: Build and Publish to NuGet
on:
push:
tags:
- 'v*.*.*'
branches: [ master, main ]
paths:
- 'src/Base58Encoding/**'
- '!src/Base58Encoding.Tests/**'
- '!src/Base58Encoding.Benchmarks/**'
pull_request:
branches: [ master, main ]
paths:
- 'src/Base58Encoding/**'
- '!src/Base58Encoding.Tests/**'
- '!src/Base58Encoding.Benchmarks/**'
workflow_dispatch:
inputs:
version:
description: 'Package version (e.g., 1.0.0)'
required: false
type: string
permissions:
id-token: write # required for GitHub OIDC
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Get version from tag
if: startsWith(github.ref, 'refs/tags/v')
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Get version from input
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
run: echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Restore dependencies
run: dotnet restore src/Base58Encoding.slnx
- name: Build
run: dotnet build src/Base58Encoding.slnx --configuration Release --no-restore
- name: Test
run: dotnet test src/Base58Encoding.Tests/Base58Encoding.Tests.csproj --configuration Release --no-build --verbosity normal
- name: Pack
if: env.VERSION != ''
run: dotnet pack src/Base58Encoding/Base58Encoding.csproj --configuration Release --no-build --output ./artifacts -p:PackageVersion=${{ env.VERSION }}
- name: Upload artifacts
if: env.VERSION != ''
uses: actions/upload-artifact@v4
with:
name: nupkg
path: ./artifacts/*.nupkg
publish:
needs: build
runs-on: ubuntu-latest
# Only publish on version tags or manual trigger with version
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.version != '')
permissions:
contents: write
id-token: write # enable GitHub OIDC token issuance for this job
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: nupkg
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: NuGet login (OIDC → temp API key)
uses: NuGet/login@v1
id: login
with:
user: ${{ secrets.NUGET_USER }}
- name: Publish to NuGet
run: dotnet nuget push ./artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --skip-duplicate
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: ./artifacts/*.nupkg
generate_release_notes: true