From 9d8361a28bc5f702a6f30b535101fab09a7eaf57 Mon Sep 17 00:00:00 2001 From: Michael Stonis <120685+michaelstonis@users.noreply.github.com> Date: Tue, 1 Dec 2026 09:38:41 -0600 Subject: [PATCH] ci: publish to nuget.org with trusted publishing Replace the long-lived EIGHTBOT_NUGET_APIKEY secret with NuGet/login, which exchanges the workflow's OIDC token for a short-lived API key. The build job now declares id-token: write, plus packages: write and contents: read since an explicit permissions block drops the rest. --- .github/workflows/nuget.yml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index 1507caa..a820736 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -18,6 +18,13 @@ jobs: build: needs: test runs-on: macos-latest + # Setting any permission drops the rest to none, so list everything the + # job needs: id-token for NuGet trusted publishing (OIDC), packages for + # the GitHub Packages pushes, contents for checkout. + permissions: + contents: read + packages: write + id-token: write steps: - uses: actions/checkout@v3 @@ -33,10 +40,18 @@ jobs: run: dotnet build TychoDB.JsonSerializer/TychoDB.JsonSerializer.csproj - name: Create the package run: dotnet pack --configuration Release /p:AssemblyVersion=${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch }} /p:Version=${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch }} TychoDB.JsonSerializer/TychoDB.JsonSerializer.csproj + # Trades the workflow's OIDC token for a short-lived (1 hour) nuget.org + # API key. Requires a matching trusted publishing policy on nuget.org. + - name: NuGet login (trusted publishing) + id: nuget-login + uses: NuGet/login@v1 + with: + user: ${{ vars.NUGET_USER }} + - name: Publish the package to GPR run: dotnet nuget push TychoDB.JsonSerializer/bin/Release/*.nupkg --api-key "${{secrets.GITHUB_TOKEN}}" --source https://nuget.pkg.github.com/theeightbot/index.json - name: Publish the package to NuGet - run: dotnet nuget push TychoDB.JsonSerializer/bin/Release/*.nupkg --api-key "${{ secrets.EIGHTBOT_NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json + run: dotnet nuget push TychoDB.JsonSerializer/bin/Release/*.nupkg --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json - name: Build TychoDB.JsonSerializer.NewtonsoftJson run: dotnet build TychoDB.JsonSerializer.NewtonsoftJson/TychoDB.JsonSerializer.NewtonsoftJson.csproj @@ -45,7 +60,7 @@ jobs: - name: Publish the package to GPR run: dotnet nuget push TychoDB.JsonSerializer.NewtonsoftJson/bin/Release/*.nupkg --api-key "${{secrets.GITHUB_TOKEN}}" --source https://nuget.pkg.github.com/theeightbot/index.json - name: Publish the package to NuGet - run: dotnet nuget push TychoDB.JsonSerializer.NewtonsoftJson/bin/Release/*.nupkg --api-key "${{ secrets.EIGHTBOT_NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json + run: dotnet nuget push TychoDB.JsonSerializer.NewtonsoftJson/bin/Release/*.nupkg --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json - name: Build TychoDB.JsonSerializer.SystemTextJson run: dotnet build TychoDB.JsonSerializer.SystemTextJson/TychoDB.JsonSerializer.SystemTextJson.csproj @@ -54,7 +69,7 @@ jobs: - name: Publish the package to GPR run: dotnet nuget push TychoDB.JsonSerializer.SystemTextJson/bin/Release/*.nupkg --api-key "${{secrets.GITHUB_TOKEN}}" --source https://nuget.pkg.github.com/theeightbot/index.json - name: Publish the package to NuGet - run: dotnet nuget push TychoDB.JsonSerializer.SystemTextJson/bin/Release/*.nupkg --api-key "${{ secrets.EIGHTBOT_NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json + run: dotnet nuget push TychoDB.JsonSerializer.SystemTextJson/bin/Release/*.nupkg --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json - name: Build Tycho run: dotnet build TychoDB/TychoDB.csproj @@ -63,7 +78,7 @@ jobs: - name: Publish the package to GPR run: dotnet nuget push TychoDB/bin/Release/*.nupkg --api-key "${{secrets.GITHUB_TOKEN}}" --source https://nuget.pkg.github.com/theeightbot/index.json - name: Publish the package to NuGet - run: dotnet nuget push TychoDB/bin/Release/*.nupkg --api-key "${{ secrets.EIGHTBOT_NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json + run: dotnet nuget push TychoDB/bin/Release/*.nupkg --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json - name: Build Tycho (Encrypted) run: dotnet build --configuration Encrypted TychoDB/TychoDB.csproj @@ -72,5 +87,5 @@ jobs: - name: Publish the package to GPR (Encrypted) run: dotnet nuget push TychoDB/bin/Encrypted/*.nupkg --api-key "${{secrets.GITHUB_TOKEN}}" --source https://nuget.pkg.github.com/theeightbot/index.json - name: Publish the package to NuGet (Encrypted) - run: dotnet nuget push TychoDB/bin/Encrypted/*.nupkg --api-key "${{ secrets.EIGHTBOT_NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json + run: dotnet nuget push TychoDB/bin/Encrypted/*.nupkg --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json