Skip to content

Commit 96e712d

Browse files
Copilotlunarcloud
andauthored
Fix tput failures in CI/CD environments (#34)
* Initial plan * Fix tput failures in CI/CD environments Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> * Add CI/CD compatibility test to prevent future regressions Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
1 parent cbde33d commit 96e712d

4 files changed

Lines changed: 102 additions & 14 deletions

File tree

.github/workflows/analyze.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ jobs:
1818
- name: 'Analyzing Code Quality'
1919
run: shellcheck ./*.sh extras/*.sh -x
2020

21+
- name: 'Testing CI/CD Compatibility'
22+
run: bash extras/test-ci-compatibility.sh
23+

extras/test-ci-compatibility.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
# CI/CD compatibility test for script-dialog library
3+
# Tests that the library can be sourced without errors in headless environments
4+
5+
set -e # Exit on any error
6+
7+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8+
EXIT_CODE=0
9+
10+
echo "Testing CI/CD compatibility..."
11+
echo ""
12+
13+
# Test 1: With TERM=dumb (common in CI environments)
14+
echo "Test 1: TERM=dumb (common in CI)"
15+
export TERM=dumb
16+
# shellcheck source=../script-dialog.sh
17+
# shellcheck disable=SC1091 # Source file path is constructed at runtime
18+
if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then
19+
if echo "$output" | grep -iq "tput.*error\|no value for"; then
20+
echo " ✗ FAILED: tput errors detected in output"
21+
echo "$output"
22+
EXIT_CODE=1
23+
else
24+
echo " ✓ PASSED: Library loaded without tput errors"
25+
fi
26+
else
27+
echo " ✗ FAILED: Library failed to source"
28+
EXIT_CODE=1
29+
fi
30+
31+
# Clean up for next test
32+
unset INTERFACE bold red yellow normal underline
33+
34+
# Test 2: With TERM unset (also common in CI)
35+
echo "Test 2: TERM unset"
36+
unset TERM
37+
# shellcheck source=../script-dialog.sh
38+
# shellcheck disable=SC1091 # Source file path is constructed at runtime
39+
if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then
40+
if echo "$output" | grep -iq "tput.*error\|no value for"; then
41+
echo " ✗ FAILED: tput errors detected in output"
42+
echo "$output"
43+
EXIT_CODE=1
44+
else
45+
echo " ✓ PASSED: Library loaded without tput errors"
46+
fi
47+
else
48+
echo " ✗ FAILED: Library failed to source"
49+
EXIT_CODE=1
50+
fi
51+
52+
# Clean up for next test
53+
unset INTERFACE bold red yellow normal underline
54+
55+
# Test 3: With normal TERM (ensure we didn't break normal usage)
56+
echo "Test 3: TERM=xterm-256color (normal usage)"
57+
export TERM=xterm-256color
58+
# shellcheck source=../script-dialog.sh
59+
# shellcheck disable=SC1091 # Source file path is constructed at runtime
60+
if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then
61+
if echo "$output" | grep -iq "error"; then
62+
echo " ✗ FAILED: Unexpected errors in output"
63+
echo "$output"
64+
EXIT_CODE=1
65+
else
66+
echo " ✓ PASSED: Library loaded successfully"
67+
fi
68+
else
69+
echo " ✗ FAILED: Library failed to source"
70+
EXIT_CODE=1
71+
fi
72+
73+
echo ""
74+
if [ $EXIT_CODE -eq 0 ]; then
75+
echo "All CI/CD compatibility tests passed ✓"
76+
else
77+
echo "Some CI/CD compatibility tests failed ✗"
78+
fi
79+
80+
exit $EXIT_CODE

helpers.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ function _calculate-gui-title() {
7676
# n/a
7777
#######################################
7878
function _calculate-tui-max() {
79-
if ! command -v >/dev/null tput; then
79+
if ! command -v tput >/dev/null 2>&1; then
8080
return;
8181
fi
8282

8383
if [ "$GUI" == "false" ] ; then
84-
MAX_LINES=$(tput lines)
85-
MAX_COLS=$(tput cols)
84+
MAX_LINES=$(tput lines 2>/dev/null)
85+
MAX_COLS=$(tput cols 2>/dev/null)
8686
fi
8787

8888
# Never really fill the whole screen space

init.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,23 @@ XDG_ICO_CALENDAR="x-office-calendar"
188188
XDG_ICO_DOCUMENT="x-office-document"
189189

190190
# see if it supports colors...
191-
ncolors=$(tput colors)
191+
if command -v tput >/dev/null 2>&1; then
192+
ncolors=$(tput colors 2>/dev/null)
193+
else
194+
ncolors=""
195+
fi
196+
192197
if [ "$NOCOLORS" == "" ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
193-
bold="$(tput bold)"
194-
underline="$(tput smul)"
195-
#standout="$(tput smso)"
196-
normal="$(tput sgr0)"
197-
red="$(tput setaf 1)"
198-
#green="$(tput setaf 2)"
199-
yellow="$(tput setaf 3)"
200-
#blue="$(tput setaf 4)"
201-
#magenta="$(tput setaf 5)"
202-
#cyan="$(tput setaf 6)"
198+
bold="$(tput bold 2>/dev/null)"
199+
underline="$(tput smul 2>/dev/null)"
200+
#standout="$(tput smso 2>/dev/null)"
201+
normal="$(tput sgr0 2>/dev/null)"
202+
red="$(tput setaf 1 2>/dev/null)"
203+
#green="$(tput setaf 2 2>/dev/null)"
204+
yellow="$(tput setaf 3 2>/dev/null)"
205+
#blue="$(tput setaf 4 2>/dev/null)"
206+
#magenta="$(tput setaf 5 2>/dev/null)"
207+
#cyan="$(tput setaf 6 2>/dev/null)"
203208
else
204209
bold=""
205210
underline=""

0 commit comments

Comments
 (0)