60 lines
2.6 KiB
Bash
Executable File
60 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env -S -i PATH=/usr/bin:/bin /bin/bash
|
|
set -euo pipefail
|
|
script_path=${BASH_SOURCE[0]}
|
|
script_dir=${script_path%/*}
|
|
[[ "$script_dir" != "$script_path" ]] || script_dir=.
|
|
repo_root="$(cd -P -- "$script_dir/.." && pwd)"
|
|
if [[ $# -lt 1 || "$1" != "integration" || $# -gt 2 || ( $# -eq 2 && "$2" != "--keep" ) ]]; then
|
|
printf 'usage: %s integration [--keep]
|
|
' "$0" >&2
|
|
exit 2
|
|
fi
|
|
|
|
canonical_file() {
|
|
local path=$1 target parent leaf
|
|
[[ "$path" = /* ]] || return 1
|
|
while [[ -L "$path" ]]; do
|
|
target=$(/usr/bin/readlink "$path") || return 1
|
|
if [[ "$target" = /* ]]; then path=$target; else path="${path%/*}/$target"; fi
|
|
done
|
|
parent=${path%/*}; leaf=${path##*/}
|
|
parent=$(cd -P -- "$parent" && pwd) || return 1
|
|
printf '%s/%s
|
|
' "$parent" "$leaf"
|
|
}
|
|
|
|
node_path= npm_path= toolchain_prefix=
|
|
for pair in "/usr/bin/node|/usr/bin/npm|/usr" "/opt/homebrew/bin/node|/opt/homebrew/bin/npm|/opt/homebrew" "/usr/local/bin/node|/usr/local/bin/npm|/usr/local"; do
|
|
node_candidate=${pair%%|*}; remainder=${pair#*|}; npm_candidate=${remainder%%|*}; prefix=${remainder##*|}
|
|
[[ -e "$node_candidate" && -e "$npm_candidate" ]] || continue
|
|
resolved_node=$(canonical_file "$node_candidate") || continue
|
|
resolved_npm=$(canonical_file "$npm_candidate") || continue
|
|
[[ -f "$resolved_node" && ! -L "$resolved_node" && -x "$resolved_node" ]] || continue
|
|
[[ -f "$resolved_npm" && ! -L "$resolved_npm" ]] || continue
|
|
[[ "${resolved_npm##*/}" = "npm-cli.js" ]] || continue
|
|
node_path=$resolved_node; npm_path=$resolved_npm; toolchain_prefix=$prefix
|
|
break
|
|
done
|
|
[[ -n "$node_path" && -n "$npm_path" && -n "$toolchain_prefix" ]] || {
|
|
printf 'trusted fixed Node/npm toolchain is unavailable
|
|
' >&2
|
|
exit 127
|
|
}
|
|
|
|
wrapper_root=$(/usr/bin/mktemp -d /tmp/thoth-p2p6-wrapper.XXXXXXXX)
|
|
trap '/bin/rm -rf -- "$wrapper_root"' EXIT HUP INT TERM
|
|
/bin/mkdir -m 700 "$wrapper_root/home" "$wrapper_root/tmp"
|
|
owned_path="${node_path%/*}:/usr/bin:/bin"
|
|
build_env=(/usr/bin/env -i "PATH=$owned_path" "HOME=$wrapper_root/home" "TMPDIR=$wrapper_root/tmp")
|
|
/bin/rm -rf -- "$repo_root/backend/dist"
|
|
"${build_env[@]}" "$node_path" "$npm_path" --prefix "$repo_root/backend" run build
|
|
|
|
p2p6_real_home=$(/bin/bash -lc 'printf "%s" ~' 2>/dev/null || true)
|
|
safe_env=(/usr/bin/env -i "PATH=$owned_path" "HOME=$wrapper_root/home" "TMPDIR=$wrapper_root/tmp"
|
|
"P2P6_REAL_HOME=${p2p6_real_home:-}" "THT_BIN=$repo_root/harness/.venv/bin/tht" "P2P6_ACCEPTANCE_NODE_PATH=$node_path" "P2P6_ACCEPTANCE_NPM_PATH=$npm_path")
|
|
set +e
|
|
"${safe_env[@]}" "$node_path" "$repo_root/backend/scripts/p2p6-acceptance.mjs" "$@"
|
|
status=$?
|
|
set -e
|
|
exit "$status"
|