Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions .github/workflows/cli-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,121 @@ jobs:
path: |
${{ matrix.os == 'windows-latest' && 'src/client/acontext-cli/acontext-cli.exe' || 'src/client/acontext-cli/acontext-cli' }}

test-install-script:
name: Test Install Script on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: src/client/acontext-cli
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
go-version-file: src/client/acontext-cli/go.mod
cache: true

- name: Test install script syntax
run: |
sh -n install.sh
echo "✓ Install script syntax is valid"

- name: Test install script help
run: |
sh install.sh --help

- name: Test platform detection logic
run: |
# Test that the script can detect the platform correctly
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
echo "Detected OS: $OS"
echo "Detected ARCH: $ARCH"

# Verify the script handles the platform correctly
case "$ARCH" in
x86_64)
EXPECTED_ARCH="amd64"
;;
aarch64|arm64)
EXPECTED_ARCH="arm64"
;;
*)
echo "✗ Unsupported architecture: $ARCH"
exit 1
;;
esac

case "$OS" in
linux|darwin)
echo "✓ Platform $OS/$EXPECTED_ARCH is supported"
;;
*)
echo "✗ Platform $OS is not supported"
exit 1
;;
esac

- name: Test dependency checks
run: |
# The script should check for curl/wget and tar/unzip
# These should be available on GitHub Actions runners
if command -v curl >/dev/null 2>&1 || command -v wget >/dev/null 2>&1; then
echo "✓ HTTP client (curl/wget) is available"
else
echo "✗ HTTP client is missing"
exit 1
fi

if command -v tar >/dev/null 2>&1 || command -v unzip >/dev/null 2>&1; then
echo "✓ Archive tool (tar/unzip) is available"
else
echo "✗ Archive tool is missing"
exit 1
fi

- name: Build test binary
run: |
go build -ldflags "-X main.version=dev" -o acontext-cli main.go
chmod +x acontext-cli
./acontext-cli version

- name: Test install script argument parsing
run: |
# Test that the script correctly parses --version argument
# We can't fully test installation without sudo, but we can test argument parsing
OUTPUT=$(sh install.sh --version dev 2>&1 || true)
if echo "$OUTPUT" | grep -q "Using specified version: vdev"; then
echo "✓ Install script correctly parses --version argument"
else
echo "✗ Install script failed to parse --version argument"
echo "Output: $OUTPUT"
exit 1
fi

- name: Test install script error handling
run: |
# Test that the script handles invalid arguments correctly
if sh install.sh --invalid-arg 2>&1 | grep -q "Unknown option"; then
echo "✓ Install script correctly handles invalid arguments"
else
echo "✗ Install script failed to handle invalid arguments"
exit 1
fi

# Test that --version without value shows error
if sh install.sh --version 2>&1 | grep -q "Version number required"; then
echo "✓ Install script correctly validates --version argument"
else
echo "✗ Install script failed to validate --version argument"
exit 1
fi

29 changes: 13 additions & 16 deletions src/client/acontext-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@

set -e

# Ensure we're running in bash for proper color support
if [ -z "$BASH_VERSION" ]; then
if command -v bash >/dev/null 2>&1; then
exec bash "$0" "$@"
fi
fi

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
Expand Down Expand Up @@ -75,12 +68,12 @@ detect_platform() {

# Check for required tools
check_dependencies() {
if ! command -v curl &> /dev/null && ! command -v wget &> /dev/null; then
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
print_error "curl or wget is required but not installed"
exit 1
fi

if ! command -v tar &> /dev/null && ! command -v unzip &> /dev/null; then
if ! command -v tar >/dev/null 2>&1 && ! command -v unzip >/dev/null 2>&1; then
print_error "tar or unzip is required but not installed"
exit 1
fi
Expand All @@ -95,10 +88,10 @@ get_latest_version() {

print_info "Fetching latest version..."

local api_url="https://api.github.com/repos/${REPO}/releases"
local version_json
api_url="https://api.github.com/repos/${REPO}/releases"
version_json=""

if command -v curl &> /dev/null; then
if command -v curl >/dev/null 2>&1; then
version_json=$(curl -fsSL "$api_url" 2>/dev/null)
else
version_json=$(wget -qO- "$api_url" 2>/dev/null)
Expand All @@ -120,13 +113,13 @@ download_binary() {
print_info "Downloading ${COMMAND_NAME}..." >&2

# URL format: https://github.com/memodb-io/Acontext/releases/download/cli%2Fv0.0.1/darwin_arm64.tar.gz
local encoded_version=$(echo "cli/${VERSION}" | sed 's/\//%2F/g')
encoded_version=$(echo "cli/${VERSION}" | sed 's/\//%2F/g')
URL="https://github.com/${REPO}/releases/download/${encoded_version}/${OS}_${ARCH}.tar.gz"

TEMP_DIR=$(mktemp -d)
TEMP_FILE="${TEMP_DIR}/${COMMAND_NAME}.tar.gz"

if command -v curl &> /dev/null; then
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "$TEMP_FILE" "$URL" || {
print_error "Failed to download from $URL" >&2
exit 1
Expand Down Expand Up @@ -189,7 +182,7 @@ install_binary() {

# Verify installation
verify_installation() {
if command -v "$COMMAND_NAME" &> /dev/null; then
if command -v "$COMMAND_NAME" >/dev/null 2>&1; then
print_success "Installation verified!"
echo
$COMMAND_NAME version 2>&1 || true
Expand Down Expand Up @@ -226,9 +219,13 @@ main() {
}

# Parse arguments
while [[ $# -gt 0 ]]; do
while [ $# -gt 0 ]; do
case $1 in
--version)
if [ -z "$2" ]; then
print_error "Version number required after --version"
exit 1
fi
VERSION="v$2"
shift 2
;;
Expand Down
Loading