diff --git a/actions/setup-cli/install.sh b/actions/setup-cli/install.sh index 1c6a0c2a9b2..d5488a9a7e2 100755 --- a/actions/setup-cli/install.sh +++ b/actions/setup-cli/install.sh @@ -1,6 +1,7 @@ #!/bin/bash set +o histexpand +# Kept in sync with ../../install-gh-aw.sh — edit that file, then copy here. # Script to download and install gh-aw binary for the current OS and architecture # Supports: Linux, macOS (Darwin), FreeBSD, Windows (Git Bash/MSYS/Cygwin) @@ -54,6 +55,17 @@ YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color +# Disable colors when output is captured or color is explicitly disabled. +# NO_COLOR is the no-color.org standard; NO_COLORS covers tools that use the non-standard variant. +# Per the spec, NO_COLOR disables colors even when set to an empty string, so we test with +set. +if [ -n "${CI:-}" ] || [ "${NO_COLOR+set}" = "set" ] || [ "${NO_COLORS+set}" = "set" ] || [ ! -t 1 ] || [ "${TERM:-}" = "dumb" ]; then + RED="" + GREEN="" + YELLOW="" + BLUE="" + NC="" +fi + # Function to print colored output print_info() { echo -e "${BLUE}[INFO]${NC} $1" diff --git a/actions/setup-cli/install_test.sh b/actions/setup-cli/install_test.sh index d758fc66b4d..de208ce04d2 100755 --- a/actions/setup-cli/install_test.sh +++ b/actions/setup-cli/install_test.sh @@ -125,6 +125,19 @@ test_version_mismatch_detection() { fi } +# Test 8: Verify no-color gate for CI environments +test_no_color_gate() { + echo "" + echo "Test 8: Verify no-color gate" + + if grep -q 'NO_COLOR+set' "$SCRIPT_PATH" && \ + grep -q 'RED=""' "$SCRIPT_PATH"; then + print_result "No-color gate present and spec-compliant" "PASS" + else + print_result "No-color gate missing or not spec-compliant" "FAIL" + fi +} + # Run all tests echo "=========================================" echo "Testing setup-cli action install.sh" @@ -137,6 +150,7 @@ test_gh_install test_version_pinning test_checksum_validation test_version_mismatch_detection +test_no_color_gate # Summary echo "" diff --git a/install-gh-aw.sh b/install-gh-aw.sh index 1c6a0c2a9b2..c7a5ed2ffed 100755 --- a/install-gh-aw.sh +++ b/install-gh-aw.sh @@ -1,6 +1,7 @@ #!/bin/bash set +o histexpand +# Kept in sync with actions/setup-cli/install.sh — edit this file, then copy to that path. # Script to download and install gh-aw binary for the current OS and architecture # Supports: Linux, macOS (Darwin), FreeBSD, Windows (Git Bash/MSYS/Cygwin) @@ -54,6 +55,17 @@ YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color +# Disable colors when output is captured or color is explicitly disabled. +# NO_COLOR is the no-color.org standard; NO_COLORS covers tools that use the non-standard variant. +# Per the spec, NO_COLOR disables colors even when set to an empty string, so we test with +set. +if [ -n "${CI:-}" ] || [ "${NO_COLOR+set}" = "set" ] || [ "${NO_COLORS+set}" = "set" ] || [ ! -t 1 ] || [ "${TERM:-}" = "dumb" ]; then + RED="" + GREEN="" + YELLOW="" + BLUE="" + NC="" +fi + # Function to print colored output print_info() { echo -e "${BLUE}[INFO]${NC} $1" diff --git a/scripts/test-install-script.sh b/scripts/test-install-script.sh index 2998084ed2d..3db7346d869 100755 --- a/scripts/test-install-script.sh +++ b/scripts/test-install-script.sh @@ -331,5 +331,16 @@ else exit 1 fi +# Test 12: Verify no-color gate for CI environments +echo "" +echo "Test 12: Verify no-color gate" +if grep -q 'NO_COLOR+set' "$PROJECT_ROOT/install-gh-aw.sh" && \ + grep -q 'RED=""' "$PROJECT_ROOT/install-gh-aw.sh"; then + echo " ✓ PASS: No-color gate present and spec-compliant" +else + echo " ✗ FAIL: No-color gate missing or not spec-compliant" + exit 1 +fi + echo "" echo "=== All tests passed ==="