Skip to content

Deploy NuGet package #134

Deploy NuGet package

Deploy NuGet package #134

name: Deploy NuGet package
on:
workflow_dispatch:
inputs:
environment:
description: Deployment environment
type: choice
options:
- pkg.github.com
- nuget.org
default: pkg.github.com
required: true
preview:
description: Append preview suffix
type: boolean
default: true
required: true
dry_run:
description: 'Dry-run only (no deploy)'
type: boolean
default: true
required: true
concurrency:
group: ${{ inputs.environment }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_info.outputs.version }}
pkg_url: ${{ steps.package_info.outputs.pkg_url }}
pkg_name: ${{ steps.package_info.outputs.pkg_name }}
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
dotnet-quality: "ga"
- name: Setup GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: "5.x"
preferLatestVersion: true
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libxml2-utils
- name: Determine version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
with:
updateAssemblyInfo: true
useConfigFile: true
configFilePath: src/gitversion.yml
- name: Compose version
id: version_info
run: |
# get base version
base="${{ steps.gitversion.outputs.majorMinorPatch }}"
# determine preview suffix
preview_tag="${{ inputs.preview && '-preview.' || '' }}"
# determine preview number
preview_num="${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || '' }}"
# combine all parts
ver="${base}${preview_tag}${preview_num}"
echo "version=$ver" >> "$GITHUB_OUTPUT"
- name: Compose package info
id: package_info
run: |
PACKAGE_NAME=$(xmllint --xpath "//PropertyGroup/PackageId/text()" src/Indicators.csproj)
echo "pkg_name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
if [[ "${{ inputs.environment }}" == "nuget.org" ]]; then
echo "pkg_url=https://www.nuget.org/packages/${PACKAGE_NAME}/${{ steps.version_info.outputs.version }}" >> $GITHUB_OUTPUT
else
echo "pkg_url=https://github.com/${{ github.repository }}/pkgs/nuget/${PACKAGE_NAME}" >> $GITHUB_OUTPUT
fi
- name: Build library
run: >
dotnet build src/Indicators.csproj
--configuration Release
--property:Version=${{ steps.version_info.outputs.version }}
--property:ContinuousIntegrationBuild=true
-warnAsError
- name: Pack for NuGet
run: >
dotnet pack src/Indicators.csproj
--configuration Release
--no-build
--include-symbols
--output NuGet
-p:PackageVersion=${{ steps.version_info.outputs.version }}
- name: Save package
uses: actions/upload-artifact@v4
with:
name: packages
path: NuGet
include-hidden-files: true
- name: Summary output
run: |
{
echo "| Version No. | Component |"
echo "| :---------- | :---------------------------------------------- |"
echo "| Major | ${{ steps.gitversion.outputs.major }} |"
echo "| Minor | ${{ steps.gitversion.outputs.minor }} |"
echo "| Patch | ${{ steps.gitversion.outputs.patch }} |"
echo "| Base | ${{ steps.gitversion.outputs.majorMinorPatch }} |"
echo "| Composed | ${{ steps.version_info.outputs.version }} |"
} >> $GITHUB_STEP_SUMMARY
deploy:
needs: build
runs-on: ubuntu-latest
if: success()
permissions:
contents: write
packages: write
environment:
name: ${{ !inputs.dry_run && inputs.environment || '' }}
url: ${{ needs.build.outputs.pkg_url }}
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
dotnet-quality: "ga"
- name: Download package
uses: actions/download-artifact@v4
with:
name: packages
path: NuGet
- name: Publish package
if: ${{ !inputs.dry_run }}
env:
API_KEY: ${{ inputs.environment == 'nuget.org' && secrets.NUGET_TOKEN || secrets.GITHUB_TOKEN }}
run: >
dotnet nuget push NuGet/*.nupkg
--source "${{ vars.NUGET_PUBLISH_URL }}"
--api-key "$API_KEY"
--skip-duplicate
- name: Tag and draft release note
uses: ncipollo/release-action@v1
if: ${{ !inputs.dry_run && inputs.environment == 'nuget.org' }}
with:
body: |
## Release ${{ needs.build.outputs.version }}
📦 Package deployed to [${{ inputs.environment }}](${{ needs.build.outputs.pkg_url }})
### Package Details
- **Name**: ${{ needs.build.outputs.pkg_name }}
- **Version**: ${{ needs.build.outputs.version }}
- **Preview**: ${{ inputs.preview && 'Yes' || 'No' }}
generateReleaseNotes: true
draft: true
makeLatest: ${{ !inputs.preview }}
prerelease: ${{ inputs.preview }}
tag: v${{ needs.build.outputs.version }}
commit: ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Deployment summary
if: always()
run: |
{
echo "## Package Deployment"
echo "| Parameter | Value |"
echo "|:------------|:------|"
echo "| Mode | ${{ inputs.dry_run && '🔍 DRY RUN' || '🚀 DEPLOY' }} |"
echo "| Status | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |"
echo "| Environment | ${{ inputs.environment }} |"
echo "| Version | ${{ needs.build.outputs.version }} |"
echo "| Package | [${{ needs.build.outputs.pkg_name }}](${{ needs.build.outputs.pkg_url }}) |"
echo "| Preview | ${{ inputs.preview && '✓' || '✗' }} |"
} >> $GITHUB_STEP_SUMMARY