Files
dev/scripts/generate-homebrew-formula.sh
zeekay def087ac12 refactor: delete hanzo-dev, consolidate to one tree (codex-rs)
hanzo-dev was a 53-day-frozen diverged fork that release.yml shipped only
because codex-rs's v8 dep was believed to block musl. It doesn't — the prebuilt
rusty_v8 musl artifacts already exist (rust-release.yml uses them). So collapse
to the single canonical tree.

- Delete hanzo-dev/ (1416 paths). codex-rs has zero deps on it; its 'unique'
  crates (zap/sse/backoff) aren't needed (codex-rs has its own upstream impls);
  zt/zap zero-trust was feature-gated OFF in release builds so it never shipped
  (external ~/work/hanzozt SDKs + docs unaffected; design notes kept in LLM.md).
- Repoint every remaining hanzo-dev build/path ref to codex-rs: workflows
  (preview-build, issue-code, issue-comment), scripts (ci-tests.sh,
  generate-homebrew-formula.sh, pre-release.sh, build-fast.sh, hanzo.sh,
  hanzo-cli), code-sign actions, dependabot.yaml, merge-policy.json, docs.
- Port the dev-fast cargo profile into codex-rs/Cargo.toml (build-fast.sh /
  pre-release.sh / release.yml preflight all use it).
- Delete obsolete hanzo-dev-only tooling (check-codex-path-deps.sh,
  upstream-merge/diff-crates.sh) + repoint their callers.
- package.json/build-fast.sh build only --bin dev (codex-rs has no
  dev-tui/dev-exec split bins).

Verified locally: codex-rs builds `dev` (Hanzo Dev header, CODE_VERSION-aware);
zero dangling source refs (only npm package names + Homebrew formula name kept).
2026-06-18 20:44:03 -07:00

152 lines
4.1 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Generate a minimal Homebrew formula from the latest GitHub release.
# Writes Formula/Dev.rb into the repo root (not a tap); you can copy it
# into a tap repo to publish.
owner_repo="hanzoai/dev"
version="${1:-}"
# Helper to treat placeholder versions as unset
sanitize_version() {
case "$1" in
""|"0.0.0"|"0.0.0-dev") echo "" ;;
*) echo "$1" ;;
esac
}
version="$(sanitize_version "$version")"
if [ -z "$version" ] && [ -f "dev-cli/package.json" ]; then
raw="$(jq -r .version dev-cli/package.json)"
version="$(sanitize_version "$raw")"
fi
if [ -z "$version" ] && git rev-parse --git-dir >/dev/null 2>&1; then
tag="$(git describe --tags --abbrev=0 2>/dev/null || true)"
if [ -n "$tag" ]; then
# Strip optional leading 'v'
tag="${tag#v}"
version="$(sanitize_version "$tag")"
fi
fi
if [ -z "$version" ]; then
cat <<'ERR' >&2
Unable to infer release version.
Provide it as the first argument or ensure a tagged release exists.
The script no longer defaults to 0.0.0 to avoid publishing broken formulas.
ERR
exit 1
fi
# Optional directory where CI placed artifacts (step: Prepare release assets)
RELEASE_ASSETS_DIR=${RELEASE_ASSETS_DIR:-"release-assets"}
assets=(
"dev-aarch64-apple-darwin.tar.gz"
"dev-x86_64-apple-darwin.tar.gz"
)
sha256_file() {
local f="$1"
if command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$f" | awk '{print $1}'
elif command -v sha256sum >/dev/null 2>&1; then
sha256sum "$f" | awk '{print $1}'
else
echo ""; return 1
fi
}
# Retry a command with backoff: retry <max_tries> <sleep_seconds> <cmd...>
retry() {
local max="$1"; shift
local sleep_s="$1"; shift
local n=1
while :; do
if "$@"; then return 0; fi
if [ "$n" -ge "$max" ]; then return 1; fi
n=$((n+1))
sleep "$sleep_s"
done
}
mkdir -p Formula
cat > Formula/Dev.rb <<'RUBY'
class Dev < Formula
desc "Hanzo Dev - AI coding assistant"
homepage "https://github.com/hanzoai/dev"
RUBY
echo " version \"v${version}\"" >> Formula/Dev.rb
cat >> Formula/Dev.rb <<'RUBY'
on_macos do
if Hardware::CPU.arm?
url "__URL_ARM64__"
sha256 "__SHA_ARM64__"
else
url "__URL_X64__"
sha256 "__SHA_X64__"
end
end
def install
bin.install Dir["dev-*"].first => "dev"
# Provide a compatibility shim
(bin/"hanzo").write <<~EOS
#!/bin/bash
exec "#{bin}/dev" "$@"
EOS
end
test do
system "#{bin}/dev", "--help"
end
end
RUBY
for a in "${assets[@]}"; do
url="https://github.com/${owner_repo}/releases/download/v${version}/${a}"
tmp="/tmp/${a}"
sha=""
# Prefer local artifact if available to avoid CDN propagation races
local_path="${RELEASE_ASSETS_DIR}/${a}"
if [ -f "$local_path" ]; then
echo "Using local asset for sha256: ${local_path}" >&2
sha=$(sha256_file "$local_path") || sha=""
fi
# Fallback to remote download (with retries) if local missing or sha empty
if [ -z "$sha" ]; then
echo "Downloading ${url} (fallback for sha256)..." >&2
if ! retry 12 5 curl -fsSL "${url}" -o "${tmp}"; then
echo "WARN: Could not download ${url} to compute sha256 (possible CDN delay)." >&2
echo " Proceeding without sha; Homebrew step will still push formula referencing the URL." >&2
else
sha=$(sha256_file "$tmp" || true)
fi
fi
# Apply URL (always), and sha when available
if [[ "${a}" == *"aarch64-apple-darwin"* ]]; then
sed -i.bak "s#__URL_ARM64__#${url}#" Formula/Dev.rb
if [ -n "$sha" ]; then sed -i.bak "s#__SHA_ARM64__#${sha}#" Formula/Dev.rb; fi
else
sed -i.bak "s#__URL_X64__#${url}#" Formula/Dev.rb
if [ -n "$sha" ]; then sed -i.bak "s#__SHA_X64__#${sha}#" Formula/Dev.rb; fi
fi
done
rm -f Formula/Dev.rb.bak
echo "Wrote Formula/Dev.rb for v${version}"
# Optional: best-effort HEAD check to surface propagation status without failing CI
for a in "${assets[@]}"; do
url="https://github.com/${owner_repo}/releases/download/v${version}/${a}"
if ! retry 6 5 bash -c "curl -fsI \"$url\" >/dev/null"; then
echo "WARN: ${a} not yet available at ${url} (HEAD 404). Likely CDN propagation; continuing." >&2
fi
done