-
Notifications
You must be signed in to change notification settings - Fork 663
feat: support nuget.org Trusted Publishing via GitHub Actions OIDC #4884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
c483a48
62df16f
22980a2
74227d4
a1bc95e
494021c
12f1b78
b933173
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,17 @@ public override async Task RunAsync(BuildContext context) | |
| if (context.IsTaggedRelease || context.IsTaggedPreRelease) | ||
| { | ||
| context.StartGroup("Publishing to Nuget.org"); | ||
| var apiKey = context.Credentials?.Nuget?.ApiKey; | ||
|
|
||
| // Prefer Trusted Publishing via OIDC token exchange (no long-lived API key required) | ||
| var apiKey = await GetNugetApiKey(context); | ||
|
|
||
| // Fall back to a static API key when OIDC is not available | ||
| if (string.IsNullOrEmpty(apiKey)) | ||
| { | ||
| context.Information("OIDC token exchange unavailable; falling back to static NuGet API key."); | ||
| apiKey = context.Credentials?.Nuget?.ApiKey; | ||
| } | ||
|
Comment on lines
+47
to
+55
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot implement this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The OIDC token exchange with static API key fallback was already implemented in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The OIDC token exchange (with fallback to static |
||
|
|
||
| if (string.IsNullOrEmpty(apiKey)) | ||
| { | ||
| throw new InvalidOperationException("Could not resolve NuGet org API key."); | ||
|
|
@@ -52,8 +62,6 @@ public override async Task RunAsync(BuildContext context) | |
| PublishToNugetRepo(context, apiKey, Constants.NugetOrgUrl); | ||
| context.EndGroup(); | ||
| } | ||
|
|
||
| await Task.CompletedTask; | ||
| } | ||
|
|
||
| private static void PublishToNugetRepo(BuildContext context, string apiKey, string apiUrl) | ||
|
|
@@ -85,17 +93,22 @@ private static void PublishToNugetRepo(BuildContext context, string apiKey, stri | |
| } | ||
| catch (HttpRequestException ex) | ||
| { | ||
| context.Error($"Network error while retrieving NuGet API key: {ex.Message}"); | ||
| context.Warning($"Network error while retrieving NuGet API key via OIDC: {ex.Message}"); | ||
| return null; | ||
| } | ||
| catch (InvalidOperationException ex) | ||
| { | ||
| context.Error($"Invalid operation while retrieving NuGet API key: {ex.Message}"); | ||
| context.Warning($"OIDC not available for NuGet API key retrieval: {ex.Message}"); | ||
| return null; | ||
| } | ||
| catch (JsonException ex) | ||
| { | ||
| context.Error($"JSON parsing error while retrieving NuGet API key: {ex.Message}"); | ||
| context.Warning($"JSON parsing error while retrieving NuGet API key via OIDC: {ex.Message}"); | ||
| return null; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| context.Warning($"Unexpected error while retrieving NuGet API key via OIDC: {ex.Message}"); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot format the table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Table columns are now aligned in commit
12f1b78.