| 1 | name: NuGet Release |
| 2 | |
| 3 | # Dispatched by release-crates.yml once the crate publish succeeds. |
| 4 | on: |
| 5 | workflow_dispatch: |
| 6 | inputs: |
| 7 | tag: |
| 8 | description: "Release tag (e.g. v0.4.0)" |
| 9 | required: true |
| 10 | |
| 11 | permissions: |
| 12 | contents: read |
| 13 | |
| 14 | env: |
| 15 | CARGO_TERM_COLOR: always |
| 16 | DOTNET_VERSION: 8.0.x |
| 17 | NUGET_PACKAGE_ID: Onde.Cli |
| 18 | ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }} |
| 19 | ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }} |
| 20 | GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }} |
| 21 | GRESIQ_API_SECRET: ${{ secrets.GRESIQ_API_SECRET }} |
| 22 | HF_TOKEN: ${{ secrets.HF_TOKEN }} |
| 23 | |
| 24 | jobs: |
| 25 | build-native-binaries: |
| 26 | name: Build native binary (${{ matrix.build.NAME }}) |
| 27 | runs-on: ${{ matrix.build.OS }} |
| 28 | strategy: |
| 29 | fail-fast: false |
| 30 | matrix: |
| 31 | build: |
| 32 | - { |
| 33 | NAME: linux-x64, |
| 34 | OS: ubuntu-latest, |
| 35 | TARGET: x86_64-unknown-linux-gnu, |
| 36 | } |
| 37 | - { |
| 38 | NAME: linux-arm64, |
| 39 | OS: ubuntu-24.04-arm, |
| 40 | TARGET: aarch64-unknown-linux-gnu, |
| 41 | } |
| 42 | - { |
| 43 | NAME: windows-x64, |
| 44 | OS: windows-2022, |
| 45 | TARGET: x86_64-pc-windows-msvc, |
| 46 | } |
| 47 | - { |
| 48 | NAME: windows-arm64, |
| 49 | OS: windows-2022, |
| 50 | TARGET: aarch64-pc-windows-msvc, |
| 51 | } |
| 52 | - { |
| 53 | NAME: darwin-x64, |
| 54 | OS: macos-26-intel, |
| 55 | TARGET: x86_64-apple-darwin, |
| 56 | } |
| 57 | - { NAME: darwin-arm64, OS: macos-26, TARGET: aarch64-apple-darwin } |
| 58 | steps: |
| 59 | - name: Checkout |
| 60 | uses: actions/checkout@v6 |
| 61 | with: |
| 62 | ref: ${{ github.event.inputs.tag || github.ref }} |
| 63 | |
| 64 | - name: Set the release version |
| 65 | shell: bash |
| 66 | run: | |
| 67 | if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 68 | release_version="${GITHUB_REF_NAME#v}" |
| 69 | else |
| 70 | release_version="${{ github.event.inputs.tag }}" |
| 71 | release_version="${release_version#v}" |
| 72 | fi |
| 73 | |
| 74 | echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV" |
| 75 | |
| 76 | - name: Read Rust toolchain |
| 77 | shell: bash |
| 78 | run: | |
| 79 | rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)" |
| 80 | if [ -z "$rust_toolchain" ]; then |
| 81 | echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2 |
| 82 | exit 1 |
| 83 | fi |
| 84 | |
| 85 | echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV" |
| 86 | |
| 87 | - name: Install Rust toolchain |
| 88 | uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 |
| 89 | with: |
| 90 | toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 91 | targets: ${{ matrix.build.TARGET }} |
| 92 | |
| 93 | - name: Setup Rust cache |
| 94 | uses: Swatinem/rust-cache@v2 |
| 95 | with: |
| 96 | key: nuget-${{ matrix.build.TARGET }} |
| 97 | |
| 98 | - name: Build binary |
| 99 | shell: bash |
| 100 | run: cargo build --locked --release --target ${{ matrix.build.TARGET }} |
| 101 | |
| 102 | - name: Prepare artifact |
| 103 | shell: bash |
| 104 | run: | |
| 105 | executable_name="onde" |
| 106 | if [[ "${{ matrix.build.OS }}" == "windows-2022" ]]; then |
| 107 | executable_name="onde.exe" |
| 108 | fi |
| 109 | |
| 110 | mkdir -p "nuget-artifacts/native/${{ matrix.build.NAME }}" |
| 111 | cp "target/${{ matrix.build.TARGET }}/release/${executable_name}" "nuget-artifacts/native/${{ matrix.build.NAME }}/${executable_name}" |
| 112 | |
| 113 | - name: Upload native artifact |
| 114 | uses: actions/upload-artifact@v4 |
| 115 | with: |
| 116 | name: nuget-native-${{ matrix.build.NAME }} |
| 117 | path: nuget-artifacts/native |
| 118 | |
| 119 | pack-nuget: |
| 120 | name: Pack NuGet .NET tool |
| 121 | runs-on: ubuntu-latest |
| 122 | needs: build-native-binaries |
| 123 | steps: |
| 124 | - name: Checkout |
| 125 | uses: actions/checkout@v6 |
| 126 | with: |
| 127 | ref: ${{ github.event.inputs.tag || github.ref }} |
| 128 | |
| 129 | - name: Set the release version |
| 130 | shell: bash |
| 131 | run: | |
| 132 | if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 133 | release_version="${GITHUB_REF_NAME#v}" |
| 134 | else |
| 135 | release_version="${{ github.event.inputs.tag }}" |
| 136 | release_version="${release_version#v}" |
| 137 | fi |
| 138 | |
| 139 | echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV" |
| 140 | |
| 141 | - name: Download native artifacts |
| 142 | uses: actions/download-artifact@v4 |
| 143 | with: |
| 144 | pattern: nuget-native-* |
| 145 | path: nuget/onde-cli/native |
| 146 | merge-multiple: true |
| 147 | |
| 148 | - name: Setup .NET SDK |
| 149 | uses: actions/setup-dotnet@v4 |
| 150 | with: |
| 151 | dotnet-version: ${{ env.DOTNET_VERSION }} |
| 152 | |
| 153 | - name: Pack .NET tool |
| 154 | shell: bash |
| 155 | run: | |
| 156 | dotnet pack nuget/onde-cli/Onde.Cli.csproj \ |
| 157 | --configuration Release \ |
| 158 | --output nuget/dist \ |
| 159 | -p:PackageVersion=${RELEASE_VERSION} |
| 160 | |
| 161 | - name: Upload package artifact |
| 162 | uses: actions/upload-artifact@v4 |
| 163 | with: |
| 164 | name: nuget-package |
| 165 | path: nuget/dist/*.nupkg |
| 166 | |
| 167 | smoke-test: |
| 168 | name: Smoke test (${{ matrix.os }}) |
| 169 | runs-on: ${{ matrix.os }} |
| 170 | needs: pack-nuget |
| 171 | strategy: |
| 172 | fail-fast: false |
| 173 | matrix: |
| 174 | os: |
| 175 | - ubuntu-latest |
| 176 | - windows-2022 |
| 177 | - macos-26 |
| 178 | steps: |
| 179 | - name: Checkout |
| 180 | uses: actions/checkout@v6 |
| 181 | with: |
| 182 | ref: ${{ github.event.inputs.tag || github.ref }} |
| 183 | |
| 184 | - name: Set the release version |
| 185 | shell: bash |
| 186 | run: | |
| 187 | if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 188 | release_version="${GITHUB_REF_NAME#v}" |
| 189 | else |
| 190 | release_version="${{ github.event.inputs.tag }}" |
| 191 | release_version="${release_version#v}" |
| 192 | fi |
| 193 | |
| 194 | echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV" |
| 195 | |
| 196 | - name: Download package artifact |
| 197 | uses: actions/download-artifact@v4 |
| 198 | with: |
| 199 | name: nuget-package |
| 200 | path: nuget/dist |
| 201 | |
| 202 | - name: Setup .NET SDK |
| 203 | uses: actions/setup-dotnet@v4 |
| 204 | with: |
| 205 | dotnet-version: ${{ env.DOTNET_VERSION }} |
| 206 | |
| 207 | - name: Install tool from local package |
| 208 | shell: pwsh |
| 209 | run: | |
| 210 | $packageSource = (Resolve-Path "nuget/dist").Path |
| 211 | @" |
| 212 | <?xml version="1.0" encoding="utf-8"?> |
| 213 | <configuration> |
| 214 | <packageSources> |
| 215 | <clear /> |
| 216 | <add key="local" value="$packageSource" /> |
| 217 | </packageSources> |
| 218 | </configuration> |
| 219 | "@ | Set-Content -Path "nuget/NuGet.Config" |
| 220 | |
| 221 | dotnet tool install ` |
| 222 | --tool-path ".tool" ` |
| 223 | --configfile "nuget/NuGet.Config" ` |
| 224 | --version "$env:RELEASE_VERSION" ` |
| 225 | "$env:NUGET_PACKAGE_ID" |
| 226 | |
| 227 | - name: Verify bundled native binary |
| 228 | shell: pwsh |
| 229 | run: | |
| 230 | $runtimeIdentifier = if ($IsWindows) { |
| 231 | if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "windows-arm64" } else { "windows-x64" } |
| 232 | } elseif ($IsMacOS) { |
| 233 | if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "darwin-arm64" } else { "darwin-x64" } |
| 234 | } else { |
| 235 | if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "linux-arm64" } else { "linux-x64" } |
| 236 | } |
| 237 | |
| 238 | $binaryName = if ($IsWindows) { "onde.exe" } else { "onde" } |
| 239 | $nativeBinary = Get-ChildItem ".tool/.store" -Recurse -File | Where-Object { |
| 240 | $_.FullName -like "*native*${runtimeIdentifier}*${binaryName}" |
| 241 | } | Select-Object -First 1 |
| 242 | |
| 243 | if (-not $nativeBinary) { |
| 244 | Write-Error "Onde native binary for ${runtimeIdentifier} was not bundled in the installed .NET tool package." |
| 245 | } |
| 246 | |
| 247 | Write-Host "Found bundled native binary at $($nativeBinary.FullName)" |
| 248 | |
| 249 | publish-nuget: |
| 250 | name: Publish to NuGet |
| 251 | runs-on: ubuntu-latest |
| 252 | needs: smoke-test |
| 253 | steps: |
| 254 | - name: Checkout |
| 255 | uses: actions/checkout@v6 |
| 256 | with: |
| 257 | ref: ${{ github.event.inputs.tag || github.ref }} |
| 258 | |
| 259 | - name: Set the release version |
| 260 | shell: bash |
| 261 | run: | |
| 262 | if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 263 | release_version="${GITHUB_REF_NAME#v}" |
| 264 | else |
| 265 | release_version="${{ github.event.inputs.tag }}" |
| 266 | release_version="${release_version#v}" |
| 267 | fi |
| 268 | |
| 269 | echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV" |
| 270 | |
| 271 | - name: Download package artifact |
| 272 | uses: actions/download-artifact@v4 |
| 273 | with: |
| 274 | name: nuget-package |
| 275 | path: nuget/dist |
| 276 | |
| 277 | - name: Setup .NET SDK |
| 278 | uses: actions/setup-dotnet@v4 |
| 279 | with: |
| 280 | dotnet-version: ${{ env.DOTNET_VERSION }} |
| 281 | |
| 282 | - name: Check whether release already exists on NuGet |
| 283 | id: nuget-check |
| 284 | shell: bash |
| 285 | run: | |
| 286 | package_index_url="https://api.nuget.org/v3-flatcontainer/onde.cli/index.json" |
| 287 | if curl -fsS "${package_index_url}" | grep -F "\"${RELEASE_VERSION}\"" >/dev/null; then |
| 288 | echo "${NUGET_PACKAGE_ID} ${RELEASE_VERSION} already exists on NuGet, skipping publish" |
| 289 | echo "exists=true" >> "$GITHUB_OUTPUT" |
| 290 | else |
| 291 | echo "exists=false" >> "$GITHUB_OUTPUT" |
| 292 | fi |
| 293 | |
| 294 | - name: Publish package |
| 295 | if: steps.nuget-check.outputs.exists != 'true' |
| 296 | env: |
| 297 | NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 298 | shell: bash |
| 299 | run: | |
| 300 | dotnet nuget push nuget/dist/*.nupkg \ |
| 301 | --api-key "${NUGET_API_KEY}" \ |
| 302 | --source https://api.nuget.org/v3/index.json \ |
| 303 | --skip-duplicate |
| 304 | |
| 305 | dispatch-mcp-registry: |
| 306 | name: Trigger MCP Registry release |
| 307 | needs: publish-nuget |
| 308 | runs-on: ubuntu-latest |
| 309 | permissions: |
| 310 | actions: write |
| 311 | steps: |
| 312 | # The MCP Registry listing needs both npm and NuGet live at this version, |
| 313 | # and NuGet is the slower of the two, so it hangs off this workflow rather |
| 314 | # than the fan-out in release-crates.yml. |
| 315 | - name: Trigger MCP Registry release workflow |
| 316 | uses: actions/github-script@v7 |
| 317 | with: |
| 318 | script: | |
| 319 | const tag = '${{ github.event.inputs.tag }}' || context.ref.replace('refs/tags/', '') |
| 320 | await github.rest.actions.createWorkflowDispatch({ |
| 321 | owner: context.repo.owner, |
| 322 | repo: context.repo.repo, |
| 323 | workflow_id: 'release-mcp-registry.yml', |
| 324 | ref: tag, |
| 325 | inputs: { tag } |
| 326 | }) |