Skip to content

Commit

Permalink
Create DeployToNuget.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Nix1983 committed Nov 1, 2023
1 parent f394654 commit 8422126
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/DeployToNuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# .github/workflows/deploy-to-nuget.yml
name: Deploy to NuGet

on:
workflow_dispatch: # Manueller Trigger

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.x' # Update to your project's .NET version

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --verbosity normal

- name: Increment version number
run: |
# Retrieve the old version number from your .csproj file
OLD_VERSION=$(grep -oP '(?<=<Version>).*?(?=</Version>)' TablerForNet.csproj)
# Parse out the individual parts of the version
MAJOR=$(echo $OLD_VERSION | cut -d'.' -f1)
MINOR=$(echo $OLD_VERSION | cut -d'.' -f2)
PATCH=$(echo $OLD_VERSION | cut -d'.' -f3)
- name: Increment version numbers
run: |
# Retrieve the old version numbers from your .csproj file
OLD_VERSION=$(grep -oP '(?<=<Version>).*?(?=</Version>)' TablerForNet.csproj)
OLD_ASSEMBLY_VERSION=$(grep -oP '(?<=<AssemblyVersion>).*?(?=</AssemblyVersion>)' TablerForNet.csproj)
OLD_FILE_VERSION=$(grep -oP '(?<=<FileVersion>).*?(?=</FileVersion>)' TablerForNet.csproj)
# Parse out the individual parts of the version
MAJOR=$(echo $OLD_VERSION | cut -d'.' -f1)
MINOR=$(echo $OLD_VERSION | cut -d'.' -f2)
PATCH=$(echo $OLD_VERSION | cut -d'.' -f3)
# Increment the version number
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH.0"
NEW_ASSEMBLY_VERSION="$MAJOR.$MINOR.$NEW_PATCH.0"
NEW_FILE_VERSION="$MAJOR.$MINOR.$NEW_PATCH.0"
# Update the .csproj file with the new version numbers
sed -i "s/<Version>$OLD_VERSION<\/Version>/<Version>$NEW_VERSION<\/Version>/" TablerForNet.csproj
sed -i "s/<AssemblyVersion>$OLD_ASSEMBLY_VERSION<\/AssemblyVersion>/<AssemblyVersion>$NEW_ASSEMBLY_VERSION<\/AssemblyVersion>/" TablerForNet.csproj
sed -i "s/<FileVersion>$OLD_FILE_VERSION<\/FileVersion>/<FileVersion>$NEW_FILE_VERSION<\/FileVersion>/" TablerForNet.csproj
- name: Pack
run: dotnet pack --no-build -c Release -o out

- name: Push new version
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add TablerForNet.csproj
git commit -m "Increment version to $NEW_VERSION"
git push origin master
- name: Push to NuGet
run: dotnet nuget push out/*.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json

0 comments on commit 8422126

Please sign in to comment.