Skip to content

Manual NuGet Push workflow #25

Manual NuGet Push workflow

Manual NuGet Push workflow #25

name: Manual NuGet Push workflow
# Controls when the action will run. Workflow runs when manually triggered using the UI or API
on: workflow_dispatch
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
defaults:
run:
shell: pwsh
jobs:
create_nuget_packages:
name: Create NuGet packages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0'
- name: Pack NuGet packages
run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg
run_tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0'
- name: Run tests
run: dotnet test --configuration Release
deploy_nuget_packages:
name: Deploy NuGet packages
runs-on: ubuntu-latest
needs: [ create_nuget_packages, run_tests ]
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0'
- name: Publish NuGet packages
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}