Skip to content

Commit 49e1008

Browse files
sunnamed434claude
andcommitted
CI: publish to nuget.org via Trusted Publishing (OIDC)
Replace the long-lived NUGET_DEPLOY_KEY with NuGet Trusted Publishing: the project-build action now runs NuGet/login@v1 to exchange the GitHub OIDC token for a short-lived nuget.org key right before the release push. Each publishing workflow gets `id-token: write` and passes `nuget_user: ${{ secrets.NUGET_USER }}`. Requires: a NUGET_USER secret (nuget.org profile name) and one Trusted Publishing policy per package on nuget.org (Workflow File = the matching BitMono.<Pkg>.yaml). The GitHub Packages nightly push still uses GITHUB_TOKEN. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6ebd4d3 commit 49e1008

11 files changed

Lines changed: 34 additions & 15 deletions

.github/actions/project-build/action.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ inputs:
1919
description: 'Push to NuGet on release?'
2020
required: false
2121
default: false
22-
nuget_key:
23-
description: 'NuGet deploy key'
22+
nuget_user:
23+
description: 'nuget.org username (profile name) for Trusted Publishing via OIDC'
2424
required: false
2525
github_token:
2626
description: 'GitHub token'
@@ -103,9 +103,18 @@ runs:
103103
fi
104104
shell: bash
105105

106+
# Trusted Publishing (OIDC): exchange the GitHub token for a short-lived nuget.org API key,
107+
# right before the push (the key expires in ~1h). Only on non-prerelease tags.
108+
# Requires `id-token: write` on the calling workflow and a Trusted Publishing policy on nuget.org.
109+
- name: NuGet login (OIDC -> temp key)
110+
id: nuget-login
111+
if: ${{ inputs.nuget_push == 'true' && github.event_name == 'create' && github.event.ref_type == 'tag' && steps.check-prerelease.outputs.is_prerelease == 'false' }}
112+
uses: NuGet/login@v1
113+
with:
114+
user: ${{ inputs.nuget_user }}
115+
106116
# Push to NuGet on each tag, but only if not a pre-release version (Release)
107117
- name: Push to NuGet (Release)
108-
run: if ${{ inputs.nuget_push == 'true' && github.event_name == 'create' && github.event.ref_type == 'tag' && steps.check-prerelease.outputs.is_prerelease == 'false' }}; then
109-
dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ inputs.nuget_key }} --skip-duplicate --source https://api.nuget.org/v3/index.json;
110-
fi
118+
if: ${{ inputs.nuget_push == 'true' && github.event_name == 'create' && github.event.ref_type == 'tag' && steps.check-prerelease.outputs.is_prerelease == 'false' }}
119+
run: dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --skip-duplicate --source https://api.nuget.org/v3/index.json
111120
shell: bash

.github/workflows/BitMono.API.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,5 +41,5 @@ jobs:
4041
with:
4142
project_path: src/BitMono.API
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true

.github/workflows/BitMono.Core.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,6 +41,6 @@ jobs:
4041
with:
4142
project_path: src/BitMono.Core
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true
4546

.github/workflows/BitMono.GlobalTool.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,7 +41,7 @@ jobs:
4041
with:
4142
project_path: src/BitMono.GlobalTool
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true
4546
use_runtime: false # Because this is a dotnet tool.
4647

.github/workflows/BitMono.Host.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,5 +41,5 @@ jobs:
4041
with:
4142
project_path: src/BitMono.Host
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true

.github/workflows/BitMono.Integration.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
permissions:
2727
contents: read # checkout
2828
packages: write # dotnet nuget push -> nuget.pkg.github.com/sunnamed434
29+
id-token: write # OIDC for NuGet Trusted Publishing
2930

3031
steps:
3132
- uses: actions/checkout@v6
@@ -56,6 +57,6 @@ jobs:
5657
project_path: src/BitMono.Integration
5758
target_framework: net8.0
5859
github_token: ${{ secrets.GITHUB_TOKEN }}
59-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
60+
nuget_user: ${{ secrets.NUGET_USER }}
6061
nuget_push: true
6162
use_runtime: false # build-tools / dev package, no RID

.github/workflows/BitMono.Obfuscation.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,5 +41,5 @@ jobs:
4041
with:
4142
project_path: src/BitMono.Obfuscation
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true

.github/workflows/BitMono.Protections.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,5 +41,5 @@ jobs:
4041
with:
4142
project_path: src/BitMono.Protections
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true

.github/workflows/BitMono.Runtime.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,5 +41,5 @@ jobs:
4041
with:
4142
project_path: src/BitMono.Runtime
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true

.github/workflows/BitMono.Shared.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
packages: write
27+
id-token: write # OIDC for NuGet Trusted Publishing
2728

2829
steps:
2930
- uses: actions/checkout@v6
@@ -40,5 +41,5 @@ jobs:
4041
with:
4142
project_path: src/BitMono.Shared
4243
github_token: ${{ secrets.GITHUB_TOKEN }}
43-
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
44+
nuget_user: ${{ secrets.NUGET_USER }}
4445
nuget_push: true

0 commit comments

Comments
 (0)