# Publish new package versions of ModelContextProtocol # # Triggers # - Scheduled (07:00 UTC daily, main branch): produces a CI-suffixed package # and publishes it to the GitHub package registry. # # - Push to `release/**`: every commit to a release branch produces a CI-suffixed # package and publishes it to the GitHub package registry. # # - Manual `workflow_dispatch` (any branch): same outputs as a scheduled/push build; # accepts a `version_suffix_override` input. # # - GitHub Release published (any branch's tag): publishes the version from # `src/Directory.Build.props` to the GitHub package registry AND NuGet.org. # # Version # - Version prefix and suffix come from `src/Directory.Build.props`. # - For non-release triggers, the suffix is replaced with `ci.{run_number}` # (or `workflow_dispatch.inputs.version_suffix_override` when provided). # - The prefix and suffix in `Directory.Build.props` should be updated after each # release using the `bump-version` or `prepare-release` skills. name: Release Publishing on: schedule: - cron: '0 7 * * *' push: branches: - 'release/**' workflow_dispatch: inputs: version_suffix_override: description: Version suffix override type: string release: types: [published] jobs: build-all-configs: # Don't run scheduled/release triggers on forks; allow manual workflow_dispatch if: ${{ github.repository == 'modelcontextprotocol/csharp-sdk' || github.event_name == 'workflow_dispatch' }} strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] configuration: [Debug, Release] fail-fast: false runs-on: ${{ matrix.os }} permissions: contents: read steps: - name: Clone the repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up .NET uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 with: dotnet-version: | 10.0.x 9.0.x - name: Build run: dotnet build --configuration ${{ matrix.configuration }} - name: Pack run: dotnet pack --configuration ${{ matrix.configuration }} build-package: runs-on: windows-latest needs: build-all-configs permissions: contents: read env: version_suffix_args: ${{ github.event_name != 'release' && format('--version-suffix "{0}"', inputs.version_suffix_override || format('ci.{0}', github.run_number)) || '' }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup .NET uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 with: dotnet-version: | 10.0.x 9.0.x - name: Pack run: dotnet pack ${{ env.version_suffix_args }} --configuration Release --output "${{ github.workspace }}/artifacts/packages" - name: Upload artifact uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 if: ${{ !cancelled() }} with: name: build-artifacts path: ${{ github.workspace }}/artifacts publish-github: needs: build-package runs-on: ubuntu-latest permissions: packages: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup .NET uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 with: dotnet-version: 10.0.x - name: Download build artifacts uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - name: Authenticate to GitHub registry run: dotnet nuget add source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --name "github" --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text - name: Publish to GitHub NuGet package registry run: dotnet nuget push ${{github.workspace}}/packages/*.nupkg --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate publish-release: if: github.event_name == 'release' needs: build-package runs-on: ubuntu-latest permissions: contents: write packages: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Download build artifacts uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - name: Upload release asset run: gh release upload ${{ github.event.release.tag_name }} ${{ github.workspace }}/packages/*.*nupkg env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-nuget: # Only publish to NuGet.org from the modelcontextprotocol/csharp-sdk repository if: ${{ github.event_name == 'release' && github.repository == 'modelcontextprotocol/csharp-sdk' }} needs: build-package runs-on: ubuntu-latest permissions: { } steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Setup .NET uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 with: dotnet-version: 10.0.x - name: Download build artifacts uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - name: Publish to NuGet.org (Releases only) run: dotnet nuget push ${{github.workspace}}/packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_KEY_MODELCONTEXTPROTOCOL }} --skip-duplicate