Skip to content

Publish to NuGet

Publish to NuGet #134

Workflow file for this run

name: Publish to NuGet
on:
push:
tags:
- 'primitives/v*'
- 'components/v*'
- 'icons-lucide/v*'
- 'icons-heroicons/v*'
- 'icons-feather/v*'
workflow_dispatch:
inputs:
package:
description: 'Package to publish'
required: true
type: choice
options:
- primitives
- components
- icons-lucide
- icons-heroicons
- icons-feather
version:
description: 'Version (e.g., 1.0.0-beta.4)'
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for MinVer
- name: Fetch tags
run: git fetch --force --tags
- name: Debug git info
run: |
echo "Current commit: $(git rev-parse HEAD)"
echo "Current branch/tag: $(git describe --tags --always)"
echo "All tags on this commit:"
git tag --points-at HEAD
echo "Git status:"
git status
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Determine package and version
id: package-info
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Manual workflow dispatch
PACKAGE="${{ inputs.package }}"
VERSION="${{ inputs.version }}"
echo "Manually triggered release"
else
# Tag push
TAG_NAME="${{ github.ref_name }}"
# Extract package name (e.g., "primitives" from "primitives/v1.0.0-beta.4")
PACKAGE=$(echo "$TAG_NAME" | cut -d'/' -f1)
# Extract version (e.g., "1.0.0-beta.4" from "primitives/v1.0.0-beta.4")
VERSION=$(echo "$TAG_NAME" | cut -d'/' -f2 | sed 's/^v//')
echo "Tag-triggered release"
fi
echo "package=$PACKAGE" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Determine project path and display name
case $PACKAGE in
primitives)
echo "project_path=src/BlazorBlueprint.Primitives/BlazorBlueprint.Primitives.csproj" >> $GITHUB_OUTPUT
echo "display_name=BlazorBlueprint.Primitives" >> $GITHUB_OUTPUT
;;
components)
echo "project_path=src/BlazorBlueprint.Components/BlazorBlueprint.Components.csproj" >> $GITHUB_OUTPUT
echo "display_name=BlazorBlueprint.Components" >> $GITHUB_OUTPUT
;;
icons-lucide)
echo "project_path=src/BlazorBlueprint.Icons.Lucide/BlazorBlueprint.Icons.Lucide.csproj" >> $GITHUB_OUTPUT
echo "display_name=BlazorBlueprint.Icons.Lucide" >> $GITHUB_OUTPUT
;;
icons-heroicons)
echo "project_path=src/BlazorBlueprint.Icons.Heroicons/BlazorBlueprint.Icons.Heroicons.csproj" >> $GITHUB_OUTPUT
echo "display_name=BlazorBlueprint.Icons.Heroicons" >> $GITHUB_OUTPUT
;;
icons-feather)
echo "project_path=src/BlazorBlueprint.Icons.Feather/BlazorBlueprint.Icons.Feather.csproj" >> $GITHUB_OUTPUT
echo "display_name=BlazorBlueprint.Icons.Feather" >> $GITHUB_OUTPUT
;;
*)
echo "Unknown package: $PACKAGE"
exit 1
;;
esac
echo "📦 Package: $PACKAGE"
echo "🏷️ Version: $VERSION"
- name: Download Tailwind CSS standalone CLI
run: |
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v4.1.16/tailwindcss-linux-x64
chmod +x tailwindcss-linux-x64
mv tailwindcss-linux-x64 tools/tailwindcss-linux
echo "Tailwind CSS standalone CLI installed"
./tools/tailwindcss-linux --help | head -1
- name: Pre-generate Tailwind CSS
run: |
echo "Pre-generating Tailwind CSS so it exists before dotnet build evaluates the project..."
./tools/tailwindcss-linux -i src/BlazorBlueprint.Components/wwwroot/css/blazorblueprint-input.css -o src/BlazorBlueprint.Components/wwwroot/blazorblueprint.css --minify
echo "Generated blazorblueprint.css ($(wc -c < src/BlazorBlueprint.Components/wwwroot/blazorblueprint.css) bytes)"
- name: Run API surface tests
run: dotnet test tests/BlazorBlueprint.Tests/BlazorBlueprint.Tests.csproj --configuration Release --verbosity normal
# Restore, Build, and Pack run AFTER tests because `dotnet test` on the test
# project rebuilds Components via ProjectReference (without UsePackageReferences),
# which would overwrite the build cache with MinVer-generated prerelease versions
# for Primitives and Icons.Lucide. Building last ensures the cache is correct
# for the --no-build pack step.
- name: Restore dependencies
run: |
# For components package, use NuGet package references instead of project references
if [ "${{ steps.package-info.outputs.package }}" = "components" ]; then
dotnet restore ${{ steps.package-info.outputs.project_path }} -p:UsePackageReferences=true
else
dotnet restore ${{ steps.package-info.outputs.project_path }}
fi
- name: Build
run: |
# For components package, use NuGet package references instead of project references
if [ "${{ steps.package-info.outputs.package }}" = "components" ]; then
dotnet build ${{ steps.package-info.outputs.project_path }} --configuration Release --no-restore -p:UsePackageReferences=true
else
dotnet build ${{ steps.package-info.outputs.project_path }} --configuration Release --no-restore
fi
echo "Checking MinVer calculated version..."
dotnet msbuild ${{ steps.package-info.outputs.project_path }} -getProperty:Version -p:Configuration=Release
- name: Pack
run: |
# For components package, use NuGet package references instead of project references
if [ "${{ steps.package-info.outputs.package }}" = "components" ]; then
dotnet pack ${{ steps.package-info.outputs.project_path }} --configuration Release --no-build --output ./packages -p:UsePackageReferences=true
else
dotnet pack ${{ steps.package-info.outputs.project_path }} --configuration Release --no-build --output ./packages
fi
- name: Verify package version
shell: bash
run: |
PACKAGE_FILE=$(ls ./packages/*.nupkg)
echo "Created package: $PACKAGE_FILE"
# Extract version from package filename
# Remove package name prefix and .nupkg suffix
PACKAGE_NAME="${{ steps.package-info.outputs.display_name }}"
BASENAME=$(basename "$PACKAGE_FILE" .nupkg)
PACKAGE_VERSION="${BASENAME#$PACKAGE_NAME.}"
echo "Package name: $PACKAGE_NAME"
echo "Package version: $PACKAGE_VERSION"
echo "Expected version: ${{ steps.package-info.outputs.version }}"
# Verify version matches
if [ "$PACKAGE_VERSION" != "${{ steps.package-info.outputs.version }}" ]; then
echo "❌ Version mismatch! Package has version $PACKAGE_VERSION but expected ${{ steps.package-info.outputs.version }}"
echo "This usually means the git tag doesn't match the MinVer configuration."
exit 1
fi
echo "✅ Version verified successfully"
- name: Push to NuGet
run: dotnet nuget push ./packages/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Summary
shell: bash
run: |
echo "## 🎉 Release Complete!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Package:** ${{ steps.package-info.outputs.display_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.package-info.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The package has been published to NuGet.org and should be available shortly." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔗 [View on NuGet.org](https://www.nuget.org/packages/${{ steps.package-info.outputs.display_name }}/${{ steps.package-info.outputs.version }})" >> $GITHUB_STEP_SUMMARY