|
1 | 1 | #!/usr/bin/env sh |
2 | 2 | set -eu |
3 | 3 |
|
4 | | -VERSION="${ORCA_VERSION:-1.1.0}" |
5 | | -DIST_DIR="${ORCA_DIST_DIR:-dist}" |
6 | | -FORMULA="${ORCA_HOMEBREW_FORMULA:-packaging/homebrew/Formula/orca.rb}" |
7 | | -CHECKSUMS="${DIST_DIR}/checksums.txt" |
| 4 | +VERSION="${1:-${ORCA_VERSION:-}}" |
| 5 | +HOMEBREW_TAP_DIR="${ORCA_HOMEBREW_TAP_DIR:-${HOME}/code/homebrew-orca}" |
| 6 | +FORMULA_OUT="${ORCA_HOMEBREW_FORMULA:-${HOMEBREW_TAP_DIR}/Formula/orca.rb}" |
| 7 | +TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/orca-homebrew.XXXXXX")" |
| 8 | + |
| 9 | +cleanup() { |
| 10 | + rm -rf "$TMP_DIR" |
| 11 | +} |
| 12 | +trap cleanup EXIT INT TERM |
8 | 13 |
|
9 | 14 | fail() { |
10 | 15 | printf 'update-homebrew-formula: %s\n' "$1" >&2 |
11 | 16 | exit 1 |
12 | 17 | } |
13 | 18 |
|
14 | | -checksum_for() { |
15 | | - name="$1" |
16 | | - awk -v name="$name" '$2 == name {print $1}' "$CHECKSUMS" |
| 19 | +[ -n "$VERSION" ] || fail "usage: $0 <version> (or set ORCA_VERSION)" |
| 20 | + |
| 21 | +BASE_URL="https://github.com/christopherkarani/Orca/releases/download/v${VERSION}" |
| 22 | + |
| 23 | +printf 'Downloading release assets for Orca %s...\n' "$VERSION" |
| 24 | + |
| 25 | +for plat in darwin-arm64 darwin-amd64 linux-arm64 linux-amd64; do |
| 26 | + artifact="orca-v${VERSION}-${plat}.tar.gz" |
| 27 | + url="${BASE_URL}/${artifact}" |
| 28 | + output="${TMP_DIR}/${artifact}" |
| 29 | + |
| 30 | + printf ' → %s\n' "$artifact" |
| 31 | + if command -v curl >/dev/null 2>&1; then |
| 32 | + curl -fsSL -o "$output" "$url" || fail "failed to download $url" |
| 33 | + elif command -v wget >/dev/null 2>&1; then |
| 34 | + wget -q -O "$output" "$url" || fail "failed to download $url" |
| 35 | + else |
| 36 | + fail "curl or wget is required" |
| 37 | + fi |
| 38 | +done |
| 39 | + |
| 40 | +sha256_file() { |
| 41 | + file="$1" |
| 42 | + if command -v sha256sum >/dev/null 2>&1; then |
| 43 | + sha256sum "$file" | awk '{print $1}' |
| 44 | + elif command -v shasum >/dev/null 2>&1; then |
| 45 | + shasum -a 256 "$file" | awk '{print $1}' |
| 46 | + else |
| 47 | + fail "sha256sum or shasum is required" |
| 48 | + fi |
17 | 49 | } |
18 | 50 |
|
19 | | -[ -f "$FORMULA" ] || fail "formula not found: $FORMULA" |
20 | | -[ -f "$CHECKSUMS" ] || fail "checksums not found: $CHECKSUMS" |
| 51 | +darwin_arm64="$(sha256_file "${TMP_DIR}/orca-v${VERSION}-darwin-arm64.tar.gz")" |
| 52 | +darwin_amd64="$(sha256_file "${TMP_DIR}/orca-v${VERSION}-darwin-amd64.tar.gz")" |
| 53 | +linux_arm64="$(sha256_file "${TMP_DIR}/orca-v${VERSION}-linux-arm64.tar.gz")" |
| 54 | +linux_amd64="$(sha256_file "${TMP_DIR}/orca-v${VERSION}-linux-amd64.tar.gz")" |
21 | 55 |
|
22 | | -darwin_amd64="$(checksum_for "orca-v${VERSION}-darwin-amd64.tar.gz")" |
23 | | -darwin_arm64="$(checksum_for "orca-v${VERSION}-darwin-arm64.tar.gz")" |
24 | | -linux_amd64="$(checksum_for "orca-v${VERSION}-linux-amd64.tar.gz")" |
25 | | -linux_arm64="$(checksum_for "orca-v${VERSION}-linux-arm64.tar.gz")" |
| 56 | +printf 'Generating formula...\n' |
26 | 57 |
|
27 | | -[ -n "$darwin_amd64" ] || fail "missing darwin amd64 checksum" |
28 | | -[ -n "$darwin_arm64" ] || fail "missing darwin arm64 checksum" |
29 | | -[ -n "$linux_amd64" ] || fail "missing linux amd64 checksum" |
30 | | -[ -n "$linux_arm64" ] || fail "missing linux arm64 checksum" |
| 58 | +mkdir -p "$(dirname "$FORMULA_OUT")" |
31 | 59 |
|
32 | | -cat > "$FORMULA" <<EOF |
| 60 | +cat > "$FORMULA_OUT" <<EOF |
33 | 61 | class Orca < Formula |
34 | 62 | desc "Local runtime firewall for AI agents" |
35 | 63 | homepage "https://github.com/christopherkarani/Orca" |
@@ -57,30 +85,27 @@ class Orca < Formula |
57 | 85 | end |
58 | 86 |
|
59 | 87 | def install |
60 | | - libexec.install "bin/orca" if File.exist?("bin/orca") |
61 | | - pkgshare.install "docs" if Dir.exist?("docs") |
62 | | - pkgshare.install "examples" if Dir.exist?("examples") |
63 | | - pkgshare.install "fixtures" if Dir.exist?("fixtures") |
64 | | - pkgshare.install "integrations" if Dir.exist?("integrations") |
65 | | - pkgshare.install "policies" if Dir.exist?("policies") |
66 | | - pkgshare.install "schemas" if Dir.exist?("schemas") |
67 | | -
|
68 | | - (bin/"orca").write <<~EOS |
69 | | - #!/bin/sh |
70 | | - export ORCA_RESOURCE_ROOT="#{pkgshare}" |
71 | | - exec "#{libexec}/orca" "\$@" |
72 | | - EOS |
73 | | - chmod 0755, bin/"orca" |
| 88 | + bin.install "bin/orca" |
74 | 89 | end |
75 | 90 |
|
76 | 91 | test do |
77 | | - assert_match version.to_s, shell_output("#{bin}/orca version") |
78 | | - hermes_manifest = shell_output("#{bin}/orca plugin manifest hermes") |
79 | | - assert_match "Hermes plugin manifest", hermes_manifest |
80 | | - assert_match "manifest status: exists", hermes_manifest |
81 | | - assert_match "(exists)", hermes_manifest |
| 92 | + assert_match version.to_s, shell_output("#{bin}/orca --version") |
82 | 93 | end |
83 | 94 | end |
84 | 95 | EOF |
85 | 96 |
|
86 | | -printf 'Updated %s for Orca %s\n' "$FORMULA" "$VERSION" |
| 97 | +printf 'Formula written to %s\n' "$FORMULA_OUT" |
| 98 | + |
| 99 | +# Optionally commit and push to the tap repo |
| 100 | +if [ -d "${HOMEBREW_TAP_DIR}/.git" ]; then |
| 101 | + cd "$HOMEBREW_TAP_DIR" |
| 102 | + git add Formula/orca.rb |
| 103 | + if git diff --cached --quiet; then |
| 104 | + printf 'No changes to commit.\n' |
| 105 | + else |
| 106 | + git commit -m "Update orca to ${VERSION}" |
| 107 | + printf 'Committed. Run `git push` to publish.\n' |
| 108 | + fi |
| 109 | +else |
| 110 | + printf 'Note: %s is not a git repo. Skipping commit.\n' "$HOMEBREW_TAP_DIR" |
| 111 | +fi |
0 commit comments