Skip to content

Commit

Permalink
update download_cli script and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
salman1993 committed Jan 17, 2025
1 parent 3697d71 commit 1390d19
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 43 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,22 @@ jobs:
name: goose-${{ matrix.architecture }}-${{ matrix.target-suffix }}
path: ${{ env.ARTIFACT }}

# ------------------------------------
# 2) Upload Install CLI Script (we only need to do this once)
# ------------------------------------
install-script:
name: Upload Install Script
runs-on: ubuntu-latest
needs: [ build-cli ]
steps:
- uses: actions/checkout@v4
- uses: actions/upload-artifact@v4
with:
name: install-cli.sh
path: install-cli.sh

# ------------------------------------------------------------
# 2) Bundle Desktop App (macOS only) - builds goosed and Electron app
# 3) Bundle Desktop App (macOS only) - builds goosed and Electron app
# ------------------------------------------------------------
bundle-desktop:
# Only run on macOS
Expand Down Expand Up @@ -195,12 +209,12 @@ jobs:
pkill -f "Goose.app/Contents/MacOS/Goose"
# ------------------------------------
# 3) Create/Update GitHub Release
# 4) Create/Update GitHub Release
# ------------------------------------
release:
name: Release
runs-on: ubuntu-latest
needs: [ build-cli, bundle-desktop ]
needs: [ build-cli, install-script, bundle-desktop ]
permissions:
contents: write

Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,22 @@ jobs:
name: goose-${{ matrix.architecture }}-${{ matrix.target-suffix }}
path: ${{ env.ARTIFACT }}

# ------------------------------------
# 2) Upload Install CLI Script (we only need to do this once)
# ------------------------------------
install-script:
name: Upload Install Script
runs-on: ubuntu-latest
needs: [ build-cli ]
steps:
- uses: actions/checkout@v4
- uses: actions/upload-artifact@v4
with:
name: install-cli.sh
path: install-cli.sh

# ------------------------------------------------------------
# 2) Bundle Desktop App (macOS only) - builds goosed and Electron app
# 3) Bundle Desktop App (macOS only) - builds goosed and Electron app
# ------------------------------------------------------------
bundle-desktop:
# Only run on macOS
Expand Down Expand Up @@ -191,12 +205,12 @@ jobs:
pkill -f "Goose.app/Contents/MacOS/Goose"
# ------------------------------------
# 3) Create/Update GitHub Release
# 4) Create/Update GitHub Release
# ------------------------------------
release:
name: Release
runs-on: ubuntu-latest
needs: [ build-cli, bundle-desktop ]
needs: [ build-cli, install-script, bundle-desktop ]
permissions:
contents: write

Expand Down
125 changes: 88 additions & 37 deletions download_cli.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,75 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
set -euo pipefail

##############################################################################
# Goose CLI Install Script
#
# This script downloads the latest 'goose' CLI binary from GitHub releases
# and installs it to your system.
#
# Supported OS: macOS (darwin), Linux
# Supported Architectures: x86_64, arm64
#
# Usage:
# curl -sSL https://raw.githubusercontent.com/block/goose/main/install.sh | bash
#
# Environment variables:
# GOOSE_BIN_DIR - Directory to which Goose will be installed (default: $HOME/.local/bin)
# GOOSE_PROVIDER - Optional: provider for goose (passed to "goose configure")
# GOOSE_MODEL - Optional: model for goose (passed to "goose configure")
##############################################################################

# --- 1) Check for curl ---
if ! command -v curl >/dev/null 2>&1; then
echo "Error: 'curl' is required to download Goose. Please install curl and try again."
exit 1
fi

# --- 2) Variables ---
REPO="block/goose"
OUT_FILE="goose"
GITHUB_API_ENDPOINT="api.github.com"
GOOSE_BIN_DIR="${GOOSE_BIN_DIR:-"$HOME/.local/bin"}"

function gh_curl() {
curl -sL -H "Accept: application/vnd.github.v3.raw" $@
# Helper function to fetch JSON from GitHub
gh_curl() {
curl -sL -H "Accept: application/vnd.github.v3.raw" "$@"
}

# Determine the operating system and architecture
OS=$(uname | tr '[:upper:]' '[:lower:]')
# --- 3) Detect OS/Architecture ---
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case "$OS" in
linux|darwin) ;;
*)
echo "Error: Unsupported OS '$OS'. Goose only supports Linux and macOS."
exit 1
;;
esac

case "$ARCH" in
x86_64)
ARCH="x86_64"
;;
arm64)
arm64|aarch64)
# Some systems use 'arm64' and some 'aarch64' – standardize to 'aarch64'
ARCH="aarch64"
;;
*)
echo "ERROR: Unsupported architecture: $ARCH"
echo "Error: Unsupported architecture '$ARCH'."
exit 1
;;
esac

