Repository navigation
ci: publish .NET SDK packages with NuGet trusted publishing, only when the version is new - #894
Merged
vadim-korolik merged 3 commits intoNov 18, 2026
Conversation
Both jobs re-push the same Highlight.ASPCore 0.2.16 / Highlight.ASP4 0.2.10 packages on every main push and relied on --skip-duplicate. Since 2026-04-16 nuget.org rejects the push before the duplicate check because NUGET_API_KEY (last set 2025-04-16) hit nuget.org's 365-day key expiry, so the job fails on every push. Check nuget.org's flat container first and only push when a package version is not published yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-by: termag
Contributor
Author
|
bugbot run |
vadim-korolik
marked this pull request as ready for review
November 17, 2026 22:36
Replace the expired long-lived NUGET_API_KEY secret with nuget.org trusted publishing: when a new version needs pushing, NuGet/login (v1.2.0, pinned by SHA) exchanges the job's GitHub OIDC token for a one-hour API key, which the push step uses. Both jobs get permissions contents: read and id-token: write. The nuget.org profile name comes from the NUGET_USER repo variable. The "only push when the version is not on nuget.org" check is kept, and login runs only when a push will happen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-by: termag
The nuget.org profile name is stored as the NUGET_USER repository secret (as NuGet's trusted publishing docs suggest), not a variable, so vars.NUGET_USER would pass an empty user to NuGet/login. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Generated-by: termag
abelonogov-ld
approved these changes
Nov 18, 2026
vadim-korolik
deleted the
termag-vkorolik/cmwl8thxv0hs37bf97g5455aw-dotnet-nuget
branch
November 18, 2026 01:00
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.
Demo
Before/fix/after transcript: https://app.termag.ldinfra.net/termag/files/vkorolik-observability-sdk/artifacts/ci-devskim-dotnet/dotnet-demo.md
Why main fails
Both jobs of
.NET SDKhave failed at "Push generated package to NuGet registry" on every push tomainsince 2026-04-16. The last green run was 2026-04-15, and no .NET code changed between the two..github/workflows/dotnet.yml:35-39(ASP.NET Core) and:67-70(ASP.NET4) push on every main push. The versions they push are Highlight.ASPCore 0.2.16 (published 2025-03-25) and Highlight.ASP4 0.2.10, both already on nuget.org. So each push was a duplicate, and--skip-duplicate/-SkipDuplicateturned nuget.org's 409 into a pass.NUGET_API_KEYrepo secret was last updated 2025-04-16T19:49Z. The first failure was 2026-04-16T21:02Z, which matches nuget.org's 365-day maximum key lifetime. nuget.org rejects an expired key before it checks for duplicates, so the push exits 1.Change
.github/scripts/nuget-needs-publish.sh), looks up each built.nupkg's id and version (symbols skipped) in nuget.org's flat-container index. It writespublish=trueonly when a version isn't published yet. Pushes tomainthat don't bump a version no longer touch NuGet.NUGET_API_KEY, as in NuGet's docs:permissions: contents: read, id-token: write.NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0withuser: ${{ secrets.NUGET_USER }}, runs only when a push will happen. This is the docs'NuGet/login@v1, pinned by SHA like the repo's other third-party actions (SEC-7924). It trades the job's GitHub OIDC token for a nuget.org API key that lasts one hour.steps.login.outputs.NUGET_API_KEYthrough an env var. ASP.NET Core usesdotnet nuget push --api-key "$NUGET_API_KEY". ASP.NET4 keeps itsnuget push bin\**\*.nupkgcommand (now-ApiKey $env:NUGET_API_KEY). I dropped-SymbolApiKeybecause the project builds no symbol packages.dotnet.ymlno longer referencessecrets.NUGET_API_KEY. I didn't delete the secret.observability-dotnethas no NuGet release workflow here.Verification
highlight.aspcore 0.2.16andhighlight.asp4 0.2.10are already on nuget.org. Both the "NuGet login" and "Push" steps were skipped, and nothing was published.actionlint1.7.12 reports only the custom runner label, whichmainalso has.secrets.NUGET_USER(3c4e6f9): PR run 44207123511 passed on both jobs, with login and push skipped. actionlint is unchanged.mainwhen a version is new, so they can't be tested until the next version bump of Highlight.ASPCore or Highlight.ASP4. Before that bump, do the setup below. Otherwise the first push fails at "NuGet login".Setup needed on nuget.org
These must match
.github/workflows/dotnet.ymlexactly, orNuGet/loginfails (fields are case-insensitive).Highlightorganization, which owns both Highlight.ASPCore and Highlight.ASP4. Then choose your username → Trusted Publishing → add a GitHub Actions policy:Highlight. The policy covers every package that owner has, which includes Highlight.ASPCore and Highlight.ASP4.launchdarklyobservability-sdkdotnet.yml(file name only, no.github/workflows/path)environment:.NUGET_USER(Settings → Secrets and variables → Actions → Secrets), set 2026-11-18. It holds the nuget.org username (profile name, not email) of the account that created the policy. The workflow passes it asuser: ${{ secrets.NUGET_USER }}toNuGet/login, as NuGet's docs recommend.dotnet.yml. Renaming it breaks the policy.NUGET_API_KEYrepo secret. Nothing in the repo uses it any more, and this PR leaves it in place.Related
The DevSkim half of this ask: #893.
Asked by
vkorolikthroughtermag ask; follow up withtermag ask … --thread cmwl8thxv0hs37bf97g5455aw.🤖 Generated with Claude Code
Opened from termag