From 41c7046688bf10086fe8088ef65ef0368239b0f8 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Fri, 27 Feb 2026 12:34:40 +0100 Subject: [PATCH 1/6] feat: add install script tests and enhance install-cli.sh for existing installations Add a scenario for breaking if kosli is installed with eg. homebrew in a different folder. --- .github/workflows/install-script-tests.yml | 36 ++++++++- bin/test_install_script.sh | 88 ++++++++++++++++++++++ bin/test_install_script_over_homebrew.sh | 16 ++++ install-cli.sh | 29 ++++++- 4 files changed, 164 insertions(+), 5 deletions(-) create mode 100755 bin/test_install_script.sh create mode 100755 bin/test_install_script_over_homebrew.sh mode change 100644 => 100755 install-cli.sh diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index d26d13d08..886ada237 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,34 @@ 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 - - name: Verify installation + mac-homebrew: + name: Test Homebrew Installation on macOS + runs-on: macos-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + - name: install homebrew + shell: bash + run: | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + - 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 \ 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..6fe8a3e01 --- /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..1ad1623aa --- /dev/null +++ b/bin/test_install_script_over_homebrew.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Attempt to run the install script +./install-cli.sh + +# 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..5028abce6 --- 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,26 @@ 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 + 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" + + case "$EXISTING_KOSLI_DIR" in + "/usr/local/bin" | "/usr/bin" | "/opt/bin") + TARGET_INSTALL_DIR="$EXISTING_KOSLI_DIR" + debug_print "Found existing Kosli installation in standard location: $TARGET_INSTALL_DIR" + ;; + *) + echo "Kosli found but was installed in another way in $EXISTING_KOSLI_PATH. Please uninstall before running this script to avoid multiple versions present" + exit 1 + ;; + esac +fi + # --- Version Selection --- if [ -n "$VERSION" ]; then echo "Downloading specified version $VERSION of Kosli CLI..." @@ -177,8 +198,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 From 3b94dd784fed0dcd8be66d563cd82f429add79dc Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Tue, 3 Mar 2026 22:06:34 +0100 Subject: [PATCH 2/6] refactor: remove Homebrew installation step from install script tests --- .github/workflows/install-script-tests.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index 886ada237..89fa3d396 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -40,10 +40,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v5 - - name: install homebrew - shell: bash - run: | - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - name: Run Homebrew install shell: bash From 7c2dbb0716342f3ae4f9721911cb4389f771ba3e Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Tue, 3 Mar 2026 22:12:10 +0100 Subject: [PATCH 3/6] fix: improve existing installation check for Kosli CLI and handle Homebrew installations --- install-cli.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/install-cli.sh b/install-cli.sh index 5028abce6..346198566 100755 --- a/install-cli.sh +++ b/install-cli.sh @@ -49,21 +49,18 @@ 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" - case "$EXISTING_KOSLI_DIR" in - "/usr/local/bin" | "/usr/bin" | "/opt/bin") - TARGET_INSTALL_DIR="$EXISTING_KOSLI_DIR" - debug_print "Found existing Kosli installation in standard location: $TARGET_INSTALL_DIR" - ;; - *) - echo "Kosli found but was installed in another way in $EXISTING_KOSLI_PATH. Please uninstall before running this script to avoid multiple versions present" - exit 1 - ;; - esac + TARGET_INSTALL_DIR="$EXISTING_KOSLI_DIR" + debug_print "Found existing Kosli installation in: $TARGET_INSTALL_DIR" fi # --- Version Selection --- From 1cc583687fc0e1ebaa4284d4b6c7d79e981d62e6 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Tue, 3 Mar 2026 22:14:01 +0100 Subject: [PATCH 4/6] fix: remove debug print for existing Kosli installation path --- install-cli.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install-cli.sh b/install-cli.sh index 346198566..2443f903e 100755 --- a/install-cli.sh +++ b/install-cli.sh @@ -60,7 +60,6 @@ if command -v kosli >/dev/null 2>&1; then debug_print "Existing Kosli directory: $EXISTING_KOSLI_DIR" TARGET_INSTALL_DIR="$EXISTING_KOSLI_DIR" - debug_print "Found existing Kosli installation in: $TARGET_INSTALL_DIR" fi # --- Version Selection --- From 3a66bf3e2f301aca2cef12eb387b933e751ee6c0 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Tue, 3 Mar 2026 22:16:17 +0100 Subject: [PATCH 5/6] fix: format and improve token parsing in test_install_script.sh --- bin/test_install_script.sh | 16 ++++++++-------- bin/test_install_script_over_homebrew.sh | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/test_install_script.sh b/bin/test_install_script.sh index 6fe8a3e01..5ab659efd 100755 --- a/bin/test_install_script.sh +++ b/bin/test_install_script.sh @@ -8,14 +8,14 @@ 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 - ;; + 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 diff --git a/bin/test_install_script_over_homebrew.sh b/bin/test_install_script_over_homebrew.sh index 1ad1623aa..491cf2d90 100755 --- a/bin/test_install_script_over_homebrew.sh +++ b/bin/test_install_script_over_homebrew.sh @@ -1,5 +1,7 @@ #!/bin/bash +# Note: set -e is intentionally omitted here to allow manual exit code checking. + # Attempt to run the install script ./install-cli.sh From 93b8700a240593bc8f235d8e065c24f2913e5beb Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Tue, 3 Mar 2026 22:20:06 +0100 Subject: [PATCH 6/6] feat: add token support to install script tests for improved authentication --- .github/workflows/install-script-tests.yml | 4 +-- bin/test_install_script_over_homebrew.sh | 36 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/.github/workflows/install-script-tests.yml b/.github/workflows/install-script-tests.yml index 89fa3d396..4bb7b4fd5 100644 --- a/.github/workflows/install-script-tests.yml +++ b/.github/workflows/install-script-tests.yml @@ -31,7 +31,7 @@ jobs: shell: bash run: | chmod +x install-cli.sh - bash bin/test_install_script.sh + bash bin/test_install_script.sh --token ${{ secrets.GITHUB_TOKEN }} mac-homebrew: name: Test Homebrew Installation on macOS @@ -53,4 +53,4 @@ jobs: shell: bash run: | chmod +x install-cli.sh - bash bin/test_install_script_over_homebrew.sh \ No newline at end of file + 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_over_homebrew.sh b/bin/test_install_script_over_homebrew.sh index 491cf2d90..b8730596c 100755 --- a/bin/test_install_script_over_homebrew.sh +++ b/bin/test_install_script_over_homebrew.sh @@ -2,8 +2,40 @@ # Note: set -e is intentionally omitted here to allow manual exit code checking. -# Attempt to run the install script -./install-cli.sh +# --- 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=$?