Skip to content

ci: publish to NuGet via Trusted Publishing, not a long-lived key - #173

Merged
phmatray merged 2 commits into
devfrom
ci/nuget-trusted-publishing
Jul 27, 2026
Merged

ci: publish to NuGet via Trusted Publishing, not a long-lived key#173
phmatray merged 2 commits into
devfrom
ci/nuget-trusted-publishing

Conversation

@phmatray

Copy link
Copy Markdown
Owner

continuous.yml passed a long-lived NUGET_API_KEY into the Nuke build. It now uses Trusted Publishing: GitHub's OIDC token is exchanged for a NuGet key valid ~1 hour, passed through the same NUGET_API_KEY variable. The only remaining secret is NUGET_USER — the nuget.org profile name, not a credential.

build/Build.cs is 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: Continuous triggers PublishIfNeeded, which is OnlyWhenStatic(IsOnVersionTag() && IsServerBuild) before it ever reaches Publish's Requires(NuGetApiKey). Pushes to main/dev and every pull_request run 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 NU1902AngleSharp 1.4.0 has 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

  1. Register a Trusted Publishing policy on nuget.org for FormCraft and FormCraft.ForMudBlazor, naming phmatray/FormCraft and continuous.yml.
  2. Set the NUGET_USER secret.
  3. Cut one release, confirm both packages appear, then delete NUGET_API_KEY.

phmatray added 2 commits July 25, 2026 15:10
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
phmatray force-pushed the ci/nuget-trusted-publishing branch from 9bc7c03 to 3cbd38d Compare July 27, 2026 18:46
@phmatray
phmatray merged commit 39c91a4 into dev Jul 27, 2026
2 checks passed
@phmatray
phmatray deleted the ci/nuget-trusted-publishing branch July 27, 2026 18:48
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