Skip to content

ci: publish to NuGet with trusted publishing instead of an API key - #19

Merged
RobertPoienar merged 1 commit into
masterfrom
ci/nuget-trusted-publishing
Nov 13, 2026
Merged

RobertPoienar merged 1 commit into
masterfrom
ci/nuget-trusted-publishing

Conversation

@RobertPoienar

Copy link
Copy Markdown
Collaborator

Why

The release run for 1.0.10 (run 43404678995) packed the package, then failed on the push:

Forbidden https://www.nuget.org/api/v2/package/
error: Response status code does not indicate success: 403 (The specified API key is invalid, has expired, or does not have permission to access the specified package.)

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; it doesn't make an old key valid.

Change

release.yml:

  • the job gets id-token: write so it can request a GitHub OIDC token (contents: read for checkout)
  • NuGet/login@v1 exchanges that token for a short-lived API key, using the trusted publishing policy
  • dotnet nuget push uses that key; the NUGET_DEPLOY_KEY secret is no longer used
  • pack is now its own step, before login, so the short-lived key is requested only when there is something to push

Before running the release again

  • Add a repository secret NUGET_USER with the nuget.org profile name (not the email) of the account that created the trusted publishing policy.
  • The policy on nuget.org must match: owner alttester, repository alt-websocket-sharp, workflow file release.yml. If the policy names an environment, the job needs a matching environment: too; this PR doesn't set one.
  • The policy's package owner must be 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

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>
@RobertPoienar
RobertPoienar merged commit 1ecdf92 into master Nov 13, 2026
1 check passed
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