ci: publish to NuGet via Trusted Publishing, not a long-lived key - #173
Merged
Conversation
continuous.yml passed a NUGET_API_KEY repository secret into the Nuke build. It now exchanges the GitHub OIDC token for a key valid ~1 hour (NuGet/login v1.2.0) and passes that through the same NUGET_API_KEY variable, so build/Build.cs is unchanged — Nuke reads an env var and neither knows nor cares that the key expires. The only remaining secret is NUGET_USER, the nuget.org profile name. The login step is gated on a version tag, mirroring the build's own gate: Continuous triggers PublishIfNeeded, which is OnlyWhenStatic(IsOnVersionTag() && IsServerBuild) before it reaches Publish's Requires(NuGetApiKey). Pushes to main/dev and pull_request runs leave the key unset today and must keep doing so — minting one on a pull request would be pointless and would fail outright for a fork, which cannot obtain this repository's OIDC token. build/README.md's environment-variable note updated: in CI the variable is fed by the OIDC exchange, and only a local manual publish uses a real key. Note this repo's CI is currently red for an unrelated reason (NU1902, AngleSharp 1.4.0 advisory treated as an error); this change does not address that and cannot go green until the package is bumped.
phmatray
force-pushed
the
ci/nuget-trusted-publishing
branch
from
July 27, 2026 18:46
9bc7c03 to
3cbd38d
Compare
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.
continuous.ymlpassed a long-livedNUGET_API_KEYinto the Nuke build. It now uses Trusted Publishing: GitHub's OIDC token is exchanged for a NuGet key valid ~1 hour, passed through the sameNUGET_API_KEYvariable. The only remaining secret isNUGET_USER— the nuget.org profile name, not a credential.build/Build.csis unchanged. Nuke reads an environment variable; it neither knows nor cares that the key expires.The gate matters here, so I matched the build's own
The login step runs only on a version tag. That mirrors what the build already does:
ContinuoustriggersPublishIfNeeded, which isOnlyWhenStatic(IsOnVersionTag() && IsServerBuild)before it ever reachesPublish'sRequires(NuGetApiKey). Pushes tomain/devand everypull_requestrun leave the key unset today and must keep doing so — minting one on a pull request would be pointless, and would fail outright for a fork, which cannot obtain this repository's OIDC token.Heads-up: this repo's CI is already red, for an unrelated reason
The last three runs fail on
NU1902—AngleSharp 1.4.0has a known moderate-severity advisory (GHSA-pgww-w46g-26qg) and the build treats it as an error. This PR does not address that and will not go green until AngleSharp is bumped. I left it alone rather than mixing a dependency bump into a credentials change; happy to do it as a separate PR.Required before the next release
FormCraftandFormCraft.ForMudBlazor, namingphmatray/FormCraftandcontinuous.yml.NUGET_USERsecret.NUGET_API_KEY.