From a9ea3670cc4b31725c5373835b8d1f6186842da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Thu, 9 Apr 2026 20:30:50 +0200 Subject: [PATCH] Publish a nuget package with optional restriction to a name --- lnx/publish-nuget/action.yml | 30 ++++++++++++++++++++++++++++++ win/publish-nuget/action.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 lnx/publish-nuget/action.yml create mode 100644 win/publish-nuget/action.yml diff --git a/lnx/publish-nuget/action.yml b/lnx/publish-nuget/action.yml new file mode 100644 index 0000000..ea55279 --- /dev/null +++ b/lnx/publish-nuget/action.yml @@ -0,0 +1,30 @@ +name: 'publish-nuget' +description: 'Publishes a NuGet package.' + +inputs: + api-key: + description: 'The API key to use for publishing the package.' + required: true + package-name: + description: 'The name of the NuGet package contains (contains check).' + default: '' + source-url: + description: 'The URL of the NuGet server to publish to. Defaults to https://api.nuget.org/v3/index.json.' + default: 'https://api.nuget.org/v3/index.json' + +runs: + using: 'composite' + steps: + - name: Publish NuGet package(s) + shell: bash + run: | + nugetFiles=$(find . -type f -name "*.nupkg") + + if [ -n "${{ inputs.package-name }}" ]; then + nugetFiles=$(echo "$nugetFiles" | grep "${{ inputs.package-name }}") + fi + + for nugetFile in $nugetFiles; do + echo "Publishing package: $(basename "$nugetFile")" + dotnet nuget push "$nugetFile" --api-key "${{ inputs.api-key }}" --source "${{ inputs.source-url }}" --skip-duplicate + done \ No newline at end of file diff --git a/win/publish-nuget/action.yml b/win/publish-nuget/action.yml new file mode 100644 index 0000000..7d0af02 --- /dev/null +++ b/win/publish-nuget/action.yml @@ -0,0 +1,30 @@ +name: 'publish-nuget' +description: 'Publishes a NuGet package.' + +inputs: + api-key: + description: 'The API key to use for publishing the package.' + required: true + package-name: + description: 'The name of the NuGet package contains (contains check).' + default: '' + source-url: + description: 'The URL of the NuGet server to publish to. Defaults to https://api.nuget.org/v3/index.json.' + default: 'https://api.nuget.org/v3/index.json' + +runs: + using: 'composite' + steps: + - name: Publish NuGet package(s) + shell: powershell + run: | + $nugetFiles = Get-ChildItem -Recurse -File -Filter "*.nupkg" + + if (![string]::IsNullOrWhiteSpace("${{ inputs.package-name }}")) { + $nugetFiles = $nugetFiles | Where-Object { $_.BaseName -match "${{ inputs.package-name }}" } + } + + foreach ($nugetFile in $nugetFiles) { + Write-Host "Publishing package: $($nugetFile.Name)" + dotnet nuget push "$($nugetFile.FullName)" --api-key "${{ inputs.api-key }}" --source "${{ inputs.source-url }}" --skip-duplicate + } \ No newline at end of file