Publish NuGet Packages #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/workflows/publish-nuget.yml | |
name: Publish NuGet Packages | |
# This workflow is triggered manually from the GitHub Actions tab | |
on: | |
workflow_dispatch: | |
inputs: | |
version_bump: | |
description: 'release version' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
jobs: | |
publish: | |
name: Build, Pack, and Publish | |
runs-on: ubuntu-latest | |
env: | |
CORE_PROJECT_PATH: "CmdScale.EntityFrameworkCore.TimescaleDB/CmdScale.EntityFrameworkCore.TimescaleDB.csproj" | |
DESIGN_PROJECT_PATH: "CmdScale.EntityFrameworkCore.TimescaleDB.Design/CmdScale.EntityFrameworkCore.TimescaleDB.Design.csproj" | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Read, Bump, and Update Version | |
id: version_bumper | |
run: | | |
# Read the current version from the main .csproj file | |
CURRENT_VERSION=$(grep '<Version>' ${{ env.CORE_PROJECT_PATH }} | sed -n 's/.*<Version>\(.*\)<\/Version>.*/\1/p') | |
echo "Current version: $CURRENT_VERSION" | |
# Split the version into parts | |
IFS='.' read -r -a version_parts <<< "$CURRENT_VERSION" | |
major=${version_parts[0]} | |
minor=${version_parts[1]} | |
patch=${version_parts[2]} | |
# Increment the version based on the workflow input | |
case "${{ github.event.inputs.version_bump }}" in | |
major) | |
major=$((major + 1)); minor=0; patch=0 | |
;; | |
minor) | |
minor=$((minor + 1)); patch=0 | |
;; | |
patch) | |
patch=$((patch + 1)) | |
;; | |
esac | |
NEW_VERSION="$major.$minor.$patch" | |
echo "Bumping to new version: $NEW_VERSION" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT | |
# Update the <Version> tag in both .csproj files | |
sed -i "s|<Version>.*</Version>|<Version>$NEW_VERSION</Version>|g" ${{ env.CORE_PROJECT_PATH }} | |
sed -i "s|<Version>.*</Version>|<Version>$NEW_VERSION</Version>|g" ${{ env.DESIGN_PROJECT_PATH }} | |
- name: Commit and Tag Version Bump | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add ${{ env.CORE_PROJECT_PATH }} ${{ env.DESIGN_PROJECT_PATH }} | |
git commit -m "Bump version to ${{ steps.version_bumper.outputs.NEW_VERSION }}" | |
git push | |
git tag "v${{ steps.version_bumper.outputs.NEW_VERSION }}" | |
git push origin "v${{ steps.version_bumper.outputs.NEW_VERSION }}" | |
- name: Build and Pack | |
run: | | |
# Build the entire solution | |
dotnet clean | |
dotnet build -c Release | |
# Pack both projects | |
dotnet pack ${{ env.CORE_PROJECT_PATH }} -c Release --no-build -o ./packages | |
dotnet pack ${{ env.DESIGN_PROJECT_PATH }} -c Release --no-build -o ./packages | |
- name: Publish to NuGet.org | |
run: | | |
dotnet nuget push "./packages/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" |