Skip to content

Build release binary with Go#53

Merged
Vasanthdev2004 merged 1 commit into
mainfrom
feat/m1-binary-build
Jun 4, 2026
Merged

Build release binary with Go#53
Vasanthdev2004 merged 1 commit into
mainfrom
feat/m1-binary-build

Conversation

@anandh8x

@anandh8x anandh8x commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Build the release-facing zero binary with Go instead of Bun compile.
  • Inject package.json version into the Go CLI with ldflags and keep dev as the raw Go fallback.
  • Add Go target helpers, build flags for cross-target output, workflow Go setup, release/package smoke updates, and docs/tests.

Validation

  • bun test tests/build-scripts.test.ts tests/foundation-tools.test.ts --timeout 15000
  • bun test tests/install-scripts.test.ts tests/release-checksums.test.ts --timeout 15000
  • bun run typecheck
  • bun run test:go
  • bun run build
  • bun run build:go
  • bun run smoke:build
  • bun run smoke:go
  • bun run package:release
  • bun run verify:release
  • tar -tzf dist/release/zero-v0.1.0-linux-x64.tar.gz
  • bun run scripts/build.ts --goos windows --goarch amd64 --output /tmp/zero-build-test.exe
  • git diff --check

Full suite note

  • bun run test: 279 pass, 5 fail locally in the same known headless/MCP environment-sensitive tests: stream-json stdin provider setup, session server port 0, and MCP stdio initialize/list flows.

Summary by CodeRabbit

  • Build System

    • New Go-native build CLI with explicit cross-compile options and deterministic output naming for multiple platforms.
  • Documentation

    • Updated development guides and checklists with clear build/release examples and clarified smoke/performance benchmark behavior.
  • Chores

    • CI workflows now set up the Go toolchain with caching enabled.
    • CLI version output changed to "dev"; tests updated to match.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Typecheck: bun run typecheck
  • [pass] Tests: bun run test
  • [pass] Build: bun run build
  • [pass] Smoke build: bun run smoke:build

Scope

Head: 9244258ea0b9
Changed files (14): .github/workflows/ci.yml, .github/workflows/release-artifacts.yml, README.md, docs/NPM_WRAPPER_SMOKE.md, docs/PERFORMANCE.md, internal/cli/app.go, internal/cli/app_test.go, package.json, scripts/artifact.ts, scripts/build.ts, scripts/package-release.ts, scripts/smoke-build.ts, and 2 more

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9cfc85ca-1025-4dfa-ab1e-1850aaf5f90d

📥 Commits

Reviewing files that changed from the base of the PR and between 7a79faa and 9244258.

📒 Files selected for processing (14)
  • .github/workflows/ci.yml
  • .github/workflows/release-artifacts.yml
  • README.md
  • docs/NPM_WRAPPER_SMOKE.md
  • docs/PERFORMANCE.md
  • internal/cli/app.go
  • internal/cli/app_test.go
  • package.json
  • scripts/artifact.ts
  • scripts/build.ts
  • scripts/package-release.ts
  • scripts/smoke-build.ts
  • tests/build-scripts.test.ts
  • tests/foundation-tools.test.ts
✅ Files skipped from review due to trivial changes (4)
  • internal/cli/app_test.go
  • docs/NPM_WRAPPER_SMOKE.md
  • docs/PERFORMANCE.md
  • README.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • .github/workflows/ci.yml
  • internal/cli/app.go
  • scripts/smoke-build.ts
  • tests/build-scripts.test.ts
  • scripts/package-release.ts
  • scripts/artifact.ts

📝 Walkthrough

Walkthrough

This PR replaces the direct go build invocation with a Bun/TypeScript build CLI that supports --goos/--goarch targets, reads package.json version, injects it into the Go build via ldflags, and updates CI, docs, tests, and npm wiring accordingly.

Changes

Go Binary Build CLI with Platform Targeting and Version Injection

Layer / File(s) Summary
Artifact path and platform mapping helpers
scripts/artifact.ts
New exports getZeroArtifactNameForGoOS, getZeroArtifactPath, getGoOS, and getGoArch map Node platform/arch to Go targets and build artifact paths.
Go binary build CLI implementation
scripts/build.ts
Full builder CLI: typed arg parsing (--goos,--goarch,--output,--help), env overrides, parsePackageVersion, defaultBuildOutput, goBuildLdflags, buildZeroBinary that spawns go build with -trimpath and version -ldflags, plus main wiring and execution guard.
Build script wiring
package.json, scripts/package-release.ts
build:go now calls bun run scripts/build.ts; package-release.ts imports parsePackageVersion from the build script.
CI workflow Go setup
.github/workflows/ci.yml, .github/workflows/release-artifacts.yml
Adds actions/setup-go steps reading go.mod and enabling cache in performance and release workflows.
CLI version and smoke validation
internal/cli/app.go, internal/cli/app_test.go, scripts/smoke-build.ts
CLI version changed from "0.1.0" const to var "dev"; smoke-build now strictly parses package.json version and asserts zero ${version} output.
Documentation and tests
README.md, docs/NPM_WRAPPER_SMOKE.md, docs/PERFORMANCE.md, tests/build-scripts.test.ts, tests/foundation-tools.test.ts
README adds cross-compile examples; docs updated for wrapper smoke and performance; tests expanded to cover artifact naming, platform mapping, parseBuildArgs, default outputs, and ldflags/version injection.

