Repository navigation
ci: publish to NuGet with trusted publishing instead of an API key - #19
Merged
Merged
Conversation
The release run for 1.0.10 failed with 403 "The specified API key is invalid, has expired, or does not have permission": the workflow still pushed with the NUGET_DEPLOY_KEY secret. A trusted publishing policy on nuget.org is only used when the workflow asks for it, so the job now requests an OIDC token (id-token: write) and exchanges it for a short-lived key with NuGet/login. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
The
releaserun for 1.0.10 (run 43404678995) packed the package, then failed on the push:The workflow still pushed with the
NUGET_DEPLOY_KEYsecret. A trusted publishing policy on nuget.org is only used when the workflow asks for it; it doesn't make an old key valid.Change
release.yml:id-token: writeso it can request a GitHub OIDC token (contents: readfor checkout)NuGet/login@v1exchanges that token for a short-lived API key, using the trusted publishing policydotnet nuget pushuses that key; theNUGET_DEPLOY_KEYsecret is no longer usedBefore running the release again
NUGET_USERwith the nuget.org profile name (not the email) of the account that created the trusted publishing policy.alttester, repositoryalt-websocket-sharp, workflow filerelease.yml. If the policy names an environment, the job needs a matchingenvironment:too; this PR doesn't set one.Altom(the owner of AltWebSocketSharp on nuget.org).1.0.10 was not pushed by the failed run, so rerunning the workflow after merge will publish it.
Testing
The YAML parses. I could not run it end to end: the token exchange only works in Actions against the real policy.
🤖 Generated with Claude Code