Skip to content

Commit 9c3d42b

Browse files
authored
Publish to NuGet via Trusted Publishing (OIDC)
Replace the long-lived NUGET_API_KEY secret with a short-lived key obtained via NuGet/login@v1. Adds job permissions (id-token: write for OIDC, checks: write for the test reporter).
1 parent 5e67c83 commit 9c3d42b

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎.github/workflows/dotnet-core.yml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ jobs:
99

1010
runs-on: ubuntu-latest
1111

12+
permissions:
13+
contents: read # checkout
14+
actions: read # test reporter
15+
checks: write # test reporter publishes a check run
16+
id-token: write # OIDC token for NuGet Trusted Publishing
17+
1218
steps:
1319
- uses: actions/checkout@v4
1420
- name: Setup .NET SDK
@@ -31,8 +37,13 @@ jobs:
3137
reporter: dotnet-trx
3238
- name: Pack library project
3339
run: dotnet pack src/Websocket.Client/Websocket.Client.csproj --no-build --configuration Release --include-symbols -p:SymbolPackageFormat=snupkg -o .
40+
- name: NuGet login (OIDC -> temporary API key)
41+
uses: NuGet/login@v1
42+
id: nuget-login
43+
with:
44+
user: marfusios
3445
- name: Publish library (NuGet)
35-
run: dotnet nuget push *.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source "https://api.nuget.org/v3/index.json" --skip-duplicate
46+
run: dotnet nuget push *.nupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json" --skip-duplicate
3647
#- name: Publish library (Github)
3748
# run: dotnet nuget push *.nupkg --api-key ${{secrets.PUBLISH_TO_GITHUB_TOKEN}} --source "https://nuget.pkg.github.com/marfusios/index.json" --skip-duplicate
3849

0 commit comments

Comments
 (0)