Skip to content

Publish NuGet (Run ID: latest build) #7

Publish NuGet (Run ID: latest build)

Publish NuGet (Run ID: latest build) #7

name: Publish NuGet Packages
run-name: "Publish NuGet (Run ID: ${{ inputs.run_id || 'latest build' }})"
on:
workflow_dispatch:
inputs:
run_id:
description: "Build workflow run ID (leave empty to use latest)"
required: false
type: string
use_local_storage:
description: "Use local artifact storage"
required: false
type: boolean
default: true
use_self_hosted_runners:
description: "Use self-hosted runners"
required: false
type: boolean
default: true
workflow_call:
inputs:
run_id:
description: "Build workflow run ID (leave empty to use latest)"
required: false
type: string
use_local_storage:
description: "Use local artifact storage"
required: false
type: boolean
default: true
use_self_hosted_runners:
description: "Use self-hosted runners"
required: false
type: boolean
default: true
permissions:
id-token: write
actions: read
contents: read
jobs:
publish:
name: Publish to NuGet.org
runs-on: ${{ inputs.use_self_hosted_runners && fromJson('["self-hosted","Linux"]') || fromJson('["ubuntu-latest"]') }}
environment: ${{ github.repository == 'bitbound/ControlR' && 'production' || 'development' }}
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Validate local storage configuration
uses: ./.github/actions/validate-local-storage
with:
use_local_storage: ${{ inputs.use_local_storage }}
artifact_host: ${{ vars.ARTIFACT_HOST }}
artifact_base_path: ${{ vars.ARTIFACT_BASE_PATH }}
- name: Get Latest Build Run ID
id: get-run-id
uses: ./.github/actions/get-latest-build-run-id
with:
run_id: ${{ inputs.run_id }}
github_token: ${{ github.token }}
- name: Download NuGet Packages
uses: ./.github/actions/download-artifact
with:
name: NuGetPackages
path: ./nuget-packages
github-token: ${{ github.token }}
artifact-host: ${{ inputs.use_local_storage && vars.ARTIFACT_HOST || '' }}
artifact-base-path: ${{ inputs.use_local_storage && vars.ARTIFACT_BASE_PATH || '' }}
run-id: ${{ steps.get-run-id.outputs.run_id }}
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: "10.x"
- name: NuGet login (OIDC)
uses: NuGet/login@v1
id: login
with:
user: ${{ secrets.NUGET_USER }}
- name: Publish to NuGet.org
shell: pwsh
run: |
# Push .nupkg files to the main NuGet feed
foreach ($package in Get-ChildItem -Path ./nuget-packages/*.nupkg) {
Write-Host "Publishing $($package.Name) to main feed..."
dotnet nuget push "$($package.FullName)" `
--api-key ${{ steps.login.outputs.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json `
--skip-duplicate
}
# Push .snupkg files to the symbol package feed
foreach ($package in Get-ChildItem -Path ./nuget-packages/*.snupkg) {
Write-Host "Publishing $($package.Name) to symbol feed..."
dotnet nuget push "$($package.FullName)" `
--api-key ${{ steps.login.outputs.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json?packageType=symbols `
--skip-duplicate
}
- name: Publish Complete
shell: pwsh
run: |
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "## NuGet Publish Summary"
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "**Files Published:**"
$packages = Get-ChildItem -Path ./nuget-packages/*.nupkg
foreach ($Item in $packages) {
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value " - $($Item.Name)"
}
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value ""
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value "✅ Successfully published to NuGet.org"