Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ jobs:
cargo test --workspace
cargo test -p lla --features wasm-plugins

- name: Test Unix installer
if: runner.os != 'Windows'
shell: bash
run: ./scripts/test_install_sh.sh

- name: Compile SDK fixtures
run: |
cargo check --manifest-path sdk/tests/fixtures/minimal_native/Cargo.toml
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- The Unix installer can once again be executed through the documented
`curl ... | bash` command without an unset `BASH_SOURCE` error.
- The Windows installer now handles GitHub checksum manifests correctly in
Windows PowerShell 5.1 and avoids its legacy Internet Explorer parsing prompt.

Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ main() {
install_binary
}

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
if [[ -z "${BASH_SOURCE[0]:-}" || "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi
101 changes: 101 additions & 0 deletions scripts/test_install_sh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
test_dir="$(mktemp -d)"
trap 'rm -rf "$test_dir"' EXIT

mkdir -p "$test_dir/bin"

cat >"$test_dir/bin/uname" <<'EOF'
#!/usr/bin/env bash
case "${1:-}" in
-s) printf '%s\n' Linux ;;
-m) printf '%s\n' x86_64 ;;
*) exit 1 ;;
esac
EOF

cat >"$test_dir/bin/curl" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

output=""
url=""
while (( $# > 0 )); do
case "$1" in
-o)
output="$2"
shift 2
;;
http://*|https://*)
url="$1"
shift
;;
*)
shift
;;
esac
done

case "$url" in
*/releases/latest)
printf '%s\n' '{"tag_name":"v0.0.0-test"}'
;;
*/SHA256SUMS)
printf '%s %s\n' "$MOCK_SHA256" lla-linux-amd64 >"$output"
;;
*/lla-linux-amd64)
printf '%s\n' 'fake lla binary' >"$output"
;;
*)
printf 'Unexpected curl URL: %s\n' "$url" >&2
exit 1
;;
esac
EOF

cat >"$test_dir/bin/sudo" <<'EOF'
#!/usr/bin/env bash
printf '%s\n' "$*" >>"$MOCK_SUDO_LOG"
EOF

chmod +x "$test_dir/bin/uname" "$test_dir/bin/curl" "$test_dir/bin/sudo"

if command -v sha256sum >/dev/null 2>&1; then
mock_sha256="$(printf '%s\n' 'fake lla binary' | sha256sum | awk '{print $1}')"
else
mock_sha256="$(printf '%s\n' 'fake lla binary' | shasum -a 256 | awk '{print $1}')"
fi

run_installer() {
local mode="$1"
local output_file="$test_dir/${mode}.out"
local sudo_log="$test_dir/${mode}.sudo"

: >"$sudo_log"
if [[ "$mode" == direct ]]; then
PATH="$test_dir/bin:$PATH" \
MOCK_SHA256="$mock_sha256" \
MOCK_SUDO_LOG="$sudo_log" \
bash "$repo_root/install.sh" >"$output_file"
else
PATH="$test_dir/bin:$PATH" \
MOCK_SHA256="$mock_sha256" \
MOCK_SUDO_LOG="$sudo_log" \
bash -s -- <"$repo_root/install.sh" >"$output_file"
fi

grep -Fq 'lla v0.0.0-test has been installed successfully!' "$output_file"
grep -Fq 'mv ' "$sudo_log"
}

bash -n "$repo_root/install.sh"
run_installer direct
run_installer piped

sourced_output="$(bash -c 'source "$1"; printf sourced' _ "$repo_root/install.sh")"
[[ "$sourced_output" == sourced ]]

printf '%s\n' 'install.sh tests passed'
Loading