Sequence Diagram(s)

sequenceDiagram
  participant Script as scripts/build.ts
  participant Parser as parseBuildArgs
  participant Reader as parsePackageVersion
  participant Builder as buildZeroBinary
  participant GoBuild as "go build"

  Script->>Parser: parse CLI args / env
  Script->>Reader: read package.json -> version
  Script->>Builder: invoke buildZeroBinary(goos, goarch, output, version)
  Builder->>GoBuild: spawn go build with -ldflags (version)
  GoBuild-->>Builder: stdout/stderr, exit status
  Builder-->>Script: success or throw
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Gitlawb/zero#45: Updates CLI version handling that this PR modifies from 0.1.0dev.
  • Gitlawb/zero#46: Prior Go build wiring and CI integration related to build:go and smoke/release steps.

Suggested reviewers

  • Vasanthdev2004

"A rabbit built a binary bold,
with flags and targets in a fold.
It reads the version neat,
and cross-compiles a feat —
zero runs dev, the story told."

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Build release binary with Go' accurately and concisely summarizes the main objective of replacing Bun compile with Go to build the release-facing zero binary.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/m1-binary-build

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai Bot previously requested changes Jun 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/build-scripts.test.ts (1)

65-83: ⚡ Quick win

Add a regression test for short-flag value rejection.

Please add a case like parseBuildArgs(['-o', '-h']) (and/or ['--goarch', '-h']) expecting a throw, so the parser behavior is locked for this CLI edge path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/build-scripts.test.ts` around lines 65 - 83, Add a regression test in
tests/build-scripts.test.ts that verifies parseBuildArgs rejects a short-flag
value that looks like a flag (e.g. call parseBuildArgs(['-o', '-h']) and/or
parseBuildArgs(['--goarch', '-h'])) by expecting it to throw; locate the
existing Go binary tests using the describe block 'Go binary build script' and
add an it case asserting that parseBuildArgs throws for those inputs to lock the
CLI edge-case behavior for the parseBuildArgs function.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/build.ts`:
- Around line 185-191: The requireValue function currently only treats values
starting with '--' as missing, allowing short flags like '-h' to be mistaken for
values; update requireValue (args, index, flag) to reject any value that starts
with '-' (single or double) — e.g., check value is truthy and does not match
/^-/ or use value.startsWith('-') — and throw the same `${flag} requires a
value` error when a short or long flag is encountered so callers like
requireValue(...) will not accept '-h' or '-o' as valid values.

---

Nitpick comments:
In `@tests/build-scripts.test.ts`:
- Around line 65-83: Add a regression test in tests/build-scripts.test.ts that
verifies parseBuildArgs rejects a short-flag value that looks like a flag (e.g.
call parseBuildArgs(['-o', '-h']) and/or parseBuildArgs(['--goarch', '-h'])) by
expecting it to throw; locate the existing Go binary tests using the describe
block 'Go binary build script' and add an it case asserting that parseBuildArgs
throws for those inputs to lock the CLI edge-case behavior for the
parseBuildArgs function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ba173577-3c7c-4332-b274-7a0b895a8fc9

📥 Commits

Reviewing files that changed from the base of the PR and between b8e194d and 7a79faa.

📒 Files selected for processing (14)
  • .github/workflows/ci.yml
  • .github/workflows/release-artifacts.yml
  • README.md
  • docs/NPM_WRAPPER_SMOKE.md
  • docs/PERFORMANCE.md
  • internal/cli/app.go
  • internal/cli/app_test.go
  • package.json
  • scripts/artifact.ts
  • scripts/build.ts
  • scripts/package-release.ts
  • scripts/smoke-build.ts
  • tests/build-scripts.test.ts
  • tests/foundation-tools.test.ts

Comment thread scripts/build.ts
@anandh8x
anandh8x force-pushed the feat/m1-binary-build branch from 7a79faa to b55d408 Compare June 4, 2026 11:11
@anandh8x
anandh8x force-pushed the feat/m1-binary-build branch from b55d408 to 9244258 Compare June 4, 2026 11:13
@Vasanthdev2004

