Skip to content

Improves dependency management and release process #8

Improves dependency management and release process

Improves dependency management and release process #8

name: Build, Test and Publish
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetches all history for all tags and branches
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: '**/bin/Release/*.nupkg'
publish:
name: Publish to NuGet
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetches all history for all tags and branches
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Extract version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION from ${GITHUB_REF}"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release /p:Version=${{ steps.get_version.outputs.VERSION }} --no-restore
- name: Pack
run: dotnet pack --configuration Release /p:Version=${{ steps.get_version.outputs.VERSION }} --no-build --output .
- name: Push to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json