Skip to content

Commit 22e2dc6

Browse files
committed
multi-arch-test-build: add generic version tests
Colorize output using ci_helpers.sh Signed-off-by: George Sapkin <[email protected]>
1 parent ee813b4 commit 22e2dc6

File tree

1 file changed

+74
-20
lines changed

1 file changed

+74
-20
lines changed

.github/scripts/test_entrypoint.sh

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if [ $PKG_MANAGER = "opkg" ]; then
1414
cp /ci/packages_ci.pub "/etc/opkg/keys/$FINGERPRINT"
1515

1616
opkg update
17+
1718
elif [ $PKG_MANAGER = "apk" ]; then
1819
echo "/ci/packages.adb" >> /etc/apk/repositories.d/distfeeds.list
1920

@@ -24,6 +25,8 @@ fi
2425

2526
CI_HELPERS="${CI_HELPERS:-/scripts/ci_helpers.sh}"
2627

28+
source "$CI_HELPERS"
29+
2730
for PKG in /ci/*.[ai]pk; do
2831
if [ $PKG_MANAGER = "opkg" ]; then
2932
tar -xzOf "$PKG" ./control.tar.gz | tar xzf - ./control
@@ -35,6 +38,7 @@ for PKG in /ci/*.[ai]pk; do
3538
# package source containing test.sh script
3639
PKG_SOURCE=$(sed -ne 's#^Source: \(.*\)$#\1#p' ./control)
3740
PKG_SOURCE="${PKG_SOURCE#/feed/}"
41+
3842
elif [ $PKG_MANAGER = "apk" ]; then
3943
# package name including variant
4044
PKG_NAME=$(apk adbdump --format json "$PKG" | jsonfilter -e '@["info"]["name"]')
@@ -47,33 +51,27 @@ for PKG in /ci/*.[ai]pk; do
4751
fi
4852

4953
echo
50-
echo "Testing package $PKG_NAME in version $PKG_VERSION from $PKG_SOURCE"
54+
info "Testing package $PKG_NAME with version $PKG_VERSION from $PKG_SOURCE"
5155

5256
if ! [ -d "/ci/$PKG_SOURCE" ]; then
53-
echo "$PKG_SOURCE is not a directory"
54-
exit 1
57+
err_die "$PKG_SOURCE is not a directory"
5558
fi
5659

5760
PRE_TEST_SCRIPT="/ci/$PKG_SOURCE/pre-test.sh"
5861
TEST_SCRIPT="/ci/$PKG_SOURCE/test.sh"
5962

60-
if ! [ -f "$TEST_SCRIPT" ]; then
61-
echo "No test.sh script available"
62-
continue
63-
fi
64-
6563
export PKG_NAME PKG_VERSION CI_HELPERS
6664

6765
if [ -f "$PRE_TEST_SCRIPT" ]; then
68-
echo "Use package specific pre-test.sh"
66+
info "Use the package-specific pre-test.sh"
6967
if sh "$PRE_TEST_SCRIPT" "$PKG_NAME" "$PKG_VERSION"; then
70-
echo "Pre-test successful"
68+
success "Pre-test successful"
7169
else
72-
echo "Pre-test failed"
73-
exit 1
70+
err_die "Pre-test failed"
7471
fi
72+
7573
else
76-
echo "No pre-test.sh script available"
74+
info "No pre-test.sh script available"
7775
fi
7876

7977
if [ $PKG_MANAGER = "opkg" ]; then
@@ -82,17 +80,73 @@ for PKG in /ci/*.[ai]pk; do
8280
apk add --allow-untrusted "$PKG"
8381
fi
8482

85-
echo "Use package specific test.sh"
86-
if sh "$TEST_SCRIPT" "$PKG_NAME" "$PKG_VERSION"; then
87-
echo "Test successful"
83+
SUCCESS=0
84+
if [ -f "$TEST_SCRIPT" ]; then
85+
info "Use the package-specific test.sh"
86+
if sh "$TEST_SCRIPT" "$PKG_NAME" "$PKG_VERSION"; then
87+
success "Test successful"
88+
SUCCESS=1
89+
else
90+
err "Test failed"
91+
fi
92+
8893
else
89-
echo "Test failed"
90-
exit 1
94+
warn "Use a generic test"
95+
96+
if [ $PKG_MANAGER = "opkg" ]; then
97+
PKG_FILES=$(opkg files "$PKG_NAME" | grep -E "^(/bin/|/sbin/|/usr/bin/|/usr/libexec/|/usr/sbin/)" || true)
98+
elif [ $PKG_MANAGER = "apk" ]; then
99+
PKG_FILES=$(apk info --contents "$PKG_NAME" | grep -E "^(bin/|sbin/|usr/bin/|usr/libexec/|usr/sbin/)" || true)
100+
fi
101+
102+
if [ -z "$PKG_FILES" ]; then
103+
success "No executables found in $PKG_NAME"
104+
SUCCESS=1
105+
else
106+
FOUND_EXEC=0
107+
for FILE in $PKG_FILES; do
108+
# apk info --contents does not have a leading /
109+
if [ $PKG_MANAGER = "apk" ]; then
110+
FILE="/$FILE"
111+
fi
112+
113+
if [ ! -f "$FILE" ] || [ ! -x "$FILE" ]; then
114+
continue
115+
fi
116+
117+
FOUND_EXEC=1
118+
info "Test executable $FILE and look for $PKG_VERSION"
119+
for V in --version -version version -v -V --help -help -?; do
120+
info "Trying $V"
121+
if "$FILE" "$V" 2>&1 | grep -F "$PKG_VERSION"; then
122+
SUCCESS=1
123+
break 2
124+
fi
125+
done
126+
done
127+
128+
if [ "$FOUND_EXEC" = 1 ]; then
129+
if [ "$SUCCESS" = 1 ]; then
130+
success "Test successful"
131+
else
132+
err "Test failed"
133+
fi
134+
else
135+
success "No executables found in $PKG_NAME"
136+
SUCCESS=1
137+
fi
138+
fi
91139
fi
92140

93141
if [ $PKG_MANAGER = "opkg" ]; then
94-
opkg remove "$PKG_NAME" --force-removal-of-dependent-packages --force-remove --autoremove || true
142+
opkg remove "$PKG_NAME" \
143+
--autoremove \
144+
--force-removal-of-dependent-packages \
145+
--force-remove \
146+
|| true
95147
elif [ $PKG_MANAGER = "apk" ]; then
96-
apk del -r "$PKG_NAME"
148+
apk del --rdepends "$PKG_NAME" || true
97149
fi
150+
151+
[ "$SUCCESS" = 1 ] || exit 1
98152
done

0 commit comments

Comments
 (0)