diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index 91c9736..f70d390 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -18,3 +18,6 @@ jobs: - name: 'Analyzing Code Quality' run: shellcheck ./*.sh extras/*.sh -x + - name: 'Testing CI/CD Compatibility' + run: bash extras/test-ci-compatibility.sh + diff --git a/extras/test-ci-compatibility.sh b/extras/test-ci-compatibility.sh new file mode 100755 index 0000000..c5a3f23 --- /dev/null +++ b/extras/test-ci-compatibility.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# CI/CD compatibility test for script-dialog library +# Tests that the library can be sourced without errors in headless environments + +set -e # Exit on any error + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +EXIT_CODE=0 + +echo "Testing CI/CD compatibility..." +echo "" + +# Test 1: With TERM=dumb (common in CI environments) +echo "Test 1: TERM=dumb (common in CI)" +export TERM=dumb +# shellcheck source=../script-dialog.sh +# shellcheck disable=SC1091 # Source file path is constructed at runtime +if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then + if echo "$output" | grep -iq "tput.*error\|no value for"; then + echo " ✗ FAILED: tput errors detected in output" + echo "$output" + EXIT_CODE=1 + else + echo " ✓ PASSED: Library loaded without tput errors" + fi +else + echo " ✗ FAILED: Library failed to source" + EXIT_CODE=1 +fi + +# Clean up for next test +unset INTERFACE bold red yellow normal underline + +# Test 2: With TERM unset (also common in CI) +echo "Test 2: TERM unset" +unset TERM +# shellcheck source=../script-dialog.sh +# shellcheck disable=SC1091 # Source file path is constructed at runtime +if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then + if echo "$output" | grep -iq "tput.*error\|no value for"; then + echo " ✗ FAILED: tput errors detected in output" + echo "$output" + EXIT_CODE=1 + else + echo " ✓ PASSED: Library loaded without tput errors" + fi +else + echo " ✗ FAILED: Library failed to source" + EXIT_CODE=1 +fi + +# Clean up for next test +unset INTERFACE bold red yellow normal underline + +# Test 3: With normal TERM (ensure we didn't break normal usage) +echo "Test 3: TERM=xterm-256color (normal usage)" +export TERM=xterm-256color +# shellcheck source=../script-dialog.sh +# shellcheck disable=SC1091 # Source file path is constructed at runtime +if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then + if echo "$output" | grep -iq "error"; then + echo " ✗ FAILED: Unexpected errors in output" + echo "$output" + EXIT_CODE=1 + else + echo " ✓ PASSED: Library loaded successfully" + fi +else + echo " ✗ FAILED: Library failed to source" + EXIT_CODE=1 +fi + +echo "" +if [ $EXIT_CODE -eq 0 ]; then + echo "All CI/CD compatibility tests passed ✓" +else + echo "Some CI/CD compatibility tests failed ✗" +fi + +exit $EXIT_CODE diff --git a/helpers.sh b/helpers.sh index ad78794..3cbdf28 100644 --- a/helpers.sh +++ b/helpers.sh @@ -76,13 +76,13 @@ function _calculate-gui-title() { # n/a ####################################### function _calculate-tui-max() { - if ! command -v >/dev/null tput; then + if ! command -v tput >/dev/null 2>&1; then return; fi if [ "$GUI" == "false" ] ; then - MAX_LINES=$(tput lines) - MAX_COLS=$(tput cols) + MAX_LINES=$(tput lines 2>/dev/null) + MAX_COLS=$(tput cols 2>/dev/null) fi # Never really fill the whole screen space diff --git a/init.sh b/init.sh index ed885ec..d0304e0 100644 --- a/init.sh +++ b/init.sh @@ -188,18 +188,23 @@ XDG_ICO_CALENDAR="x-office-calendar" XDG_ICO_DOCUMENT="x-office-document" # see if it supports colors... -ncolors=$(tput colors) +if command -v tput >/dev/null 2>&1; then + ncolors=$(tput colors 2>/dev/null) +else + ncolors="" +fi + if [ "$NOCOLORS" == "" ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then - bold="$(tput bold)" - underline="$(tput smul)" - #standout="$(tput smso)" - normal="$(tput sgr0)" - red="$(tput setaf 1)" - #green="$(tput setaf 2)" - yellow="$(tput setaf 3)" - #blue="$(tput setaf 4)" - #magenta="$(tput setaf 5)" - #cyan="$(tput setaf 6)" + bold="$(tput bold 2>/dev/null)" + underline="$(tput smul 2>/dev/null)" + #standout="$(tput smso 2>/dev/null)" + normal="$(tput sgr0 2>/dev/null)" + red="$(tput setaf 1 2>/dev/null)" + #green="$(tput setaf 2 2>/dev/null)" + yellow="$(tput setaf 3 2>/dev/null)" + #blue="$(tput setaf 4 2>/dev/null)" + #magenta="$(tput setaf 5 2>/dev/null)" + #cyan="$(tput setaf 6 2>/dev/null)" else bold="" underline=""