diff --git a/actions/setup-cli/install.sh b/actions/setup-cli/install.sh index 58d73c6805d..8b3d322f685 100755 --- a/actions/setup-cli/install.sh +++ b/actions/setup-cli/install.sh @@ -253,15 +253,28 @@ if [ "$TRY_GH_INSTALL" = true ] && command -v gh &> /dev/null; then # Verify the installation succeeded if gh aw version &> /dev/null; then INSTALLED_VERSION=$(gh aw version 2>&1 | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1) - print_success "Successfully installed gh-aw using gh extension install" - print_info "Installed version: $INSTALLED_VERSION" - # Set output for GitHub Actions - if [ -n "${GITHUB_OUTPUT}" ]; then - echo "installed_version=${INSTALLED_VERSION}" >> "${GITHUB_OUTPUT}" + # Ensure we could parse an installed version; empty means verification failed + if [ -z "$INSTALLED_VERSION" ]; then + print_warning "gh extension install completed but the installed gh-aw version could not be determined" + print_info "Falling back to manual installation..." + else + # Verify the installed version matches the requested version (if specific version was requested) + if [ "$VERSION" != "latest" ] && [ "$INSTALLED_VERSION" != "$VERSION" ]; then + print_warning "Version mismatch: requested $VERSION but gh extension install installed $INSTALLED_VERSION" + print_info "Falling back to manual installation to install the correct version..." + else + print_success "Successfully installed gh-aw using gh extension install" + print_info "Installed version: $INSTALLED_VERSION" + + # Set output for GitHub Actions + if [ -n "${GITHUB_OUTPUT}" ]; then + echo "installed_version=${INSTALLED_VERSION}" >> "${GITHUB_OUTPUT}" + fi + + exit 0 + fi fi - - exit 0 else print_warning "gh extension install completed but verification failed" print_info "Falling back to manual installation..." diff --git a/actions/setup-cli/install_test.sh b/actions/setup-cli/install_test.sh index d9773bee4a0..8a22eb09052 100755 --- a/actions/setup-cli/install_test.sh +++ b/actions/setup-cli/install_test.sh @@ -109,6 +109,20 @@ test_checksum_validation() { fi } +# Test 7: Verify version mismatch detection after gh extension install +test_version_mismatch_detection() { + echo "" + echo "Test 7: Verify version mismatch detection after gh extension install" + + # Check if script detects when installed version differs from requested version + if grep -q 'INSTALLED_VERSION.*!=.*VERSION' "$SCRIPT_PATH" && \ + grep -q 'Version mismatch' "$SCRIPT_PATH"; then + print_result "Script detects version mismatch after gh extension install" "PASS" + else + print_result "Script missing version mismatch detection (gh extension install may install wrong version)" "FAIL" + fi +} + # Run all tests echo "=========================================" echo "Testing setup-cli action install.sh" @@ -120,6 +134,7 @@ test_input_version test_gh_install test_version_pinning test_checksum_validation +test_version_mismatch_detection # Summary echo "" diff --git a/install-gh-aw.sh b/install-gh-aw.sh index 58d73c6805d..8b3d322f685 100755 --- a/install-gh-aw.sh +++ b/install-gh-aw.sh @@ -253,15 +253,28 @@ if [ "$TRY_GH_INSTALL" = true ] && command -v gh &> /dev/null; then # Verify the installation succeeded if gh aw version &> /dev/null; then INSTALLED_VERSION=$(gh aw version 2>&1 | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1) - print_success "Successfully installed gh-aw using gh extension install" - print_info "Installed version: $INSTALLED_VERSION" - # Set output for GitHub Actions - if [ -n "${GITHUB_OUTPUT}" ]; then - echo "installed_version=${INSTALLED_VERSION}" >> "${GITHUB_OUTPUT}" + # Ensure we could parse an installed version; empty means verification failed + if [ -z "$INSTALLED_VERSION" ]; then + print_warning "gh extension install completed but the installed gh-aw version could not be determined" + print_info "Falling back to manual installation..." + else + # Verify the installed version matches the requested version (if specific version was requested) + if [ "$VERSION" != "latest" ] && [ "$INSTALLED_VERSION" != "$VERSION" ]; then + print_warning "Version mismatch: requested $VERSION but gh extension install installed $INSTALLED_VERSION" + print_info "Falling back to manual installation to install the correct version..." + else + print_success "Successfully installed gh-aw using gh extension install" + print_info "Installed version: $INSTALLED_VERSION" + + # Set output for GitHub Actions + if [ -n "${GITHUB_OUTPUT}" ]; then + echo "installed_version=${INSTALLED_VERSION}" >> "${GITHUB_OUTPUT}" + fi + + exit 0 + fi fi - - exit 0 else print_warning "gh extension install completed but verification failed" print_info "Falling back to manual installation..."