You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ci: publish via NuGet Trusted Publishing (keyless OIDC) (#2)
Replace the long-lived NUGET_API_KEY secret with NuGet.org Trusted
Publishing per the official docs. The publish job now requests a GitHub
OIDC token (id-token: write) and NuGet/login@v1 exchanges it for a
short-lived (1 h) API key used by dotnet nuget push. The only secret
needed is NUGET_USER (the nuget.org profile name). The old
"Require NUGET_API_KEY secret" guard is replaced by a NUGET_USER guard,
and the header comment's outdated "not GA / not supported" rationale is
removed. All other behavior (master gate, version resolution, tag check,
pack, dry_run, tag + GitHub release) is preserved. CHANGELOG updated.
# Fail fast if the publish secret is missing so a run cannot silently pass without publishing.
87
-
- name: Require NUGET_API_KEY secret
88
+
# Fail fast if the trusted-publishing username is missing so a run cannot silently pass without publishing.
89
+
# Note: this only checks the secret. The other prerequisite — a Trusted Publishing policy registered on
90
+
# nuget.org for this repo/workflow (Workflow File = dotnet-publish.yml) — cannot be checked here; if it is
91
+
# missing the NuGet/login step below fails with nuget.org's own error.
92
+
- name: Require NUGET_USER secret
88
93
if: ${{ github.event.inputs.dry_run != 'true' }}
89
94
env:
90
-
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
95
+
NUGET_USER: ${{ secrets.NUGET_USER }}
91
96
run: |
92
-
if [ -z "${NUGET_API_KEY}" ]; then
93
-
echo "::error::NUGET_API_KEY secret is empty or missing; cannot publish to NuGet.org."
97
+
if [ -z "${NUGET_USER}" ]; then
98
+
echo "::error::NUGET_USER secret is empty or missing (set it to the nuget.org profile name, not an email). A NuGet Trusted Publishing policy for this repo/workflow must also be registered on nuget.org; see https://learn.microsoft.com/en-us/nuget/nuget-org/trusted-publishing"
94
99
exit 1
95
100
fi
96
101
102
+
# Exchange the GitHub OIDC token for a short-lived NuGet API key. Trusted Publishing keys expire
103
+
# after 1 hour, so this runs immediately before the push (not earlier in the job).
104
+
- name: NuGet login (OIDC -> short-lived API key)
105
+
id: login
106
+
if: ${{ github.event.inputs.dry_run != 'true' }}
107
+
uses: NuGet/login@v1
108
+
with:
109
+
user: ${{ secrets.NUGET_USER }}
110
+
97
111
- name: Push to NuGet
98
112
if: ${{ github.event.inputs.dry_run != 'true' }}
99
-
env:
100
-
# The NuGet.org API key is stored as a repository secret.
0 commit comments