Switch NuGet publishing to OIDC trusted publishing - #46
Merged
Merged
Conversation
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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Release.ymlandPreRelease.ymlnow use NuGet.org's Trusted Publishing (OIDC) instead of the long-livedNUGETORGAPIKEYsecret.id-token: writepermission (pluscontents: write, already implicitly needed for the release-creation step inRelease.yml).NuGet/login@v1step immediately beforePack & Publishthat exchanges the GitHub OIDC token for a short-lived NuGet API key, passed to the build viaNUGET_API_KEY.Follow-ups required outside this PR
Release.ymlandPreRelease.yml.NUGET_USERrepo secret containing the nuget.org profile username (not email).NUGETORGAPIKEYsecret.Test plan
NUGET_USERsecret added to repoPreReleaseworkflow manually and confirm package publishes successfullyReleaseworkflow manually and confirm package + GitHub release publish successfully