Skip to content

Commit 94867f2

Browse files
Port NuGet publish step to use trusted publishing (OIDC) instead of API key secret
Agent-Logs-Url: https://github.com/crispthinking/FastText.NetWrapper/sessions/e33d7de8-1098-4fb4-8342-d5bec1e045de Co-authored-by: corpo-iwillspeak <265613520+corpo-iwillspeak@users.noreply.github.com>
1 parent b51c881 commit 94867f2

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

.github/workflows/publish.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ permissions:
1212
packages: write
1313
checks: write
1414
pull-requests: write
15+
id-token: write # Required for NuGet trusted publishing (OIDC)
1516

1617
jobs:
1718
build:
@@ -33,4 +34,14 @@ jobs:
3334
- name: Publish NuGet package
3435
if: github.event_name == 'release'
3536
run: |
36-
dotnet nuget push bin/artifacts/**/*.nupkg --api-key "${{ secrets.NUGET_APIKEY }}" --source "https://api.nuget.org/v3/index.json" --skip-duplicate
37+
OIDC_TOKEN=$(curl --silent --show-error --fail-with-body \
38+
--url "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange" \
39+
--header "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
40+
| jq --raw-output '.value')
41+
API_KEY=$(curl --silent --show-error --fail-with-body \
42+
--request POST \
43+
--url "https://api.nuget.org/v1/authentication/authenticate" \
44+
--header "Content-Type: application/json" \
45+
--data "{\"oidcToken\": \"$OIDC_TOKEN\"}" \
46+
| jq --raw-output '.apiKey')
47+
dotnet nuget push bin/artifacts/**/*.nupkg --api-key "$API_KEY" --source "https://api.nuget.org/v3/index.json" --skip-duplicate

0 commit comments

Comments
 (0)