Skip to content

Commit 46c1fa7

Browse files
ci: migrate NuGet publish to trusted publishing (OIDC) (#440)
## Summary Migrates the NuGet publish step in `Deploy.yml` from a long-lived `NUGET_API_KEY` secret to OIDC-based trusted publishing via `NuGet/login@v1`. ## Changes - Added `permissions: id-token: write` to the `deploy` job (required for OIDC token issuance) - Added `NuGet/login@v1` step to exchange the OIDC token for a short-lived NuGet API key - Replaced `secrets.NUGET_API_KEY` with `steps.login.outputs.NUGET_API_KEY` in the push step ## nuget.org Setup (already done) A trusted publishing policy has been created on nuget.org for `IntelliTect.Analyzers`: - **Owner**: IntelliTect - **Repository**: CodingGuidelines - **Workflow**: `Deploy.yml` - **Environment**: `Production` ## Required Action Before Merging Add a `NUGET_USER` secret to the **Production** GitHub environment: - **Name**: `NUGET_USER` - **Value**: the nuget.org profile name (not email) of the `IntelliTect-Nuget` account ## After First Successful Publish Once a release triggers a successful publish via OIDC, the old `NUGET_API_KEY` secret can be removed from the repository secrets.
1 parent 445980c commit 46c1fa7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

.github/workflows/Deploy.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,26 @@ jobs:
5050
name: "Production"
5151
url: "https://www.nuget.org/packages/IntelliTect.Analyzers"
5252
name: Push NuGets
53+
permissions:
54+
id-token: write # Required for NuGet trusted publishing (OIDC)
55+
contents: read
56+
actions: read # Required for actions/download-artifact
5357

5458
steps:
5559
- name: Download artifact from build job
5660
uses: actions/download-artifact@v8
5761
with:
5862
name: NuGet
5963

64+
- name: NuGet login (OIDC)
65+
id: login
66+
uses: NuGet/login@v1
67+
with:
68+
user: ${{ secrets.NUGET_USER }} # nuget.org profile name (NOT email)
69+
6070
- name: Push NuGet
6171
run: |
6272
$tagVersion = "${{ github.ref }}".substring(11)
6373
echo "TAG_VERSION=$tagVersion" >> $env:GITHUB_OUTPUT
64-
dotnet nuget push IntelliTect.Analyzers.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
74+
dotnet nuget push IntelliTect.Analyzers.$tagVersion.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --skip-duplicate
6575
id: tag-version

0 commit comments

Comments
 (0)