FILE="goose-$ARCH-unknown-linux-gnu.tar.bz2"
# Build the filename we expect in the release assets
if [ "$OS" = "darwin" ]; then
FILE="goose-$ARCH-apple-darwin.tar.bz2"
else
FILE="goose-$ARCH-unknown-linux-gnu.tar.bz2"
fi

# Find the goose binary asset id
# --- 4) Fetch GitHub Releases and locate the correct asset ID ---
echo "Looking up the most recent goose binary release..."
echo ""
RELEASES=$(gh_curl https://$GITHUB_API_ENDPOINT/repos/$REPO/releases)
Expand All @@ -52,31 +90,45 @@ ASSET_ID=$(echo "$RELEASES" | awk -v file="$FILE" '
')

if [ -z "$ASSET_ID" ]; then
echo "ERROR: $FILE asset not found"
echo "Error: Could not find a release asset named '$FILE' in the latest releases."
exit 1
fi

# Download the goose binary
# --- 5) Download & extract 'goose' binary ---
echo "Downloading $FILE..."
echo ""
curl -sL --header 'Accept: application/octet-stream' https://$GITHUB_API_ENDPOINT/repos/$REPO/releases/assets/$ASSET_ID > $FILE
tar -xjf $FILE
echo "Cleaning up $FILE..."
rm $FILE
chmod +x goose goosed

LOCAL_BIN="$HOME/.local/bin"
if [ ! -d "$LOCAL_BIN" ]; then
echo "Directory $LOCAL_BIN does not exist. Creating it now..."
mkdir -p "$LOCAL_BIN"
echo "Directory $LOCAL_BIN created successfully."
curl -sL --header 'Accept: application/octet-stream' \
"https://$GITHUB_API_ENDPOINT/repos/$REPO/releases/assets/$ASSET_ID" \
--output "$FILE"

echo "Extracting $FILE..."
tar -xjf "$FILE"

echo "Cleaning up..."
rm "$FILE"

# Make binaries executable
chmod +x goose

# --- 6) Install to $GOOSE_BIN_DIR ---
if [ ! -d "$GOOSE_BIN_DIR" ]; then
echo "Creating directory: $GOOSE_BIN_DIR"
mkdir -p "$GOOSE_BIN_DIR"
fi

echo "Moving goose to $GOOSE_BIN_DIR/$OUT_FILE"
mv goose "$GOOSE_BIN_DIR/$OUT_FILE"


# --- 7) Check PATH and give instructions if needed ---
if [[ ":$PATH:" != *":$GOOSE_BIN_DIR:"* ]]; then
echo ""
echo "Warning: $GOOSE_BIN_DIR is not in your PATH."
echo "Add it to your PATH by editing ~/.bashrc, ~/.zshrc, or similar:"
echo " export PATH=\"$GOOSE_BIN_DIR:\$PATH\""
echo "Then reload your shell (e.g. 'source ~/.bashrc', 'source ~/.zshrc') to apply changes."
echo ""
fi

echo "Sending goose to $LOCAL_BIN/$OUT_FILE"
echo ""
mv goose $LOCAL_BIN/$OUT_FILE
mv goosed $LOCAL_BIN

# Check if the directory is in the PATH
if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then
Expand All @@ -87,23 +139,22 @@ if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then
echo ""
echo "Then reload your shell configuration file by running:"
echo ""
echo " source ~/.bashrc # or source ~/.zshrc"
echo " source ~/.bashrc # or "
fi

# Initialize config args with the default name
CONFIG_ARGS="-n default"

# Check for GOOSE_PROVIDER environment variable
# --- 8) Auto-configure Goose (Optional) ---
CONFIG_ARGS="-n default"
if [ -n "${GOOSE_PROVIDER:-}" ]; then
CONFIG_ARGS="$CONFIG_ARGS -p $GOOSE_PROVIDER"
CONFIG_ARGS="$CONFIG_ARGS -p $GOOSE_PROVIDER"
fi

# Check for GOOSE_MODEL environment variable
if [ -n "${GOOSE_MODEL:-}" ]; then
CONFIG_ARGS="$CONFIG_ARGS -m $GOOSE_MODEL"
CONFIG_ARGS="$CONFIG_ARGS -m $GOOSE_MODEL"
fi

$LOCAL_BIN/$OUT_FILE configure $CONFIG_ARGS
echo "Configuring Goose with: '$CONFIG_ARGS'"
"$GOOSE_BIN_DIR/$OUT_FILE" configure $CONFIG_ARGS

echo ""
echo "You can now run Goose using: $OUT_FILE session"
echo "Goose installed successfully! Run '$OUT_FILE session' to get started."
echo ""

0 comments on commit 1390d19

Please sign in to comment.