Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ jobs:
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: [ validate_nuget, run_test ]

# Job-level, so it must restate contents: read — a job-level block REPLACES the
# workflow-level one rather than adding to it.
permissions:
contents: read
id-token: write # request the GitHub OIDC token for NuGet Trusted Publishing

steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v8
Expand All @@ -140,8 +147,21 @@ jobs:
# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
# Trusted Publishing: exchanges the OIDC token (needs `id-token: write` above) for a NuGet
# key valid ~1 hour, so no long-lived secret is stored. Keep it adjacent to the push so the
# key cannot expire in between. Requires a Trusted Publishing policy on nuget.org naming
# this repository and `main.yml`, plus the NUGET_USER secret (the nuget.org profile name).
# Deliberately UNGUARDED: this job only runs on a published Release, so publishing is
# expected. A missing policy must fail loudly rather than skip and leave the release
# unpublished behind a green check.
- name: NuGet login (OIDC -> short-lived key)
id: nuget-login
uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0
with:
user: ${{ secrets.NUGET_USER }}

- name: Publish NuGet package
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push $file --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
Loading