Skip to content

Commit 61339b7

Browse files
committed
Make check less brittle and add test.
1 parent 7b15d09 commit 61339b7

File tree

3 files changed

+317
-40
lines changed

3 files changed

+317
-40
lines changed

.github/workflows/test-install.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test Install
2+
3+
on:
4+
push:
5+
branches: [main, release/**]
6+
paths:
7+
- install.sh
8+
- test_install.rb
9+
pull_request:
10+
paths:
11+
- install.sh
12+
- test_install.rb
13+
14+
concurrency:
15+
group:
16+
${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha ||
17+
github.ref }}
18+
cancel-in-progress: true
19+
20+
defaults:
21+
run:
22+
shell: bash
23+
24+
jobs:
25+
test-install:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
- uses: ruby/setup-ruby@09a7688d3b55cf0e976497ff046b70949eeaccfd # v1.288.0
30+
with:
31+
ruby-version: ruby
32+
- name: Run install tests
33+
run: ruby test_install.rb

install.sh

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ suggest_runtime_library_install() {
149149
package=""
150150
if command_exists apt-get; then
151151
case "$missing_lib" in
152-
libdbus-1.so.3) package="libdbus-1-3" ;;
153-
libudev.so.1) package="libudev1" ;;
154-
*) package="" ;;
152+
libdbus-1*) package="libdbus-1-3" ;;
153+
libudev*) package="libudev1" ;;
154+
*) package="" ;;
155155
esac
156156
if [ -n "$package" ]; then
157157
cat <<EOF
@@ -168,9 +168,9 @@ EOF
168168
fi
169169
elif command_exists dnf; then
170170
case "$missing_lib" in
171-
libdbus-1.so.3) package="dbus-libs" ;;
172-
libudev.so.1) package="systemd-libs" ;;
173-
*) package="" ;;
171+
libdbus-1*) package="dbus-libs" ;;
172+
libudev*) package="systemd-libs" ;;
173+
*) package="" ;;
174174
esac
175175
if [ -n "$package" ]; then
176176
cat <<EOF
@@ -186,9 +186,9 @@ EOF
186186
fi
187187
elif command_exists yum; then
188188
case "$missing_lib" in
189-
libdbus-1.so.3) package="dbus-libs" ;;
190-
libudev.so.1) package="systemd-libs" ;;
191-
*) package="" ;;
189+
libdbus-1*) package="dbus-libs" ;;
190+
libudev*) package="systemd-libs" ;;
191+
*) package="" ;;
192192
esac
193193
if [ -n "$package" ]; then
194194
cat <<EOF
@@ -204,9 +204,9 @@ EOF
204204
fi
205205
elif command_exists pacman; then
206206
case "$missing_lib" in
207-
libdbus-1.so.3) package="dbus" ;;
208-
libudev.so.1) package="systemd-libs" ;;
209-
*) package="" ;;
207+
libdbus-1*) package="dbus" ;;
208+
libudev*) package="systemd-libs" ;;
209+
*) package="" ;;
210210
esac
211211
if [ -n "$package" ]; then
212212
cat <<EOF
@@ -220,9 +220,9 @@ EOF
220220
fi
221221
elif command_exists zypper; then
222222
case "$missing_lib" in
223-
libdbus-1.so.3) package="libdbus-1-3" ;;
224-
libudev.so.1) package="libudev1" ;;
225-
*) package="" ;;
223+
libdbus-1*) package="libdbus-1-3" ;;
224+
libudev*) package="libudev1" ;;
225+
*) package="" ;;
226226
esac
227227
if [ -n "$package" ]; then
228228
cat <<EOF
@@ -552,43 +552,59 @@ print_contract_tooling_summary() {
552552
echo " Ready for smart contract builds."
553553
}
554554

555-
post_install_check() {
555+
check_runtime_libraries() {
556556
installed_binary="$1"
557-
version_output=""
558-
if version_output="$("$installed_binary" --version 2>&1)"; then
557+
558+
if [ "$OS" != "linux" ]; then
559559
return 0
560560
fi
561561

562-
missing_lib="$(printf '%s\n' "$version_output" | sed -n 's/.*error while loading shared libraries: \([^:]*\):.*/\1/p')"
562+
if ! command_exists ldconfig; then
563+
return 0
564+
fi
563565

564-
if [ -n "$missing_lib" ]; then
565-
echo ""
566-
echo "Warning: $BINARY_NAME was installed, but a runtime shared library is missing:"
567-
printf ' %s\n' "$missing_lib"
568-
echo ""
569-
suggest_runtime_library_install "$missing_lib"
570-
echo ""
571-
echo "After installing the runtime dependency, run:"
572-
printf ' %s --version\n' "$installed_binary"
573-
return 1
566+
ldconfig_output="$(ldconfig -p 2>/dev/null)"
567+
missing_libs=""
568+
569+
for lib in libdbus-1 libudev; do
570+
if ! printf '%s\n' "$ldconfig_output" | grep -q "$lib"; then
571+
missing_libs="$missing_libs $lib"
572+
fi
573+
done
574+
575+
missing_libs="${missing_libs# }"
576+
if [ -z "$missing_libs" ]; then
577+
return 0
574578
fi
575579

576580
echo ""
577-
echo "Warning: post-install check failed:"
578-
printf '%s\n' "$version_output"
581+
echo "Warning: $BINARY_NAME was installed, but runtime shared libraries are missing:"
582+
for lib in $missing_libs; do
583+
printf ' %s\n' "$lib"
584+
echo ""
585+
suggest_runtime_library_install "$lib"
586+
done
587+
echo ""
588+
echo "After installing the runtime dependencies, run:"
589+
printf ' %s --version\n' "$installed_binary"
590+
return 1
591+
}
579592

580-
if [ "$OS" = "linux" ] && [ "${LIBC:-unknown}" = "musl" ]; then
581-
if [ -f "$installed_binary" ] && printf '%s\n' "$version_output" | grep -qi "not found"; then
582-
cat <<EOF
593+
post_install_check() {
594+
installed_binary="$1"
583595

584-
This usually means the downloaded binary targets glibc but this system uses musl (e.g. Alpine).
585-
Next steps:
586-
1) Use a glibc-based image (Debian/Ubuntu/Fedora) for the prebuilt binary.
587-
2) If you must stay on Alpine, build stellar-cli from source on Alpine.
588-
EOF
589-
fi
596+
check_runtime_libraries "$installed_binary"
597+
runtime_ok=$?
598+
599+
version_output=""
600+
if version_output="$("$installed_binary" --version 2>&1)"; then
601+
return "$runtime_ok"
590602
fi
591603

604+
echo ""
605+
echo "Warning: post-install check failed:"
606+
printf '%s\n' "$version_output"
607+
592608
return 1
593609
}
594610

0 commit comments

Comments
 (0)