Skip to content

Publish NuGet Package to GitHub Registry #7

Publish NuGet Package to GitHub Registry

Publish NuGet Package to GitHub Registry #7

Workflow file for this run

name: Publish NuGet Package to GitHub Registry
on:
push:
branches:
- releases/*
create:
branches:
- releases/*
tags:
- releases/*
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract package information
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
if [[ "$BRANCH_NAME" =~ releases/([^/]+)/(.+) ]]; then
echo "PACKAGE=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV
else
echo "Branch name does not match the required pattern 'releases/{Package}/{Version}'"
exit 1
fi
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Pack the project
run: find -type f -name "$PACKAGE.csproj" | xargs -I {} dotnet pack "{}" --configuration Release --output ./nupkgs
- name: Validate package version
run: |
PACKAGE_FILE=$(find ./nupkgs -name '$PACKAGE.$VERSION.nupkg' | head -n 1)
if [ -z "$PACKAGE_FILE" ]; then
echo "No NuGet package '$PACKAGE.$VERSION.nupkg' found."
echo "Maybe the package or version doesn't match the expected '$PACKAGE' with version '$VERSION'."
ls ./nupkgs
exit 1
fi
- name: Publish NuGet package to GitHub Packages
run: dotnet nuget push ./nupkgs/$PACKAGE.$VERSION.nupkg --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json -k {{"${{ secrets.TOKEN_GITHUB }}"