Publish Nuget package #14
Workflow file for this run
This file contains 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
name: Publish Nuget package | |
on: | |
release: | |
types: | |
- published # Run the workflow when a release is published | |
env: | |
working-directory: ./ | |
NuGetDirectory: ${{ github.workspace}}/nuget | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.x | |
- name: Restore dependencies | |
run: dotnet restore | |
working-directory: ${{env.working-directory}} | |
- name: Build the project | |
run: dotnet build --configuration Release --no-restore | |
working-directory: ${{env.working-directory}} | |
- name: Run tests | |
run: dotnet test --configuration Release --no-build --verbosity normal | |
working-directory: ${{env.working-directory}} | |
# Create the NuGet package in the folder from the environment variable NuGetDirectory | |
- name: Pack the NuGet package | |
run: dotnet pack ./CacheDrive --configuration Release --no-build --output ${{env.NuGetDirectory}} | |
working-directory: ${{env.working-directory}} | |
# List the NuGet package | |
- name: List the NuGet package | |
run: ls ${{env.NuGetDirectory}} | |
# Publish the NuGet package as an artifact, so it can be used in other workflows or in the following jobs | |
- name: Publish the NuGet package as an artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget | |
if-no-files-found: error | |
retention-days: 7 | |
path: ${{env.NuGetDirectory}}/*.nupkg | |
publish: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Download the NuGet package | |
uses: actions/download-artifact@v4 | |
with: | |
name: nuget | |
path: ${{ env.NuGetDirectory }} | |
- name: List the NuGet package | |
run: ls ${{env.NuGetDirectory}} | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.x | |
- name: Publish the NuGet package | |
run: | | |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) { | |
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
} |