Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions .github/workflows/github-actions-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ jobs:
with:
toolchain: nightly

# Unset BAML_VERSION so the renderer's own baml.toml picks its toolchain,
# Unset BAML_TOOLCHAIN so the renderer's own baml.toml picks its toolchain,
# as it does when the action runs it.
- name: Test comment rendering
run: env -u BAML_VERSION baml --agent-skill-check off --color never --no-progress --project packaging/github-actions/baml-action/codequality test
run: env -u BAML_TOOLCHAIN baml --agent-skill-check off --color never --no-progress --project packaging/github-actions/baml-action/codequality test

- name: Lint Bash
working-directory: packaging/github-actions/baml-action
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/release-baml-language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,14 @@ jobs:
export BAML_HOME="$RUNNER_TEMP/developer-docs-baml"
scripts/install.sh --version "$VERSION" --no-modify-path
baml_binary="$BAML_HOME/bin/baml"
actual_version="$("$baml_binary" --version | sed -n 's/^baml toolchain \([^ ]*\).*/\1/p')"
# Wrapper 0.3+ prints `baml wrapper X` and passes --version through to
# the toolchain (`baml-cli X`); wrapper 0.2 printed `baml toolchain X`.
version_output="$("$baml_binary" --version)"
printf '%s\n' "$version_output"
actual_version="$(sed -n \
-e 's/^baml-cli \([^ ]*\).*/\1/p' \
-e 's/^baml toolchain \(baml-cli \)\{0,1\}\([^ ]*\).*/\2/p' \
<<<"$version_output")"
if [[ "$actual_version" != "$VERSION" ]]; then
echo "::error::installed BAML toolchain is $actual_version, expected $VERSION"
exit 1
Expand Down
6 changes: 3 additions & 3 deletions packaging/github-actions/baml-action/scripts/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ measure_base() {
echo "$work/base.json"
# Measure the base with the head's toolchain, not whatever the base's
# baml.toml selects, so a toolchain bump doesn't read as a code change.
elif BAML_VERSION="$BAML_RESOLVED_VERSION" measure "$base_dir/$prefix" "$work/base.json"; then
elif BAML_TOOLCHAIN="$BAML_RESOLVED_VERSION" measure "$base_dir/$prefix" "$work/base.json"; then
echo "$work/base.json"
fi
git -C "$root" worktree remove --force "$base_dir" >&2 || true
Expand Down Expand Up @@ -125,8 +125,8 @@ run_codequality() {

local status
# The renderer is a BAML project pinned to its own toolchain, so drop
# setup-baml's BAML_VERSION and let its baml.toml choose.
status="$(env -u BAML_VERSION BAML_TELEMETRY=off \
# setup-baml's BAML_TOOLCHAIN and let its baml.toml choose.
status="$(env -u BAML_TOOLCHAIN BAML_TELEMETRY=off \
baml "${flags[@]}" --project "$GITHUB_ACTION_PATH/codequality" run main -- \
${base_args[@]+"${base_args[@]}"} \
--head "$work/head.json" \
Expand Down
2 changes: 1 addition & 1 deletion packaging/github-actions/setup-baml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ steps:
toolchain: 0.16.0
```

An explicit `toolchain` input overrides a conflicting project selector for subsequent workflow steps through the wrapper's documented `BAML_VERSION` mechanism.
An explicit `toolchain` input overrides a conflicting project selector for subsequent workflow steps through the wrapper's documented `BAML_TOOLCHAIN` mechanism.

When `toolchain` is omitted, the official BAML wrapper resolves the project selector from the nearest `baml.toml`:

Expand Down
6 changes: 5 additions & 1 deletion packaging/github-actions/setup-baml/lib/wrapper-output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ export function resolveSelector(output) {
return validateSelector(selector);
}

// Wrapper 0.3+ prints `baml wrapper X` and then passes --version through to the
// selected toolchain (`baml-cli X`); wrapper 0.2 printed `baml toolchain X (...)`.
export function resolveVersion(output) {
const match = output.match(/^baml toolchain ([^\s(]+)(?:\s|$)/m);
const match =
output.match(/^baml-cli ([^\s(]+)(?:\s|$)/m) ??
output.match(/^baml toolchain (?:baml-cli )?([^\s(]+)(?:\s|$)/m);
if (!match || match[1] === "not") {
throw new Error("the BAML wrapper did not report a resolved concrete toolchain version");
}
Expand Down
13 changes: 8 additions & 5 deletions packaging/github-actions/setup-baml/scripts/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ $ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

$InstallerUrl = "https://pkg.boundaryml.com/install.ps1"
# Later steps get the official manifest source explicitly: wrapper 0.3 rejects an
# empty BAML_MANIFEST_BASE_URL instead of treating it as unset.
$ManifestBaseUrl = "https://pkg.boundaryml.com/manifest/v1"
$Helper = Join-Path $env:GITHUB_ACTION_PATH "lib/wrapper-output.mjs"
$BinDir = Join-Path $env:BAML_HOME "bin"
$Wrapper = Join-Path $BinDir "baml.exe"
Expand All @@ -10,7 +13,7 @@ $Temp = Join-Path $TempRoot ("setup-baml-" + [System.Guid]::NewGuid())
$Installer = Join-Path $Temp "install.ps1"

Remove-Item Env:BAML_MANIFEST_BASE_URL -ErrorAction SilentlyContinue
Remove-Item Env:BAML_VERSION -ErrorAction SilentlyContinue
Remove-Item Env:BAML_TOOLCHAIN -ErrorAction SilentlyContinue

New-Item -ItemType Directory -Path $Temp | Out-Null
try {
Expand All @@ -29,7 +32,7 @@ try {
throw "setup-baml: invalid toolchain input"
}
$VersionOverride = $Selector
$env:BAML_VERSION = $VersionOverride
$env:BAML_TOOLCHAIN = $VersionOverride
} else {
$ListOutput = (& $Wrapper toolchain list | Out-String)
if ($LASTEXITCODE -ne 0) {
Expand All @@ -42,7 +45,7 @@ try {
}
}

& $Wrapper toolchain use $Selector
& $Wrapper toolchain use --global $Selector
if ($LASTEXITCODE -ne 0) {
throw "setup-baml: BAML toolchain installation failed with exit code $LASTEXITCODE"
}
Expand All @@ -63,8 +66,8 @@ try {

$BinDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
"BAML_HOME=$($env:BAML_HOME)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"BAML_VERSION=$VersionOverride" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"BAML_MANIFEST_BASE_URL=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"BAML_TOOLCHAIN=$VersionOverride" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"BAML_MANIFEST_BASE_URL=$ManifestBaseUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"version=$Version" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
"path=$Wrapper" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
"toolchain-path=$ToolchainPath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
Expand Down
13 changes: 8 additions & 5 deletions packaging/github-actions/setup-baml/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
set -euo pipefail

readonly installer_url="https://pkg.boundaryml.com/install.sh"
# Later steps get the official manifest source explicitly: wrapper 0.3 rejects an
# empty BAML_MANIFEST_BASE_URL instead of treating it as unset.
readonly manifest_base_url="https://pkg.boundaryml.com/manifest/v1"
readonly helper="${GITHUB_ACTION_PATH}/lib/wrapper-output.mjs"
readonly bin_dir="${BAML_HOME}/bin"
readonly wrapper="${bin_dir}/baml"

unset BAML_MANIFEST_BASE_URL || true
unset BAML_VERSION || true
unset BAML_TOOLCHAIN || true

tmp_dir="$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/setup-baml.XXXXXX")"
trap 'rm -rf "$tmp_dir"' EXIT
Expand All @@ -21,14 +24,14 @@ version_override=""
if [[ -n "$requested" ]]; then
selector="$(printf '%s' "$requested" | node "$helper" validate-selector)"
version_override="$selector"
export BAML_VERSION="$version_override"
export BAML_TOOLCHAIN="$version_override"
else
list_output="$("$wrapper" toolchain list)"
printf '%s\n' "$list_output"
selector="$(printf '%s' "$list_output" | node "$helper" selector)"
fi

"$wrapper" toolchain use "$selector"
"$wrapper" toolchain use --global "$selector"
version_output="$("$wrapper" --version)"
printf '%s\n' "$version_output"
version="$(printf '%s' "$version_output" | node "$helper" version)"
Expand All @@ -42,8 +45,8 @@ fi
printf '%s\n' "$bin_dir" >> "$GITHUB_PATH"
{
printf 'BAML_HOME=%s\n' "$BAML_HOME"
printf 'BAML_VERSION=%s\n' "$version_override"
printf 'BAML_MANIFEST_BASE_URL=\n'
printf 'BAML_TOOLCHAIN=%s\n' "$version_override"
printf 'BAML_MANIFEST_BASE_URL=%s\n' "$manifest_base_url"
} >> "$GITHUB_ENV"
{
printf 'version=%s\n' "$version"
Expand Down
16 changes: 15 additions & 1 deletion packaging/github-actions/setup-baml/test/wrapper-output.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ test("rejects unresolved and unsafe wrapper selectors", () => {
assert.throws(() => resolveSelector("installed toolchains: (none)\n"));
});

test("reads concrete versions from wrapper version output", () => {
test("reads the toolchain version that wrapper 0.3+ passes through", () => {
assert.equal(resolveVersion("baml wrapper 0.3.1\nbaml-cli 0.25.1\n"), "0.25.1");
assert.equal(resolveVersion("baml wrapper 0.3.1\r\nbaml-cli 0.25.1\r\n"), "0.25.1");
assert.equal(resolveVersion("baml wrapper 0.3.1\nbaml-cli 0.23.1-nightly.20261026.a\n"), "0.23.1-nightly.20261026.a");
});

test("rejects wrapper 0.3+ output without a toolchain version", () => {
assert.throws(() => resolveVersion("baml wrapper 0.3.1\n"));
assert.throws(() => resolveVersion("baml wrapper 0.3.1\nbaml-cli\n"));
assert.throws(() => resolveVersion("baml wrapper 0.3.1\nbaml-cli nightly\n"));
});

test("reads concrete versions from wrapper 0.2 version output", () => {
assert.equal(resolveVersion("baml wrapper 0.2.4\nbaml toolchain 0.16.0 (nightly)\n"), "0.16.0");
assert.equal(resolveVersion("baml wrapper 0.2.5\nbaml toolchain 0.25.0\n"), "0.25.0");
assert.equal(resolveVersion("baml wrapper 0.2.5\nbaml toolchain baml-cli 0.25.0 (local: /work/baml-cli)\n"), "0.25.0");
assert.equal(resolveVersion("baml wrapper 0.2.4\nbaml toolchain 0.15.1-nightly.20260810.b (nightly, from /work/baml.toml)\n"), "0.15.1-nightly.20260810.b");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,31 @@ export async function invokeBaml(
});
}

export async function readBamlBinaryIdentity(
binaryPath: string,
): Promise<BamlBinaryIdentity> {
const result = await invokeBaml(binaryPath, ['--version']);
const wrapperMatch = /^baml wrapper (\S+)$/m.exec(result.stdout);
const toolchainMatch = /^baml toolchain (\S+)(?: \([^\n]+\))?$/m.exec(
result.stdout,
);
/**
* Reads `baml --version` output. Wrapper 0.3+ prints `baml wrapper X` and then
* passes `--version` through to the selected toolchain (`baml-cli X`); wrapper
* 0.2 printed the toolchain itself as `baml toolchain [baml-cli ]X [(...)]`.
*/
export function parseBamlVersionOutput(stdout: string): BamlBinaryIdentity {
const wrapperMatch = /^baml wrapper (\S+)$/m.exec(stdout);
const toolchainMatch =
/^baml-cli (\S+)$/m.exec(stdout) ??
/^baml toolchain (?:baml-cli )?(\S+)(?: \([^\n]+\))?$/m.exec(stdout);
if (!wrapperMatch || !toolchainMatch) {
throw new Error(
'The selected baml binary did not expose the required wrapper and toolchain identities.',
);
}
return {
productVersion: toolchainMatch[1],
rawVersionOutput: result.stdout,
rawVersionOutput: stdout,
wrapperVersion: wrapperMatch[1],
};
}

export async function readBamlBinaryIdentity(
binaryPath: string,
): Promise<BamlBinaryIdentity> {
const result = await invokeBaml(binaryPath, ['--version']);
return parseBamlVersionOutput(result.stdout);
}
43 changes: 43 additions & 0 deletions typescript2/app-developer-docs/tests/generated-content.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { parseBamlVersionOutput } from '../lib/generated-content/baml-binary.ts';
import { hashDocumentManifest } from '../lib/generated-content/document-ir.ts';
import { projectDocumentRelease } from '../lib/generated-content/document-projector.ts';
import {
Expand All @@ -20,6 +21,48 @@ import {
referencePageRowSchema,
} from '../lib/generated-content/schemas.ts';

test('baml --version identity reads wrapper 0.3 and wrapper 0.2 output', () => {
// Wrapper 0.3+ passes --version through to the selected toolchain.
const current = 'baml wrapper 0.3.1\nbaml-cli 0.25.1\n';
assert.deepEqual(parseBamlVersionOutput(current), {
productVersion: '0.25.1',
rawVersionOutput: current,
wrapperVersion: '0.3.1',
});
// Wrapper 0.2 reported the toolchain on its own line.
assert.equal(
parseBamlVersionOutput(
'baml wrapper 0.2.4\nbaml toolchain 0.16.0 (nightly)\n',
).productVersion,
'0.16.0',
);
assert.equal(
parseBamlVersionOutput('baml wrapper 0.2.5\nbaml toolchain 0.25.0\n')
.productVersion,
'0.25.0',
);
assert.equal(
parseBamlVersionOutput(
'baml wrapper 0.2.5\nbaml toolchain baml-cli 0.25.0 (local: /work/baml-cli)\n set by $BAML_TOOLCHAIN\n',
).productVersion,
'0.25.0',
);
});

test('baml --version identity rejects output without both identities', () => {
for (const output of [
'baml wrapper 0.3.1\n',
'baml-cli 0.25.1\n',
'baml wrapper 0.2.4\nbaml toolchain not installed\n',
'baml wrapper 0.2.4\nbaml toolchain not resolved\n',
]) {
assert.throws(
() => parseBamlVersionOutput(output),
/wrapper and toolchain identities/,
);
}
});

test('canonical JSON sorts object keys, preserves arrays, and normalizes negative zero', () => {
assert.equal(
canonicalJson({ a: [{ x: null, y: true }], z: -0 }),
Expand Down
Loading