Copy link
Copy Markdown
Collaborator

Blockers
None.

Non-Blocking

  • Local review host still does not have Go installed, so I could not run the Go/release artifact commands locally. bun run build fails here with Executable not found in $PATH: "go". I verified Go build/test/smoke through the PR's GitHub CI jobs instead; Go test/build/smoke passed on ubuntu, macos, and windows at head 9244258.
  • The branch merge-base was behind current origin/main, so I created a latest-main test-merge worktree. The merge applied cleanly and the TS/Bun validation path passed there too.
  • CodeRabbit's short-flag parser finding is fixed in current code: requireValue() now rejects any value starting with -, and the regression test covers ['-o', '-h'] / ['--goarch', '-h']. My manual parser probe also confirmed those inputs throw.
  • Release workflow packaging is only triggered by workflow_dispatch/tags, not this PR's normal CI. The pieces it depends on are covered by unit tests plus CI Go build/smoke; if we want full release confidence before tagging, run the release-artifacts workflow or package:release on a machine with Go installed.

Looks Good

  • This moves the release-facing bun run build path to the Go binary builder while keeping build:go as the stable alias. That matches the Go-native migration direction better than continuing to ship Bun-compiled TS as the release binary.
  • Version injection is centralized via -ldflags -X github.com/Gitlawb/zero/internal/cli.version=<package version>, with the Go CLI defaulting to dev when built raw.
  • Platform mapping is explicit: Node win32 -> Go windows, x64 -> amd64, and target GOOS controls zero.exe vs zero output naming.
  • The build CLI handles --goos, --goarch, -o/--output, env overrides, inline values, help output, and flag-shaped missing values cleanly.
  • Release/package smoke docs now distinguish the Go-native release binary from the transitional TS/Bun wrapper.
  • PR-branch validation I ran:
    • bun install --frozen-lockfile PASS
    • bun test tests/build-scripts.test.ts tests/foundation-tools.test.ts --timeout 15000 PASS, 20 pass / 0 fail
    • bun test tests/install-scripts.test.ts tests/release-checksums.test.ts --timeout 15000 PASS, 10 pass / 0 fail
    • bun run typecheck PASS
    • bun test ./tests --timeout 15000 PASS, 285 pass / 0 fail
    • git diff --check PASS
    • build CLI --help PASS
    • parser edge probe for -o -h, --goarch -h, and --goos= PASS
  • Latest-main test-merge validation I ran:
    • merge origin/pr/53 into current origin/main PASS
    • targeted build/foundation tests PASS, 20 pass / 0 fail
    • install/release-checksum tests PASS, 10 pass / 0 fail
    • bun run typecheck PASS
    • bun test ./tests --timeout 15000 PASS, 285 pass / 0 fail
    • git diff --check --cached and git diff --check PASS
  • GitHub CI for 9244258: Go test/build/smoke PASS on ubuntu/macos/windows, TS/Bun test/typecheck/build/smoke PASS, performance smoke PASS.

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved current head 9244258 after reviewing the Go release-binary build path, verifying the parser edge fix, checking CI Go validation, and validating both PR branch and latest-main test-merge TS/Bun paths.

@gnanam1990 gnanam1990 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved current head 9244258ea0b93e8700ced1387939e20ef337a75c after rechecking the build-script changes, the previously requested short-flag parser fix, and the release binary flow.

Notes:

  • The earlier CodeRabbit requireValue finding is fixed in current code: values starting with - are rejected, and the regression test covers ['-o', '-h'] and ['--goarch', '-h'].
  • CodeRabbit's latest pass says no actionable comments were generated.
  • I did not find remaining blockers in the changed release/build path.

Validation run:

  • bun install --frozen-lockfile passed
  • bun test tests/build-scripts.test.ts tests/foundation-tools.test.ts --timeout 15000 passed
  • bun test tests/install-scripts.test.ts tests/release-checksums.test.ts --timeout 15000 passed
  • bun run typecheck passed
  • go test ./... passed
  • bun run build passed and produced the Go binary with version 0.1.0
  • bun run smoke:build passed
  • bun run smoke:go passed
  • bun test ./tests --timeout 15000 passed, 285 pass / 0 fail
  • git diff --check origin/main...HEAD passed

@Vasanthdev2004

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Vasanthdev2004
Vasanthdev2004 dismissed coderabbitai[bot]’s stale review June 4, 2026 13:54

Fixed in 9244258; latest CodeRabbit status is green and maintainers approved current head.

@Vasanthdev2004
Vasanthdev2004 merged commit e42a34f into main Jun 4, 2026
6 checks passed
@Vasanthdev2004
Vasanthdev2004 deleted the feat/m1-binary-build branch June 28, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants