|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Generate the Homebrew formula for the `cants` (codeanalyzer-typescript) binary. |
| 4 | +# |
| 5 | +# This is the non-Rust equivalent of what cargo-dist does automatically: it takes |
| 6 | +# the per-platform binaries that the release already publishes as GitHub Release |
| 7 | +# assets, computes their sha256, and emits a formula that downloads + installs the |
| 8 | +# matching binary for the user's platform. |
| 9 | +# |
| 10 | +# It reads the binaries straight from the release-bins/ dir built by release.yml, |
| 11 | +# so the checksums are guaranteed to match the bytes that were uploaded. The |
| 12 | +# download URLs point at the GitHub Release assets of the SAME tag. |
| 13 | +# |
| 14 | +# Usage: |
| 15 | +# REPO=codellm-devkit/codeanalyzer-ts VERSION=0.2.0 \ |
| 16 | +# ./generate_formula.sh ../../release-bins > codeanalyzer-ts.rb |
| 17 | +# |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +BINS_DIR="${1:?usage: generate_formula.sh <release-bins-dir>}" |
| 21 | +REPO="${REPO:?set REPO, e.g. codellm-devkit/codeanalyzer-ts}" |
| 22 | +VERSION="${VERSION:?set VERSION, e.g. 0.2.0}" |
| 23 | +BASE_URL="https://github.com/${REPO}/releases/download/v${VERSION}" |
| 24 | + |
| 25 | +sha() { shasum -a 256 "$1" | cut -d' ' -f1; } |
| 26 | + |
| 27 | +# Map each release asset (named by Python wheel platform tag) to its Homebrew |
| 28 | +# os/arch block. Windows is intentionally omitted -- Homebrew is macOS/Linux only. |
| 29 | +asset_macos_arm="cants-macosx_11_0_arm64" |
| 30 | +asset_macos_intel="cants-macosx_10_12_x86_64" |
| 31 | +asset_linux_intel="cants-manylinux2014_x86_64" |
| 32 | +asset_linux_arm="cants-manylinux2014_aarch64" |
| 33 | + |
| 34 | +for a in "$asset_macos_arm" "$asset_macos_intel" "$asset_linux_intel" "$asset_linux_arm"; do |
| 35 | + [[ -f "$BINS_DIR/$a" ]] || { echo "missing expected binary: $BINS_DIR/$a" >&2; exit 1; } |
| 36 | +done |
| 37 | + |
| 38 | +cat <<EOF |
| 39 | +# This file is auto-generated by packaging/homebrew/generate_formula.sh on release. |
| 40 | +# Do not edit by hand -- changes will be overwritten on the next tag. |
| 41 | +class CodeanalyzerTypescript < Formula |
| 42 | + desc "CLDK TypeScript analyzer (cants) -- emits canonical CLDK analysis.json" |
| 43 | + homepage "https://github.com/${REPO}" |
| 44 | + version "${VERSION}" |
| 45 | + license "Apache-2.0" |
| 46 | +
|
| 47 | + on_macos do |
| 48 | + on_arm do |
| 49 | + url "${BASE_URL}/${asset_macos_arm}" |
| 50 | + sha256 "$(sha "$BINS_DIR/$asset_macos_arm")" |
| 51 | + end |
| 52 | + on_intel do |
| 53 | + url "${BASE_URL}/${asset_macos_intel}" |
| 54 | + sha256 "$(sha "$BINS_DIR/$asset_macos_intel")" |
| 55 | + end |
| 56 | + end |
| 57 | +
|
| 58 | + on_linux do |
| 59 | + on_arm do |
| 60 | + url "${BASE_URL}/${asset_linux_arm}" |
| 61 | + sha256 "$(sha "$BINS_DIR/$asset_linux_arm")" |
| 62 | + end |
| 63 | + on_intel do |
| 64 | + url "${BASE_URL}/${asset_linux_intel}" |
| 65 | + sha256 "$(sha "$BINS_DIR/$asset_linux_intel")" |
| 66 | + end |
| 67 | + end |
| 68 | +
|
| 69 | + def install |
| 70 | + # The release asset is a bare executable; Homebrew stages it under its |
| 71 | + # original (platform-tagged) name. Install it as the canonical "cants". |
| 72 | + bin.install Dir["cants-*"].first => "cants" |
| 73 | + end |
| 74 | +
|
| 75 | + test do |
| 76 | + # cants has no --version flag and requires -i; --help is handled first and |
| 77 | + # exits 0, so it is the safe smoke test that the binary runs on this platform. |
| 78 | + assert_match "Usage: cants", shell_output("#{bin}/cants --help") |
| 79 | + end |
| 80 | +end |
| 81 | +EOF |
0 commit comments