Version.Nuget.Publish #13
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: Version.Nuget.Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
push: | |
branches: | |
- main | |
defaults: | |
run: | |
shell: pwsh | |
jobs: | |
publish: | |
name: Build, pack & publish | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup dotnet | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: | | |
6.x | |
8.x | |
- name: Install dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --configuration Release --no-restore --verbosity normal | |
# Publish | |
# Create the NuGet package in the package folder | |
- name: Pack | |
run: dotnet pack --configuration Release --no-build --output package | |
# Publish the NuGet package as an artifact, so they can be used in the following jobs | |
#- uses: actions/upload-artifact@v3 | |
# with: | |
# name: nuget | |
# if-no-files-found: error | |
# retention-days: 7 | |
# path: ${{ package}}/*.nupkg | |
- name: Publish nupkg and snupkg to NuGet.org | |
run: | | |
foreach ($file in Get-ChildItem package -Recurse -Include *.nupkg) { | |
# Extract the version part from the file name | |
$version = [regex]::Match($file.Name, '\d+\.\d+\.\d+(-[a-zA-Z]+\.\d+)?').Value | |
# Allow only non-prerelease or beta versions | |
if ($version -notmatch '-alpha' -and ($version -notmatch '-' -or $version -match '-beta')) { | |
Write-Host "Publishing $file..." | |
dotnet nuget push $file.FullName --api-key "${{ secrets.WRAPTHATNUGET }}" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
} else { | |
Write-Host "::warning file=$($file.FullName)::Skipping package with version $version (alpha versions are not allowed)." | |
} | |
} | |