Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .agents/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ Push a `v*` tag matching the `[workspace.package]` version in the root `Cargo.to

`release-npm.yml` ("Code Release npm") runs on the same tag and publishes `@ondeinference/onde-code` (a Node launcher in `packaging/npm/onde-code`) plus five platform packages, `@ondeinference/onde-code-{darwin-arm64,darwin-x64,linux-x64,linux-arm64,windows-x64}`. Auth is npm Trusted Publishing; npm authenticates with OIDC, not a token. Trusted Publishers are configured per package (all six point at `release-npm.yml`), so a new package needs one before its first CI publish; run `packaging/npm/scripts/setup-trusted-publishing.sh` to create and attach them. Verify with `npm view @ondeinference/onde-code version`.

`release-nuget.yml` ("Code Release NuGet") runs on the same tag and publishes `Onde.Code`, a .NET tool (`packaging/nuget/onde-code`) that bundles the five binaries and launches the one for the host. Auth is NuGet Trusted Publishing: nuget.org needs a policy for this repo and `release-nuget.yml`, and the `NUGET_USER` repo secret holds the profile name that owns the package. Its jobs check out `inputs.tag`, so a manual dispatch only works for tags that already contain `packaging/nuget/`. Verify with `https://api.nuget.org/v3-flatcontainer/onde.code/index.json`.

**winget:** `release-winget.yml` files the Package Request issue with `WINGET_ISSUE_TOKEN` (`public_repo`), then opens the manifest PR with `WINGET_PR_TOKEN`, a classic PAT with `public_repo`, `read:org`, `read:discussion`, and `workflow`. The first three cover forking and the `gh pr edit` GraphQL query. `workflow` is there because wingetcreate fast-forwards the token owner's fork before it branches, and GitHub refuses that sync once an upstream commit changes a file under `.github/workflows`. "The forked repository could not be synced with the upstream commits" can mean the PAT lacks `workflow`, or that the fork has simply drifted too far behind upstream; add the scope, or sync the fork by hand and rerun.
349 changes: 349 additions & 0 deletions .github/workflows/release-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
name: Code Release NuGet

# Publishes Onde.Code, a .NET tool that bundles the native onde-code binaries, on the same v*
# tag that release-github.yml and release-npm.yml build from.
#
# Auth is NuGet Trusted Publishing (OIDC), so no long-lived API key is stored. nuget.org needs a
# trusted publishing policy for this repository and workflow (release-nuget.yml), and the
# NUGET_USER repo secret must hold the nuget.org profile name that owns the package.

on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v1.0.4)"
required: true

concurrency:
# A re-pushed or re-dispatched tag fires this a second time. Queue the
# duplicate behind the original instead of cancelling it: cancelling a run
# mid-publish can leave a channel half-uploaded, whereas a queued duplicate
# just hits the "already published" check and exits clean.
group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }}
cancel-in-progress: false

permissions:
contents: read

env:
CARGO_TERM_COLOR: always
DOTNET_VERSION: 8.0.x
NUGET_PACKAGE_ID: Onde.Code

jobs:
# The launcher's version comes from the tag, but the binary reports CARGO_PKG_VERSION, so a
# mismatch would publish a package that lies about its version.
verify-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Tag matches Cargo.toml
shell: bash
env:
TAG: ${{ github.event.inputs.tag || github.ref_name }}
run: |
crate=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
if [ "$TAG" != "v$crate" ]; then
echo "::error::tag $TAG does not match Cargo.toml version $crate"
exit 1
fi

build-native-binaries:
name: Build native binary (${{ matrix.build.NAME }})
needs: verify-version
runs-on: ${{ matrix.build.OS }}
strategy:
fail-fast: false
matrix:
build:
- { NAME: darwin-arm64, OS: macos-latest, TARGET: aarch64-apple-darwin }
- { NAME: darwin-x64, OS: macos-15-intel, TARGET: x86_64-apple-darwin }
- { NAME: linux-x64, OS: ubuntu-latest, TARGET: x86_64-unknown-linux-gnu }
- { NAME: linux-arm64, OS: ubuntu-24.04-arm, TARGET: aarch64-unknown-linux-gnu }
- { NAME: windows-x64, OS: windows-latest, TARGET: x86_64-pc-windows-msvc }
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.build.TARGET }}

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: nuget-${{ matrix.build.TARGET }}

