diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index d26d13d08..4bb7b4fd5 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -5,10 +5,14 @@ on: paths: - 'install-cli.sh' - '.github/workflows/install-script-tests.yml' + - 'bin/test_install_script.sh' + - 'bin/test_install_script_over_homebrew.sh' pull_request: paths: - 'install-cli.sh' - '.github/workflows/install-script-tests.yml' + - 'bin/test_install_script.sh' + - 'bin/test_install_script_over_homebrew.sh' workflow_dispatch: jobs: @@ -23,10 +27,30 @@ jobs: - name: Checkout repository uses: actions/checkout@v5 - - name: Run install script + - name: Run install script test shell: bash - run: bash install-cli.sh --debug --token ${{ secrets.GITHUB_TOKEN }} + run: | + chmod +x install-cli.sh + bash bin/test_install_script.sh --token ${{ secrets.GITHUB_TOKEN }} - - name: Verify installation + mac-homebrew: + name: Test Homebrew Installation on macOS + runs-on: macos-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Run Homebrew install + shell: bash + run: brew install kosli-cli + + - name: Verify Homebrew installation + shell: bash + run: command -v kosli + + - name: Run install script test shell: bash - run: kosli version \ No newline at end of file + run: | + chmod +x install-cli.sh + bash bin/test_install_script_over_homebrew.sh --token ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/bin/test_install_script.sh b/bin/test_install_script.sh new file mode 100755 index 000000000..5ab659efd --- /dev/null +++ b/bin/test_install_script.sh @@ -0,0 +1,88 @@ +#!/bin/bash +set -e + +# --- Configuration --- +TOKEN="" + +# Parse arguments for the test script itself, primarily to pass --token +while [[ "$#" -gt 0 ]]; do + case $1 in + --token) + if [[ -n "$2" && "$2" != --* ]]; then + TOKEN="$2" + shift + else + echo "Error: --token requires a value" + exit 1 + fi + ;; + *) echo "Unknown parameter: $1"; exit 1 ;; + esac + shift +done + +# Helper to construct command +run_install() { + local cmd="./install-cli.sh" + if [ -n "$TOKEN" ]; then + cmd="$cmd --token $TOKEN" + fi + # Add other arguments passed to function + cmd="$cmd $@" + echo "Running: $cmd" + $cmd +} + +# Colors for output +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +log_info() { + echo -e "${GREEN}[INFO] $1${NC}" +} + +log_error() { + echo -e "${RED}[ERROR] $1${NC}" +} + + +# Test 1: Install specific version +SPECIFIC_VERSION="v2.11.40" +log_info "Test 1: Installing specific version ${SPECIFIC_VERSION}..." + +# We pass --version as requested by the user +run_install --version "${SPECIFIC_VERSION}" --debug + +if ! command -v kosli &> /dev/null; then + log_error "Kosli CLI not found after installation" + exit 1 +fi + +INSTALLED_VERSION=$(kosli version | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+") +log_info "Installed version: ${INSTALLED_VERSION}" + +if [[ "${INSTALLED_VERSION}" == "${SPECIFIC_VERSION}" ]]; then + log_info "✅ Specific version installed successfully" +else + log_info "Expected ${SPECIFIC_VERSION}, got ${INSTALLED_VERSION}" + log_error "❌ Version mismatch" + exit 1 +fi + +# Test 2: Upgrade to latest version +log_info "Test 2: Upgrading to latest version..." +run_install --debug + +LATEST_INSTALLED_VERSION=$(kosli version | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+") +log_info "Installed version after update: ${LATEST_INSTALLED_VERSION}" + +# Simple check to ensure version changed (assuming latest > specific) +if [[ "${LATEST_INSTALLED_VERSION}" != "${SPECIFIC_VERSION}" ]]; then + log_info "✅ Version updated successfully (from ${SPECIFIC_VERSION} to ${LATEST_INSTALLED_VERSION})" +else + log_error "❌ Version did not update" + exit 1 +fi + +log_info "🎉 All installation tests passed!" diff --git a/bin/test_install_script_over_homebrew.sh b/bin/test_install_script_over_homebrew.sh new file mode 100755 index 000000000..b8730596c --- /dev/null +++ b/bin/test_install_script_over_homebrew.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Note: set -e is intentionally omitted here to allow manual exit code checking. + +# --- Configuration --- +TOKEN="" + +# Parse arguments for the test script itself, primarily to pass --token +while [[ "$#" -gt 0 ]]; do + case $1 in + --token) + if [[ -n "$2" && "$2" != --* ]]; then + TOKEN="$2" + shift + else + echo "Error: --token requires a value" + exit 1 + fi + ;; + *) echo "Unknown parameter: $1"; exit 1 ;; + esac + shift +done + +# Helper to construct command +run_install() { + local cmd="./install-cli.sh" + if [ -n "$TOKEN" ]; then + cmd="$cmd --token $TOKEN" + fi + # Add other arguments passed to function + cmd="$cmd $@" + echo "Running: $cmd" + $cmd +} + +# Run the install script +run_install + +# Capture the exit code of the install script +EXIT_CODE=$? + +# Check if the exit code is 1 (expected failure due to existing brew installation) +if [ $EXIT_CODE -eq 1 ]; then + echo "Success: install-cli.sh detected existing Homebrew installation and exited with 1." + exit 0 +else + echo "Failure: install-cli.sh did not exit with 1. Actual exit code: $EXIT_CODE" + exit 1 +fi diff --git a/install-cli.sh b/install-cli.sh old mode 100644 new mode 100755 index 36a5b70a4..2443f903e --- a/install-cli.sh +++ b/install-cli.sh @@ -11,6 +11,7 @@ VERSION="" FILE_NAME="kosli" DEBUG=false GITHUB_TOKEN="" +TARGET_INSTALL_DIR="" # --- Debug function --- debug_print() { @@ -45,6 +46,22 @@ while [ $# -gt 0 ]; do esac done +# --- Check existing installation --- +debug_print "Checking for existing Kosli installation" +if command -v kosli >/dev/null 2>&1; then + if command -v brew >/dev/null 2>&1 && brew list kosli-cli >/dev/null 2>&1; then + echo "Kosli was installed via Homebrew. Please use 'brew upgrade kosli-cli' instead." + exit 1 + fi + + EXISTING_KOSLI_PATH=$(command -v kosli) + debug_print "Existing Kosli found at: $EXISTING_KOSLI_PATH" + EXISTING_KOSLI_DIR=$(dirname "$EXISTING_KOSLI_PATH") + debug_print "Existing Kosli directory: $EXISTING_KOSLI_DIR" + + TARGET_INSTALL_DIR="$EXISTING_KOSLI_DIR" +fi + # --- Version Selection --- if [ -n "$VERSION" ]; then echo "Downloading specified version $VERSION of Kosli CLI..." @@ -177,8 +194,14 @@ echo "Installing Kosli CLI..." debug_print "Starting installation process" debug_print "Current PATH: $PATH" +if [ -n "$TARGET_INSTALL_DIR" ]; then + INSTALL_DIRS="$TARGET_INSTALL_DIR" +else + INSTALL_DIRS="/usr/local/bin /usr/bin /opt/bin" +fi + # Check directories one by one instead of using set -- -for dir in "/usr/local/bin" "/usr/bin" "/opt/bin"; do +for dir in $INSTALL_DIRS; do debug_print "Checking directory: $dir" # Check if destination directory exists and is in the PATH if [ -d "$dir" ] && echo "$PATH" | grep -q "$dir"; then