Skip to content

Switch NuGet publishing to OIDC trusted publishing - #46

Merged
johnkors merged 3 commits into
mainfrom
jk/nuget-trusted-publishing
Sep 14, 2026
Merged

johnkors merged 3 commits into
mainfrom
jk/nuget-trusted-publishing

Conversation

@johnkors

Copy link
Copy Markdown
Contributor

Summary

  • Both Release.yml and PreRelease.yml now use NuGet.org's Trusted Publishing (OIDC) instead of the long-lived NUGETORGAPIKEY secret.
  • Added id-token: write permission (plus contents: write, already implicitly needed for the release-creation step in Release.yml).
  • Added a NuGet/login@v1 step immediately before Pack & Publish that exchanges the GitHub OIDC token for a short-lived NuGet API key, passed to the build via NUGET_API_KEY.

Follow-ups required outside this PR

  • Create a Trusted Publishing policy on nuget.org for this repo, pointing at Release.yml and PreRelease.yml.
  • Add a NUGET_USER repo secret containing the nuget.org profile username (not email).
  • Once verified working, remove the now-unused NUGETORGAPIKEY secret.

Test plan

  • Confirm Trusted Publishing policy created on nuget.org
  • Confirm NUGET_USER secret added to repo
  • Run PreRelease workflow manually and confirm package publishes successfully
  • Run Release workflow manually and confirm package + GitHub release publish successfully

Replaces the long-lived NUGETORGAPIKEY secret with NuGet.org's
Trusted Publishing flow: the workflow requests a GitHub OIDC token
and exchanges it for a short-lived NuGet API key via NuGet/login@v1
right before pushing.
Release.yml and PreRelease.yml duplicated the checkout/gitversion/
setup-dotnet/NuGet-login/pack-and-publish steps. Move that into
publish.yml (workflow_call) so each caller only supplies a
prerelease flag and consumes the resulting version outputs.
NuGet Trusted Publishing policies are keyed off the top-level
triggering workflow file, so having Release.yml and PreRelease.yml
as separate files meant configuring two trusted publishing policies
on nuget.org. Collapse them into one Release.yml with a `prerelease`
workflow_dispatch input; the GitHub release job is skipped when
prerelease is true. Only one nuget.org policy is needed now.
@johnkors
johnkors merged commit e5fb4a4 into main Sep 14, 2026
2 of 3 checks passed
@johnkors
johnkors deleted the jk/nuget-trusted-publishing branch September 14, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant