Skip to content

Commit 6da1f5a

Browse files
committed
chore(process-daemon): publish from the monorepo
1 parent 58833a6 commit 6da1f5a

7 files changed

Lines changed: 360 additions & 23 deletions

File tree

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
name: Process daemon release
2+
3+
# Publishes the opencode-pty binaries and the @opencode-ai/pty npm packages from packages/process-daemon.
4+
# Only process-daemon-v<version> tags publish; pull requests that touch the release pipeline build and pack
5+
# without publishing.
6+
7+
on:
8+
push:
9+
tags:
10+
- "process-daemon-v*"
11+
pull_request:
12+
paths:
13+
- .github/workflows/release-process-daemon.yml
14+
- packages/process-daemon/build.rs
15+
- packages/process-daemon/npm/**
16+
- packages/process-daemon/script/npm-packages.mjs
17+
workflow_dispatch:
18+
19+
permissions:
20+
contents: read
21+
22+
defaults:
23+
run:
24+
working-directory: packages/process-daemon
25+
26+
env:
27+
CARGO_TERM_COLOR: always
28+
PROTOCOL_VERSION: 7
29+
ZIG_VERSION: 0.16.0
30+
GNU_GLIBC_VERSION: "2.30"
31+
CARGO_ZIGBUILD_VERSION: 0.23.2
32+
33+
jobs:
34+
checks:
35+
runs-on: ubuntu-22.04
36+
steps:
37+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+
- uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # v2.0.5
39+
with:
40+
version: ${{ env.ZIG_VERSION }}
41+
- name: Configure baseline Zig builds
42+
run: |
43+
chmod +x "$GITHUB_WORKSPACE/packages/process-daemon/script/release-bin/zig"
44+
echo "OPENCODE_REAL_ZIG=$(command -v zig)" >> "$GITHUB_ENV"
45+
echo "$GITHUB_WORKSPACE/packages/process-daemon/script/release-bin" >> "$GITHUB_PATH"
46+
- name: Install Rust
47+
run: rustup toolchain install 1.90.0 --profile minimal --component clippy --component rustfmt
48+
- name: Validate tag
49+
run: |
50+
package_version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "opencode-pty") | .version')"
51+
npm_version="$(node -p 'require("./npm/package.json").version')"
52+
test "$package_version" = "$npm_version"
53+
node -e 'const pkg = require("./npm/package.json"); if (Object.values(pkg.optionalDependencies).some(version => version !== pkg.version)) process.exit(1)'
54+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
55+
[[ "$GITHUB_REF_NAME" =~ ^process-daemon-v[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)?$ ]]
56+
test "${GITHUB_REF_NAME#process-daemon-v}" = "$package_version"
57+
fi
58+
- run: cargo fmt --check
59+
- run: cargo clippy --all-targets --all-features -- -D warnings
60+
61+
build:
62+
needs: checks
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
include:
67+
- runner: ubuntu-22.04
68+
target: x86_64-unknown-linux-gnu
69+
- runner: ubuntu-22.04-arm
70+
target: aarch64-unknown-linux-gnu
71+
- runner: ubuntu-22.04
72+
target: x86_64-unknown-linux-musl
73+
musl: true
74+
- runner: ubuntu-22.04-arm
75+
target: aarch64-unknown-linux-musl
76+
musl: true
77+
- runner: macos-15-intel
78+
target: x86_64-apple-darwin
79+
- runner: macos-15
80+
target: aarch64-apple-darwin
81+
runs-on: ${{ matrix.runner }}
82+
env:
83+
MACOSX_DEPLOYMENT_TARGET: "11.0"
84+
steps:
85+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
86+
- uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # v2.0.5
87+
with:
88+
version: ${{ env.ZIG_VERSION }}
89+
cache-key: ${{ matrix.target }}
90+
- name: Configure baseline Zig builds
91+
run: |
92+
chmod +x "$GITHUB_WORKSPACE/packages/process-daemon/script/release-bin/zig"
93+
echo "OPENCODE_REAL_ZIG=$(command -v zig)" >> "$GITHUB_ENV"
94+
echo "$GITHUB_WORKSPACE/packages/process-daemon/script/release-bin" >> "$GITHUB_PATH"
95+
- name: Install musl toolchain
96+
if: matrix.musl
97+
run: sudo apt-get update && sudo apt-get install -y musl-tools
98+
- name: Install Rust target
99+
run: rustup toolchain install 1.90.0 --profile minimal --target "${{ matrix.target }}"
100+
- name: Install glibc baseline linker
101+
if: endsWith(matrix.target, '-linux-gnu')
102+
run: cargo install cargo-zigbuild --locked --version "$CARGO_ZIGBUILD_VERSION"
103+
- name: Test service
104+
run: cargo test --locked --target "${{ matrix.target }}" --lib --test service --test ownership
105+
- name: Test CLI integration
106+
if: runner.os != 'macOS'
107+
run: cargo test --locked --target "${{ matrix.target }}" --test playground
108+
- name: Build
109+
run: |
110+
if [[ "${{ matrix.target }}" == *-linux-gnu ]]; then
111+
cargo zigbuild --locked --release --target "${{ matrix.target }}.$GNU_GLIBC_VERSION"
112+
else
113+
cargo build --locked --release --target "${{ matrix.target }}"
114+
fi
115+
- name: Verify glibc baseline
116+
if: endsWith(matrix.target, '-linux-gnu')
117+
run: |
118+
binary="target/${{ matrix.target }}/release/opencode-pty"
119+
required="$(readelf --version-info "$binary" | grep -oE 'GLIBC_[0-9]+(\.[0-9]+)+' | sed 's/GLIBC_//' | sort -V | tail -n 1)"
120+
echo "Highest required glibc version: $required"
121+
test "$(printf '%s\n' "$required" "$GNU_GLIBC_VERSION" | sort -V | tail -n 1)" = "$GNU_GLIBC_VERSION"
122+
- name: Smoke test
123+
run: |
124+
version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "opencode-pty") | .version')"
125+
binary="target/${{ matrix.target }}/release/opencode-pty"
126+
output="$("$binary" --version)"
127+
test "$output" = "opencode-pty $version (protocol $PROTOCOL_VERSION)"
128+
runtime="$RUNNER_TEMP/opencode-pty-release-smoke"
129+
rm -rf "$runtime"
130+
printf 'new /bin/sh -c "printf release-smoke; sleep 1"\nwait 250\nquit\n' \
131+
| "$binary" play --runtime-dir "$runtime" --name smoke > "$RUNNER_TEMP/opencode-pty-release-smoke.log"
132+
grep -q 'release-smoke' "$RUNNER_TEMP/opencode-pty-release-smoke.log"
133+
grep -q 'checkpoint' "$RUNNER_TEMP/opencode-pty-release-smoke.log"
134+
test ! -e "$runtime/smoke"
135+
- name: Package
136+
run: |
137+
version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "opencode-pty") | .version')"
138+
name="opencode-pty-${version}-${{ matrix.target }}"
139+
mkdir -p "dist/$name"
140+
cp "target/${{ matrix.target }}/release/opencode-pty" "dist/$name/"
141+
cp LICENSE README.md "dist/$name/"
142+
tar -C dist -czf "dist/$name.tar.gz" "$name"
143+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
144+
with:
145+
name: opencode-pty-${{ matrix.target }}
146+
path: packages/process-daemon/dist/*.tar.gz
147+
if-no-files-found: error
148+
149+
build-windows:
150+
needs: checks
151+
strategy:
152+
fail-fast: false
153+
matrix:
154+
include:
155+
- runner: windows-2025
156+
target: x86_64-pc-windows-msvc
157+
arch: x64
158+
- runner: windows-11-arm
159+
target: aarch64-pc-windows-msvc
160+
arch: arm64
161+
runs-on: ${{ matrix.runner }}
162+
timeout-minutes: 45
163+
defaults:
164+
run:
165+
shell: pwsh
166+
working-directory: packages/process-daemon
167+
env:
168+
CARGO_BUILD_TARGET: ${{ matrix.target }}
169+
RUSTUP_TOOLCHAIN: 1.90.0-x86_64-pc-windows-msvc
170+
# Portable CPU for Ghostty (see build.rs) and no Visual C++ runtime dependency.
171+
OPENCODE_ZIG_CPU: baseline
172+
RUSTFLAGS: -C target-feature=+crt-static
173+
steps:
174+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
175+
- name: Enable long dependency paths
176+
run: git config --global core.longpaths true
177+
- uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # v2.0.5
178+
if: matrix.arch == 'x64'
179+
with:
180+
version: ${{ env.ZIG_VERSION }}
181+
cache-key: release-${{ matrix.target }}
182+
# Zig 0.16 crashes when building Ghostty on the native ARM64 host, so use
183+
# the x64-hosted compiler there (matching check-process-daemon.yml).
184+
- name: Install x64 Zig for ARM64 cross-compilation
185+
if: matrix.arch == 'arm64'
186+
run: |
187+
$archive = Join-Path $env:RUNNER_TEMP 'zig-x64.zip'
188+
Invoke-WebRequest 'https://ziglang.org/download/0.16.0/zig-x86_64-windows-0.16.0.zip' -OutFile $archive
189+
if ((Get-FileHash $archive -Algorithm SHA256).Hash -ne '68659eb5f1e4eb1437a722f1dd889c5a322c9954607f5edcf337bc3684a75a7e') { throw 'Zig archive checksum mismatch' }
190+
Expand-Archive $archive -DestinationPath $env:RUNNER_TEMP
191+
Join-Path $env:RUNNER_TEMP 'zig-x86_64-windows-0.16.0' >> $env:GITHUB_PATH
192+
- name: Fix Zig 0.16 ARM64 function-pointer alignment
193+
if: matrix.arch == 'arm64'
194+
run: |
195+
$file = Join-Path $env:RUNNER_TEMP 'zig-x86_64-windows-0.16.0/lib/std/debug/SelfInfo/Windows.zig'
196+
$source = [System.IO.File]::ReadAllText($file)
197+
$old = '@ptrCast(try si.loadNtdllProc(@tagName(proc)))'
198+
if (!$source.Contains($old)) { throw 'Zig alignment workaround no longer matches; re-evaluate it' }
199+
[System.IO.File]::WriteAllText($file, $source.Replace($old, '@ptrCast(@alignCast(try si.loadNtdllProc(@tagName(proc))))'))
200+
- name: Install Rust toolchain and target
201+
run: rustup toolchain install $env:RUSTUP_TOOLCHAIN --force-non-host --profile minimal --target $env:CARGO_BUILD_TARGET
202+
- name: Build
203+
run: cargo build --locked --release
204+
- name: Smoke test
205+
run: |
206+
$metadata = cargo metadata --locked --no-deps --format-version 1 | ConvertFrom-Json
207+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
208+
$version = ($metadata.packages | Where-Object name -eq 'opencode-pty').version
209+
$binary = "target/$env:CARGO_BUILD_TARGET/release/opencode-pty.exe"
210+
$output = & $binary --version
211+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
212+
if ($output -ne "opencode-pty $version (protocol $env:PROTOCOL_VERSION)") { throw "Unexpected version output: $output" }
213+
# Start a real daemon over a named pipe; it stops when nobody claims it.
214+
$runtime = Join-Path $env:RUNNER_TEMP 'opencode-pty-release-smoke'
215+
$daemon = Start-Process $binary -ArgumentList @('daemon', '--runtime-dir', $runtime, '--name', 'smoke') -PassThru -NoNewWindow
216+
$deadline = (Get-Date).AddSeconds(10)
217+
while (!(Test-Path (Join-Path $runtime 'smoke/service.json'))) {
218+
if ($daemon.HasExited -or (Get-Date) -gt $deadline) { throw 'daemon did not register' }
219+
Start-Sleep -Milliseconds 50
220+
}
221+
if (!$daemon.WaitForExit(15000)) { $daemon.Kill(); throw 'unclaimed daemon did not stop' }
222+
if (Test-Path (Join-Path $runtime 'smoke')) { throw 'runtime directory was not removed' }
223+
- name: Package
224+
run: |
225+
$metadata = cargo metadata --locked --no-deps --format-version 1 | ConvertFrom-Json
226+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
227+
$version = ($metadata.packages | Where-Object name -eq 'opencode-pty').version
228+
$name = "opencode-pty-$version-$env:CARGO_BUILD_TARGET"
229+
New-Item -ItemType Directory -Force "dist/$name" | Out-Null
230+
Copy-Item "target/$env:CARGO_BUILD_TARGET/release/opencode-pty.exe" "dist/$name/"
231+
Copy-Item LICENSE, README.md "dist/$name/"
232+
tar -C dist -czf "dist/$name.tar.gz" $name
233+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
234+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
235+
with:
236+
name: opencode-pty-${{ matrix.target }}
237+
path: packages/process-daemon/dist/*.tar.gz
238+
if-no-files-found: error
239+
240+
release:
241+
needs: [build, build-windows]
242+
runs-on: ubuntu-22.04
243+
permissions:
244+
contents: write
245+
id-token: write
246+
attestations: write
247+
steps:
248+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
249+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
250+
with:
251+
node-version: "24"
252+
registry-url: https://registry.npmjs.org
253+
- name: Install npm with trusted publishing support
254+
run: npm install --global npm@^11.5.1
255+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
256+
with:
257+
path: packages/process-daemon/dist
258+
pattern: opencode-pty-*
259+
merge-multiple: true
260+
- name: Create checksums and manifest
261+
working-directory: packages/process-daemon/dist
262+
run: |
263+
version="$(node -p 'require("../npm/package.json").version')"
264+
sha256sum opencode-pty-*.tar.gz > SHA256SUMS
265+
artifacts='[]'
266+
while read -r sha256 archive; do
267+
target="${archive#opencode-pty-${version}-}"
268+
target="${target%.tar.gz}"
269+
artifacts="$(jq --arg target "$target" --arg archive "$archive" --arg sha256 "$sha256" '. + [{target: $target, archive: $archive, sha256: $sha256}]' <<<"$artifacts")"
270+
done < SHA256SUMS
271+
jq -n \
272+
--arg version "$version" \
273+
--argjson protocol "$PROTOCOL_VERSION" \
274+
--argjson artifacts "$artifacts" \
275+
'{schema: 1, version: $version, protocol: $protocol, artifacts: $artifacts}' \
276+
> release-manifest.json
277+
sha256sum release-manifest.json >> SHA256SUMS
278+
- name: Prepare npm packages
279+
run: node script/npm-packages.mjs dist
280+
- name: Validate npm packages
281+
run: |
282+
for package in dist/npm/*; do
283+
npm pack --dry-run "$package" >/dev/null
284+
done
285+
temporary="$(mktemp -d)"
286+
npm pack --pack-destination "$temporary" dist/npm/opencode-pty-linux-x64-gnu dist/npm/opencode-pty >/dev/null
287+
npm install --prefix "$temporary" --ignore-scripts --no-package-lock --no-audit --no-fund "$temporary"/*.tgz
288+
test "$("$temporary/node_modules/.bin/opencode-pty" --version)" = "opencode-pty $(node -p 'require("./npm/package.json").version') (protocol $PROTOCOL_VERSION)"
289+
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
290+
if: startsWith(github.ref, 'refs/tags/process-daemon-v')
291+
with:
292+
subject-checksums: packages/process-daemon/dist/SHA256SUMS
293+
# The monorepo's Latest release drives OpenCode's own update paths, so this release must never become
294+
# Latest. It is drafted first because immutable releases lock assets once published.
295+
- name: Publish release
296+
if: startsWith(github.ref, 'refs/tags/process-daemon-v')
297+
env:
298+
GH_TOKEN: ${{ github.token }}
299+
run: |
300+
version="${GITHUB_REF_NAME#process-daemon-v}"
301+
gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1 ||
302+
gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --draft --verify-tag --latest=false \
303+
--title "process-daemon v$version" \
304+
--notes "opencode-pty $version (protocol $PROTOCOL_VERSION) from packages/process-daemon, published to npm as @opencode-ai/pty@$version."
305+
gh release upload "$GITHUB_REF_NAME" dist/*.tar.gz dist/SHA256SUMS dist/release-manifest.json --clobber --repo "$GITHUB_REPOSITORY"
306+
gh release edit "$GITHUB_REF_NAME" --draft=false --latest=false --repo "$GITHUB_REPOSITORY"
307+
- name: Publish npm packages
308+
if: startsWith(github.ref, 'refs/tags/process-daemon-v')
309+
run: |
310+
version="${GITHUB_REF_NAME#process-daemon-v}"
311+
for package in dist/npm/opencode-pty-*; do
312+
name="$(node -p 'require(process.argv[1]).name' "$(realpath "$package/package.json")")"
313+
if ! npm view "$name@$version" version >/dev/null 2>&1; then
314+
npm publish "$package" --access public --provenance
315+
fi
316+
done
317+
name="@opencode-ai/pty"
318+
if ! npm view "$name@$version" version >/dev/null 2>&1; then
319+
npm publish dist/npm/opencode-pty --access public --provenance
320+
fi

‎packages/core/src/persistent-pty/pty-binding.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Published separately by anomalyco/opencode-pty; it has not migrated npm scopes.
1+
// Published from packages/process-daemon under its original npm scope.
22
import { binaryPath } from "@opencode-ai/pty"
33

44
const binding: string | { readonly path: string; readonly version: string; readonly sha256: string } | undefined =

‎packages/process-daemon/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2024"
55
rust-version = "1.90"
66
description = "Persistent PTY service for OpenCode"
77
license = "MIT"
8-
repository = "https://github.com/anomalyco/opencode-pty"
8+
repository = "https://github.com/anomalyco/opencode"
99
links = "ghostty-vt"
1010

1111
[dependencies]

‎packages/process-daemon/README.md‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,31 @@ gh run view RUN_ID --repo anomalyco/opencode --log-failed
345345

346346
## Releases
347347

348-
The release workflow has not moved to the monorepo yet; until it does, the
349-
process below describes releases from anomalyco/opencode-pty.
350-
351-
Pushing a `vX.Y.Z` tag matching the version in `Cargo.toml` creates an unsigned
352-
GitHub release. The release contains x86-64 and arm64 binaries for Linux GNU,
353-
Linux musl, macOS, and Windows (MSVC, statically linked C runtime), plus
354-
`SHA256SUMS`, a machine-readable
355-
`release-manifest.json`, and GitHub build-provenance attestations. Release
356-
builds force Ghostty's Zig code generation to its baseline CPU target so
357-
artifacts do not inherit instruction-set extensions from CI runners (Windows
358-
builds set `OPENCODE_ZIG_CPU=baseline`, since the Unix Zig wrapper is a shell
359-
script). Linux GNU artifacts support glibc 2.30 and newer.
348+
Releases are built by
349+
[`.github/workflows/release-process-daemon.yml`](../../.github/workflows/release-process-daemon.yml)
350+
in anomalyco/opencode. To release version `X.Y.Z`:
351+
352+
1. Bump `version` in `Cargo.toml` (and `Cargo.lock`), and `version` plus every
353+
`optionalDependencies` entry in `npm/package.json`, to `X.Y.Z`. The workflow
354+
fails if any of them disagree.
355+
2. Merge the bump to `dev`.
356+
3. Push a `process-daemon-vX.Y.Z` tag at the merged commit:
357+
358+
```sh
359+
git tag process-daemon-vX.Y.Z
360+
git push origin process-daemon-vX.Y.Z
361+
```
362+
363+
The tag creates an unsigned GitHub release titled `process-daemon vX.Y.Z`. It
364+
is never marked Latest, because the monorepo's Latest release drives
365+
OpenCode's own update paths. The release contains x86-64 and arm64 binaries
366+
for Linux GNU, Linux musl, macOS, and Windows (MSVC, statically linked C
367+
runtime), plus `SHA256SUMS`, a machine-readable `release-manifest.json`, and
368+
GitHub build-provenance attestations. Release builds force Ghostty's Zig code
369+
generation to its baseline CPU target so artifacts do not inherit
370+
instruction-set extensions from CI runners (Windows builds set
371+
`OPENCODE_ZIG_CPU=baseline`, since the Unix Zig wrapper is a shell script).
372+
Linux GNU artifacts support glibc 2.30 and newer.
360373

361374
Tagged releases also publish `@opencode-ai/pty` to npm with optional,
362375
platform-specific binary packages. Installing the npm package selects the native
@@ -367,10 +380,13 @@ its path as `binaryPath`:
367380
import { binaryPath } from "@opencode-ai/pty"
368381
```
369382

370-
```sh
371-
git tag v0.1.0
372-
push origin v0.1.0
373-
```
383+
npm publishing uses trusted publishing with provenance. Each of the nine
384+
packages (`@opencode-ai/pty` and the eight `@opencode-ai/pty-<platform>`
385+
packages) must list anomalyco/opencode with workflow
386+
`release-process-daemon.yml` as its trusted publisher.
387+
388+
Pull requests that change the release pipeline run the same build and npm
389+
packing without publishing anything.
374390

375391
Platform signing will be added later.
376392

0 commit comments

Comments
 (0)