# --bin keeps the test-only fake-mcp-server out of the package.
- name: Build binary
shell: bash
run: cargo build --locked --release -p onde-code --bin onde-code --target ${{ matrix.build.TARGET }}

# The exe must not import the VC++ runtime DLLs (see .cargo/config.toml), or it fails to
# load on a machine without the redistributable.
- name: Check static CRT
if: matrix.build.NAME == 'windows-x64'
shell: pwsh
run: ./packaging/windows/check-static-crt.ps1 -Path target/${{ matrix.build.TARGET }}/release/onde-code.exe

- name: Prepare artifact
shell: bash
env:
BUILD_NAME: ${{ matrix.build.NAME }}
run: |
executable_name="onde-code"
if [[ "${BUILD_NAME}" == windows-* ]]; then
executable_name="onde-code.exe"
fi

mkdir -p "nuget-artifacts/native/${{ matrix.build.NAME }}"
cp "target/${{ matrix.build.TARGET }}/release/${executable_name}" \
"nuget-artifacts/native/${{ matrix.build.NAME }}/${executable_name}"

- name: Upload native artifact
uses: actions/upload-artifact@v4
with:
name: nuget-native-${{ matrix.build.NAME }}
path: nuget-artifacts/native

pack-nuget:
name: Pack NuGet .NET tool
runs-on: ubuntu-latest
needs: build-native-binaries
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}

- name: Set the release version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_version="${GITHUB_REF_NAME#v}"
else
release_version="${{ github.event.inputs.tag }}"
release_version="${release_version#v}"
fi
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"

- name: Download native artifacts
uses: actions/download-artifact@v4
with:
pattern: nuget-native-*
path: packaging/nuget/onde-code/native
merge-multiple: true

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Pack .NET tool
shell: bash
run: |
dotnet pack packaging/nuget/onde-code/OndeCode.csproj \
--configuration Release \
--output packaging/nuget/dist \
-p:PackageVersion="${RELEASE_VERSION}"

# All five binaries ship in one package, so this sits closer to nuget.org's
# 250 MB ceiling than the single-platform npm and PyPI artifacts do. Fail
# here with a clear message rather than at `dotnet nuget push`, where the
# error is just "the package file exceeds the size limit".
- name: Check package size against the NuGet limit
shell: bash
run: |
package="$(find packaging/nuget/dist -name '*.nupkg' | head -n 1)"
size_bytes="$(wc -c < "${package}")"
limit_bytes=$((250 * 1024 * 1024))

echo "Package: ${package}"
echo "Size: $((size_bytes / 1024 / 1024)) MiB"

if [ "${size_bytes}" -gt "${limit_bytes}" ]; then
echo "::error::${package} is over nuget.org's 250 MB package limit. Split the tool into RID-specific packages (.NET 10 DotnetToolRidPackage) instead of bundling every target." >&2
exit 1
fi

- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: packaging/nuget/dist/*.nupkg

smoke-test:
name: Smoke test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: pack-nuget
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}

- name: Set the release version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_version="${GITHUB_REF_NAME#v}"
else
release_version="${{ github.event.inputs.tag }}"
release_version="${release_version#v}"
fi
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"

- name: Download package artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: packaging/nuget/dist

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install tool from local package
shell: pwsh
run: |
$packageSource = (Resolve-Path "packaging/nuget/dist").Path
@"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="local" value="$packageSource" />
</packageSources>
</configuration>
"@ | Set-Content -Path "packaging/nuget/NuGet.Config"

dotnet tool install `
--tool-path ".tool" `
--configfile "packaging/nuget/NuGet.Config" `
--version "$env:RELEASE_VERSION" `
"$env:NUGET_PACKAGE_ID"

- name: Verify bundled native binary
shell: pwsh
run: |
$runtimeIdentifier = if ($IsWindows) {
if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "windows-arm64" } else { "windows-x64" }
} elseif ($IsMacOS) {
if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "darwin-arm64" } else { "darwin-x64" }
} else {
if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) { "linux-arm64" } else { "linux-x64" }
}

$binaryName = if ($IsWindows) { "onde-code.exe" } else { "onde-code" }
$nativeBinary = Get-ChildItem ".tool/.store" -Recurse -File | Where-Object {
$_.FullName -like "*native*${runtimeIdentifier}*${binaryName}"
} | Select-Object -First 1

if (-not $nativeBinary) {
Write-Error "The onde-code native binary for ${runtimeIdentifier} was not bundled in the installed .NET tool package."
}

Write-Host "Found bundled native binary at $($nativeBinary.FullName)"

publish-nuget:
name: Publish to NuGet
runs-on: ubuntu-latest
needs: smoke-test
# Trusted Publishing exchanges a GitHub OIDC token for a short-lived NuGet
# API key, so no long-lived NUGET_API_KEY secret is stored. Requires a
# trusted publishing policy on nuget.org for this repository and workflow
# (release-nuget.yml); without one the login step fails.
permissions:
contents: read
id-token: write
steps:
- name: Set the release version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_version="${GITHUB_REF_NAME#v}"
else
release_version="${{ github.event.inputs.tag }}"
release_version="${release_version#v}"
fi
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"

- name: Download package artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
path: packaging/nuget/dist

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Check whether release already exists on NuGet
id: nuget-check
shell: bash
run: |
package_index_url="https://api.nuget.org/v3-flatcontainer/onde.code/index.json"

# Keep the fetch and the version match separate. Piping curl into
# grep hides a failed fetch behind an empty match, so an outage or a
# blocked request would read as "not published yet" and send the
# publish below into a version that is already there. A 404 here
# means the package itself is not on NuGet, which is the first
# release and a real "not published".
index=$(mktemp)
STATUS=$(curl -sS -o "${index}" -w '%{http_code}' \
--retry 3 --retry-delay 2 --retry-all-errors "${package_index_url}")

case "$STATUS" in
200)
if grep -F "\"${RELEASE_VERSION}\"" "${index}" >/dev/null; then
echo "${NUGET_PACKAGE_ID} ${RELEASE_VERSION} already exists on NuGet, skipping publish"
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
;;
404)
echo "${NUGET_PACKAGE_ID} is not on NuGet yet, publishing its first version"
echo "exists=false" >> "$GITHUB_OUTPUT"
;;
*)
echo "Unexpected ${STATUS} from NuGet while checking whether ${NUGET_PACKAGE_ID} ${RELEASE_VERSION} is published" >&2
exit 1
;;
esac

# Exchange the workflow's OIDC token for a short-lived NuGet API key. The
# key is written to the environment for the subsequent `dotnet nuget push`
# via the NUGET_API_KEY variable this action sets.
- name: NuGet trusted-publishing login
if: steps.nuget-check.outputs.exists != 'true'
uses: NuGet/login@v1
id: nuget-login
with:
user: ${{ secrets.NUGET_USER }}

- name: Publish package
if: steps.nuget-check.outputs.exists != 'true'
shell: bash
run: |
dotnet nuget push packaging/nuget/dist/*.nupkg \
--api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@

# Node (npm launcher)
node_modules/

# NuGet (.NET tool)
packaging/nuget/**/bin/
packaging/nuget/**/obj/
packaging/nuget/**/native/
packaging/nuget/dist/
packaging/nuget/NuGet.Config
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<p align="center">
<a href="https://ondeinference.com"><img src="https://img.shields.io/badge/ondeinference.com-235843?style=flat-square&labelColor=17211D" alt="Website"></a>
<a href="https://www.npmjs.com/package/@ondeinference/onde-code"><img src="https://img.shields.io/npm/v/@ondeinference/onde-code?style=flat-square&labelColor=17211D&color=235843" alt="npm"></a>
<a href="https://www.nuget.org/packages/Onde.Code"><img src="https://img.shields.io/nuget/v/Onde.Code?style=flat-square&labelColor=17211D&color=235843" alt="NuGet"></a>
<a href="https://crates.io/crates/onde-code"><img src="https://img.shields.io/crates/v/onde-code?style=flat-square&labelColor=17211D&color=235843" alt="Crates.io"></a>
<a href="https://github.com/ondeinference/onde-code/releases"><img src="https://img.shields.io/github/v/release/ondeinference/onde-code?style=flat-square&labelColor=17211D&color=235843" alt="Release"></a>
<a href="https://github.com/ondeinference/onde-code/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/ondeinference/onde-code/ci.yml?style=flat-square&labelColor=17211D&color=235843&label=CI" alt="CI"></a>
Expand All @@ -35,6 +36,7 @@ It is one static binary written in Rust, and it also accepts any OpenAI API comp

```sh
npm install -g @ondeinference/onde-code # pulls in the binary for your platform
dotnet tool install -g Onde.Code # or as a .NET tool
npx @ondeinference/onde-code --acp # or run it without installing, from an editor
```

Expand Down
Loading
Loading