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
35 changes: 33 additions & 2 deletions .github/workflows/NuGetPublish.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
name: Publish to NuGet.org

# Publishes RMC.Numerics to nuget.org with trusted publishing: the job exchanges a GitHub OIDC token
# for a one-hour nuget.org API key, so no long-lived key is stored in the repository.
#
# One-time setup on nuget.org (signed in as an owner of RMC.Numerics): Account > Trusted Publishing >
# add a policy with Package Owner USACE-RMC, Repository Owner USACE-RMC, Repository Numerics and
# Workflow File NuGetPublish.yml. The login user is the nuget.org profile USACE-RMC.
#
# A published GitHub Release vX.Y.Z runs this workflow on its tag. To publish an existing tag again
# (for example after a failed push), run it manually from main with release_tag set to that tag.

on:
release:
types: [published]
workflow_dispatch:
inputs:
release_tag:
description: 'Existing release tag to publish to nuget.org (for example, v2.3.0)'
required: true
type: string

permissions:
contents: read

jobs:
publish:
runs-on: windows-latest
timeout-minutes: 60
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.release_tag) || github.sha }}

- uses: actions/setup-dotnet@v4
with:
Expand All @@ -21,13 +44,21 @@ jobs:
- name: Extract version from tag
id: version
shell: bash
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
env:
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
run: echo "VERSION=${RELEASE_TAG#v}" >> "$GITHUB_OUTPUT"

- name: Build
run: dotnet build Numerics/Numerics.csproj -c Release -p:Version=${{ steps.version.outputs.VERSION }}

- name: Pack
run: dotnet pack Numerics/Numerics.csproj -c Release --no-build -p:Version=${{ steps.version.outputs.VERSION }}

- name: NuGet login (OIDC token for a short-lived API key)
id: login
uses: NuGet/login@v1
with:
user: USACE-RMC

- name: Push to NuGet.org
run: dotnet nuget push "Numerics/bin/Release/RMC.Numerics.${{ steps.version.outputs.VERSION }}.nupkg" --api-key ${{ secrets.NUGET_ORG_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
run: dotnet nuget push "Numerics/bin/Release/RMC.Numerics.${{ steps.version.outputs.VERSION }}.nupkg" --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
Loading