Skip to content

Commit 409de90

Browse files
designcodeclaude
andauthored
feat: installation via homebrew tap (#65)
* feat: installation via homebrew tap * fix: check homebrew only for binary installs in update command Moves the isHomebrewInstall() check after the isBinary guard so npm installs always get the npm update command, even if brew also has tigris installed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5295a3f commit 409de90

5 files changed

Lines changed: 201 additions & 2 deletions

File tree

.github/workflows/release.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,18 @@ jobs:
147147
done
148148
149149
echo "All assets uploaded to $TAG"
150+
151+
update-homebrew:
152+
needs: [release, build-binaries]
153+
if: needs.release.outputs.new_release_published == 'true'
154+
runs-on: ubuntu-latest
155+
156+
steps:
157+
- uses: actions/checkout@v5
158+
with:
159+
ref: v${{ needs.release.outputs.new_release_version }}
160+
161+
- name: Update Homebrew formula
162+
env:
163+
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
164+
run: scripts/update-homebrew.sh ${{ needs.release.outputs.new_release_version }}

INSTALL.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Tigris CLI Installation Guide
22

3+
## Homebrew (macOS and Linux)
4+
5+
```sh
6+
brew install tigrisdata/tap/tigris
7+
```
8+
9+
### Uninstall (Homebrew)
10+
11+
```sh
12+
brew uninstall tigris
13+
```
14+
15+
---
16+
317
## npm
418

519
Requires Node.js 18+.
@@ -28,8 +42,8 @@ curl -fsSL https://raw.githubusercontent.com/tigrisdata/cli/main/scripts/install
2842

2943
#### Options
3044

31-
| Environment Variable | Description |
32-
| -------------------- | --------------------------------------------------- |
45+
| Environment Variable | Description |
46+
| -------------------- | ---------------------------------------------------- |
3347
| `TIGRIS_VERSION` | Install a specific version (e.g., `v2.9.0`) |
3448
| `TIGRIS_INSTALL_DIR` | Custom install directory (default: `/usr/local/bin`) |
3549

homebrew/Formula/tigris.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# typed: false
2+
# frozen_string_literal: true
3+
4+
# This formula is auto-generated by scripts/update-homebrew.sh — do not edit manually.
5+
class Tigris < Formula
6+
desc "Command line interface for Tigris object storage"
7+
homepage "https://www.tigrisdata.com"
8+
license "MIT"
9+
version "VERSION_PLACEHOLDER"
10+
11+
on_macos do
12+
on_arm do
13+
url "https://github.com/tigrisdata/cli/releases/download/vVERSION_PLACEHOLDER/tigris-darwin-arm64.tar.gz"
14+
sha256 "SHA_DARWIN_ARM64_PLACEHOLDER"
15+
end
16+
on_intel do
17+
url "https://github.com/tigrisdata/cli/releases/download/vVERSION_PLACEHOLDER/tigris-darwin-x64.tar.gz"
18+
sha256 "SHA_DARWIN_X64_PLACEHOLDER"
19+
end
20+
end
21+
22+
on_linux do
23+
on_arm do
24+
url "https://github.com/tigrisdata/cli/releases/download/vVERSION_PLACEHOLDER/tigris-linux-arm64.tar.gz"
25+
sha256 "SHA_LINUX_ARM64_PLACEHOLDER"
26+
end
27+
on_intel do
28+
url "https://github.com/tigrisdata/cli/releases/download/vVERSION_PLACEHOLDER/tigris-linux-x64.tar.gz"
29+
sha256 "SHA_LINUX_X64_PLACEHOLDER"
30+
end
31+
end
32+
33+
def install
34+
host_os = OS.mac? ? "darwin" : "linux"
35+
host_arch = Hardware::CPU.arm? ? "arm64" : "x64"
36+
bin.install "tigris-#{host_os}-#{host_arch}" => "tigris"
37+
bin.install_symlink "tigris" => "t3"
38+
end
39+
40+
test do
41+
assert_match version.to_s, shell_output("#{bin}/tigris --version")
42+
end
43+
end

scripts/update-homebrew.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env bash
2+
# Updates the Homebrew formula with the correct version and SHA256 hashes,
3+
# then opens a PR against the tigrisdata/homebrew-tap repo.
4+
#
5+
# Usage:
6+
# scripts/update-homebrew.sh <version>
7+
#
8+
# Example:
9+
# scripts/update-homebrew.sh 1.2.3
10+
#
11+
# Environment variables:
12+
# HOMEBREW_TAP_TOKEN - GitHub token with push and PR access to the tap repo (required in CI)
13+
# HOMEBREW_TAP_REPO - Override tap repo (default: tigrisdata/homebrew-tap)
14+
15+
set -euo pipefail
16+
17+
VERSION="${1:?Usage: update-homebrew.sh <version>}"
18+
TAP_REPO="${HOMEBREW_TAP_REPO:-tigrisdata/homebrew-tap}"
19+
CLI_REPO="tigrisdata/cli"
20+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
21+
TEMPLATE="${SCRIPT_DIR}/../homebrew/Formula/tigris.rb"
22+
23+
if [ ! -f "$TEMPLATE" ]; then
24+
echo "ERROR: Formula template not found at $TEMPLATE"
25+
exit 1
26+
fi
27+
28+
# Download each archive and compute SHA256
29+
compute_sha256() {
30+
local asset_name="$1"
31+
local url="https://github.com/${CLI_REPO}/releases/download/v${VERSION}/${asset_name}"
32+
local tmp
33+
tmp="$(mktemp)"
34+
echo "Downloading ${asset_name}..." >&2
35+
curl -fsSL "$url" -o "$tmp"
36+
if command -v sha256sum > /dev/null 2>&1; then
37+
sha256sum "$tmp" | awk '{print $1}'
38+
else
39+
shasum -a 256 "$tmp" | awk '{print $1}'
40+
fi
41+
rm -f "$tmp"
42+
}
43+
44+
echo "Computing SHA256 hashes for v${VERSION}..."
45+
46+
SHA_DARWIN_ARM64="$(compute_sha256 "tigris-darwin-arm64.tar.gz")"
47+
SHA_DARWIN_X64="$(compute_sha256 "tigris-darwin-x64.tar.gz")"
48+
SHA_LINUX_ARM64="$(compute_sha256 "tigris-linux-arm64.tar.gz")"
49+
SHA_LINUX_X64="$(compute_sha256 "tigris-linux-x64.tar.gz")"
50+
51+
echo " darwin-arm64: ${SHA_DARWIN_ARM64}"
52+
echo " darwin-x64: ${SHA_DARWIN_X64}"
53+
echo " linux-arm64: ${SHA_LINUX_ARM64}"
54+
echo " linux-x64: ${SHA_LINUX_X64}"
55+
56+
# Generate the formula from the template
57+
FORMULA="$(sed \
58+
-e "s/VERSION_PLACEHOLDER/${VERSION}/g" \
59+
-e "s/SHA_DARWIN_ARM64_PLACEHOLDER/${SHA_DARWIN_ARM64}/g" \
60+
-e "s/SHA_DARWIN_X64_PLACEHOLDER/${SHA_DARWIN_X64}/g" \
61+
-e "s/SHA_LINUX_ARM64_PLACEHOLDER/${SHA_LINUX_ARM64}/g" \
62+
-e "s/SHA_LINUX_X64_PLACEHOLDER/${SHA_LINUX_X64}/g" \
63+
"$TEMPLATE")"
64+
65+
echo ""
66+
echo "Generated formula:"
67+
echo "---"
68+
echo "$FORMULA"
69+
echo "---"
70+
71+
# Clone the tap repo, update the formula, and push
72+
TMP_DIR="$(mktemp -d)"
73+
trap 'rm -rf "$TMP_DIR"' EXIT
74+
75+
CLONE_URL="https://github.com/${TAP_REPO}.git"
76+
if [ -n "${HOMEBREW_TAP_TOKEN:-}" ]; then
77+
CLONE_URL="https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/${TAP_REPO}.git"
78+
fi
79+
80+
BRANCH="update-tigris-${VERSION}"
81+
82+
echo ""
83+
echo "Cloning ${TAP_REPO}..."
84+
git clone --depth 1 "$CLONE_URL" "$TMP_DIR/tap"
85+
86+
cd "$TMP_DIR/tap"
87+
88+
mkdir -p Formula
89+
echo "$FORMULA" > Formula/tigris.rb
90+
91+
git add Formula/tigris.rb
92+
93+
if git diff --cached --quiet; then
94+
echo "Formula is already up to date."
95+
exit 0
96+
fi
97+
98+
git checkout -b "$BRANCH"
99+
git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \
100+
commit -m "tigris ${VERSION}"
101+
git push origin "$BRANCH"
102+
103+
echo ""
104+
echo "Creating pull request..."
105+
GH_TOKEN="${HOMEBREW_TAP_TOKEN:-}" gh pr create \
106+
--repo "$TAP_REPO" \
107+
--base main \
108+
--head "$BRANCH" \
109+
--title "tigris ${VERSION}" \
110+
--body "Update Tigris CLI formula to [v${VERSION}](https://github.com/${CLI_REPO}/releases/tag/v${VERSION})." \
111+
--label "automated"
112+
113+
echo ""
114+
echo "Pull request created for v${VERSION}"

src/utils/update-check.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execSync } from 'child_process';
12
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
23
import https from 'https';
34
import { homedir } from 'os';
@@ -92,6 +93,16 @@ export function isNewerVersion(current: string, latest: string): boolean {
9293
return false;
9394
}
9495

96+
function isHomebrewInstall(): boolean {
97+
if (process.platform === 'win32') return false;
98+
try {
99+
execSync('brew list tigris', { stdio: 'ignore' });
100+
return true;
101+
} catch {
102+
return false;
103+
}
104+
}
105+
95106
/**
96107
* Returns the platform-appropriate shell command for updating the CLI.
97108
*/
@@ -102,6 +113,8 @@ export function getUpdateCommand(): string {
102113

103114
if (!isBinary) {
104115
return 'npm install -g @tigrisdata/cli';
116+
} else if (isHomebrewInstall()) {
117+
return 'brew upgrade tigris';
105118
} else if (isWindows) {
106119
return 'irm https://raw.githubusercontent.com/tigrisdata/cli/main/scripts/install.ps1 | iex';
107120
} else {

0 commit comments

Comments
 (0)