mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 15:41:17 +00:00
feat(mosh): integrate MoshCatty pure Rust client (no Cygwin legacy) (#2085)
* feat(mosh): default bundled client to MoshCatty releases Wire Netcatty packaging and npm run dev to pull pure Rust mosh-client binaries from binaricat/MoshCatty (moshcatty-* tags), document the cutover, and mark the old Cygwin Windows fetch path as legacy-only. * fix(mosh): accept pure MoshCatty packages (exe-only, no dlls/terminfo) Align fetch/packaging with MoshCatty pure-Rust releases: require only mosh-client[.exe], treat Cygwin dll bags and terminfo as optional legacy layout. Document moshcatty-0.1.1 (ConPTY Ctrl+C + static MSVC CRT). * refactor(mosh): drop Cygwin legacy; MoshCatty-only pipeline Remove FluentTerminal/mosh-bin fallbacks, build-mosh C++ CI, and dll/terminfo runtime helpers. Fetch accepts only moshcatty-* pure binaries; packaging ships a single mosh-client per platform. * docs: align ET checklist and et README with MoshCatty-only mosh Update mosh template references after removing Cygwin build pipeline and legacy fallbacks. Point ET packaging notes at fetch-mosh / MoshCatty instead of deleted build-mosh-binaries workflow. * docs(mosh): require MoshCatty 0.1.2+ for Linux glibc floors Codex review vs main: defaulting to MoshCatty Linux binaries built on ubuntu-latest required GLIBC 2.34, above Netcatty's package floors (x64 2.28 / arm64 2.31). Document the floors, prefer moshcatty-0.1.2+, and drop trailing whitespace in the design note. Upstream MoshCatty release CI now builds in almalinux:8 / debian:bullseye with assert. * fix(mosh): reject MoshCatty releases below 0.1.2 Codex re-review: docs alone still allowed MOSH_BIN_RELEASE=moshcatty-0.1.0/0.1.1, which produce packages that fail to start on Netcatty's Linux glibc floors. Validate the minimum tag in resolve and fetch, skip pre-0.1.2 when picking latest, and cover the reject path in unit tests. * fix(mosh): pin MoshCatty owner and reject floor prereleases Codex review vs main (P2): - Always default MOSH_BIN owner/repo to binaricat/MoshCatty; do not inherit fork owner from GITHUB_REPOSITORY in resolve or fetch. - Treat moshcatty-X.Y.Z-rcN as below final X.Y.Z so pins like moshcatty-0.1.2-rc1 cannot bypass the glibc floor. * fix(mosh): accept build metadata in MoshCatty release tags TAG_RE rejected '+' so moshcatty-0.1.2+build.1 failed validation even though the version parser and isAtLeastMinRelease accepted it. Align the regex and require a successful semver parse.
This commit is contained in:
19 files changed
+482
-1808
No files matched your search
@@ -1,164 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build a portable mosh-client binary inside manylinux2014.
|
||||
#
|
||||
# Inputs (env):
|
||||
# MOSH_REF — git ref of mobile-shell/mosh to build (e.g. mosh-1.4.0)
|
||||
# ARCH — x64 | arm64 (for output naming only; container is already that arch)
|
||||
# OUT_DIR — directory to write mosh-client-linux-<arch>.tar.gz + sha256
|
||||
#
|
||||
# Output:
|
||||
# $OUT_DIR/mosh-client-linux-<arch>.tar.gz (binary + terminfo bundle)
|
||||
# $OUT_DIR/mosh-client-linux-<arch>.tar.gz.sha256
|
||||
#
|
||||
# The bundle ships a private terminfo database next to the binary because
|
||||
# our statically-linked ncurses has its compiled-in TERMINFO path pointing
|
||||
# at the build-time prefix (a temp dir). Without bundling, mosh-client on
|
||||
# distros lacking /usr/share/terminfo (or stripped containers) fails with
|
||||
# "Terminfo database could not be found." See issue #890.
|
||||
#
|
||||
# Strategy: build OpenSSL, protobuf, ncurses as static archives in a
|
||||
# scratch prefix, then build mosh against those and link libstdc++/libgcc
|
||||
# statically. The resulting binary still depends on standard Linux system
|
||||
# libraries such as glibc/libz/libutil from the manylinux2014 baseline
|
||||
# (compatible with virtually every distro released since 2014, including
|
||||
# Debian 9+, Ubuntu 18.04+, CentOS 7+).
|
||||
set -euo pipefail
|
||||
|
||||
: "${MOSH_REF:?missing MOSH_REF}"
|
||||
: "${ARCH:?missing ARCH}"
|
||||
: "${OUT_DIR:?missing OUT_DIR}"
|
||||
|
||||
validate_mosh_ref() {
|
||||
if [[ ! "$MOSH_REF" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \
|
||||
|| [[ "$MOSH_REF" == *..* ]] \
|
||||
|| [[ "$MOSH_REF" == *@\{* ]] \
|
||||
|| [[ "$MOSH_REF" == */ ]] \
|
||||
|| [[ "$MOSH_REF" == *.lock ]]; then
|
||||
echo "ERROR: invalid MOSH_REF: $MOSH_REF" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
validate_mosh_ref
|
||||
|
||||
OPENSSL_VER=3.0.13
|
||||
PROTOBUF_VER=21.12
|
||||
NCURSES_VER=6.4
|
||||
|
||||
curl_retry() {
|
||||
local url="$1"
|
||||
local dest="$2"
|
||||
curl -fsSL --retry 8 --retry-delay 5 --retry-max-time 600 "$url" -o "$dest"
|
||||
}
|
||||
|
||||
WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
PREFIX="$WORK/prefix"
|
||||
mkdir -p "$PREFIX/lib" "$PREFIX/include" "$OUT_DIR"
|
||||
|
||||
yum install -y -q autoconf automake libtool perl perl-IPC-Cmd make gcc gcc-c++ pkgconfig zlib-devel
|
||||
|
||||
cd "$WORK"
|
||||
|
||||
# OpenSSL static
|
||||
curl_retry "https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz" openssl.tgz
|
||||
tar xzf openssl.tgz
|
||||
( cd "openssl-$OPENSSL_VER"
|
||||
./config no-shared no-tests --prefix="$PREFIX" --openssldir="$PREFIX/ssl"
|
||||
make -j"$(nproc)"
|
||||
make install_sw )
|
||||
|
||||
# protobuf static (3.x stays compatible with mosh's generated proto code)
|
||||
curl_retry "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VER/protobuf-cpp-3.$PROTOBUF_VER.tar.gz" protobuf.tgz
|
||||
tar xzf protobuf.tgz
|
||||
( cd "protobuf-3.$PROTOBUF_VER"
|
||||
./configure --prefix="$PREFIX" --enable-static --disable-shared --with-pic
|
||||
make -j"$(nproc)"
|
||||
make install )
|
||||
|
||||
# ncurses static
|
||||
curl_retry "https://invisible-island.net/archives/ncurses/ncurses-$NCURSES_VER.tar.gz" ncurses.tgz
|
||||
tar xzf ncurses.tgz
|
||||
( cd "ncurses-$NCURSES_VER"
|
||||
CFLAGS="-fPIC -O2" CXXFLAGS="-fPIC -O2" \
|
||||
./configure --prefix="$PREFIX" --without-shared --without-debug --without-cxx-shared --without-tests --disable-pc-files --enable-widec
|
||||
make -j"$(nproc)"
|
||||
make install )
|
||||
|
||||
# Mosh. Fetch the requested ref explicitly so branch names, tags, and commit
|
||||
# SHAs all work from workflow_dispatch.
|
||||
git init mosh
|
||||
git -C mosh remote add origin https://github.com/mobile-shell/mosh.git
|
||||
git -C mosh fetch --depth 1 origin "$MOSH_REF"
|
||||
git -C mosh checkout --detach FETCH_HEAD
|
||||
( cd mosh
|
||||
export PATH="$PREFIX/bin:$PATH"
|
||||
./autogen.sh
|
||||
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/lib64/pkgconfig" \
|
||||
./configure --enable-completion=no --disable-server \
|
||||
CPPFLAGS="-I$PREFIX/include -I$PREFIX/include/ncursesw" \
|
||||
CXXFLAGS="-I$PREFIX/include -I$PREFIX/include/ncursesw -O2" \
|
||||
CFLAGS="-I$PREFIX/include -I$PREFIX/include/ncursesw -O2" \
|
||||
LDFLAGS="-L$PREFIX/lib -L$PREFIX/lib64 -static-libstdc++ -static-libgcc" \
|
||||
LIBS="-ldl -lpthread"
|
||||
make -j"$(nproc)" )
|
||||
|
||||
BUNDLE_DIR="$WORK/linux-$ARCH-bundle"
|
||||
mkdir -p "$BUNDLE_DIR"
|
||||
OUT_BIN="$BUNDLE_DIR/mosh-client"
|
||||
cp mosh/src/frontend/mosh-client "$OUT_BIN"
|
||||
strip "$OUT_BIN"
|
||||
|
||||
echo "--- file ---"
|
||||
file "$OUT_BIN"
|
||||
echo "--- ldd ---"
|
||||
ldd "$OUT_BIN" || true
|
||||
echo "--- size ---"
|
||||
ls -lh "$OUT_BIN"
|
||||
|
||||
# Sanity check: must not link any non-system shared libraries. Allow only
|
||||
# the glibc runtime family and the ELF loader.
|
||||
ldd "$OUT_BIN" > "$WORK/ldd.txt" || true
|
||||
awk '
|
||||
/=>/ { print $1; next }
|
||||
/^[[:space:]]*\/.*ld-linux/ { print $1; next }
|
||||
' "$WORK/ldd.txt" > "$WORK/deps.txt"
|
||||
if grep -Ev '^(linux-vdso\.so\.1|lib(c|m|pthread|rt|dl|resolv|util|z)\.so\.[0-9]+|/lib.*/ld-linux.*\.so\.[0-9]+|ld-linux.*\.so\.[0-9]+)$' "$WORK/deps.txt"; then
|
||||
echo "ERROR: mosh-client links a non-system shared library; static linking failed." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Bundle the terminfo entries our statically-linked ncurses needs. The
|
||||
# ncurses `make install` above populated $PREFIX/share/terminfo/ with the
|
||||
# full upstream terminfo.src. Ship a curated subset so users hit a
|
||||
# working entry regardless of TERM.
|
||||
TERMINFO_SRC="$PREFIX/share/terminfo"
|
||||
TERMINFO_OUT="$BUNDLE_DIR/terminfo"
|
||||
mkdir -p "$TERMINFO_OUT"
|
||||
copy_terminfo_entry() {
|
||||
local name="$1"
|
||||
for src in "$TERMINFO_SRC"/?/"$name" "$TERMINFO_SRC"/??/"$name"; do
|
||||
[ -f "$src" ] || continue
|
||||
local rel
|
||||
rel=$(basename "$(dirname "$src")")
|
||||
mkdir -p "$TERMINFO_OUT/$rel"
|
||||
cp "$src" "$TERMINFO_OUT/$rel/$name"
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
for entry in xterm-256color xterm xterm-color vt100 vt220 ansi screen screen-256color tmux tmux-256color dumb linux; do
|
||||
copy_terminfo_entry "$entry" || echo "WARN: terminfo entry $entry not found in $TERMINFO_SRC" >&2
|
||||
done
|
||||
if [ ! -f "$TERMINFO_OUT/x/xterm-256color" ] && [ ! -f "$TERMINFO_OUT/78/xterm-256color" ]; then
|
||||
echo "ERROR: failed to bundle xterm-256color terminfo for mosh-client (linux-$ARCH)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "--- bundled terminfo ---"
|
||||
find "$TERMINFO_OUT" -type f -print
|
||||
|
||||
BUNDLE_TGZ="$OUT_DIR/mosh-client-linux-$ARCH.tar.gz"
|
||||
( cd "$BUNDLE_DIR" && tar -czf "$BUNDLE_TGZ" "mosh-client" "terminfo" )
|
||||
|
||||
( cd "$OUT_DIR" && sha256sum "mosh-client-linux-$ARCH.tar.gz" > "mosh-client-linux-$ARCH.tar.gz.sha256" )
|
||||
cat "$OUT_DIR/mosh-client-linux-$ARCH.tar.gz.sha256"
|
||||
@@ -1,214 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build a universal2 (arm64 + x86_64) mosh-client for macOS.
|
||||
#
|
||||
# Inputs (env):
|
||||
# MOSH_REF — git ref of mobile-shell/mosh
|
||||
# OUT_DIR — destination directory
|
||||
# MACOSX_DEPLOYMENT_TARGET — minimum macOS version (default 11.0)
|
||||
#
|
||||
# Output:
|
||||
# $OUT_DIR/mosh-client-darwin-universal.tar.gz (binary + terminfo bundle)
|
||||
# $OUT_DIR/mosh-client-darwin-universal.tar.gz.sha256
|
||||
#
|
||||
# The bundle ships a private terminfo database next to the binary because
|
||||
# our statically-linked ncurses has its compiled-in TERMINFO path pointing
|
||||
# at the build-time prefix (a temp dir). Without bundling, mosh-client
|
||||
# fails with "Terminfo database could not be found." See issue #890.
|
||||
#
|
||||
# Strategy: build OpenSSL/protobuf/ncurses for arm64 and x86_64
|
||||
# (cross-compile via Apple clang's -arch flag), link mosh-client per arch,
|
||||
# then lipo the two single-arch binaries into one universal binary. The
|
||||
# final binary is allowed to depend only on macOS system dylibs.
|
||||
set -euo pipefail
|
||||
|
||||
: "${MOSH_REF:?missing MOSH_REF}"
|
||||
: "${OUT_DIR:?missing OUT_DIR}"
|
||||
|
||||
validate_mosh_ref() {
|
||||
if [[ ! "$MOSH_REF" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \
|
||||
|| [[ "$MOSH_REF" == *..* ]] \
|
||||
|| [[ "$MOSH_REF" == *@\{* ]] \
|
||||
|| [[ "$MOSH_REF" == */ ]] \
|
||||
|| [[ "$MOSH_REF" == *.lock ]]; then
|
||||
echo "ERROR: invalid MOSH_REF: $MOSH_REF" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
validate_mosh_ref
|
||||
|
||||
export MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-11.0}"
|
||||
|
||||
OPENSSL_VER=3.0.13
|
||||
PROTOBUF_VER=21.12
|
||||
NCURSES_VER=6.4
|
||||
|
||||
curl_retry() {
|
||||
local url="$1"
|
||||
local dest="$2"
|
||||
curl -fsSL --retry 8 --retry-delay 5 --retry-max-time 600 "$url" -o "$dest"
|
||||
}
|
||||
|
||||
# Install build tools when they are not already present on the runner.
|
||||
brew list autoconf >/dev/null 2>&1 || brew install autoconf
|
||||
brew list automake >/dev/null 2>&1 || brew install automake
|
||||
brew list pkg-config >/dev/null 2>&1 || brew install pkg-config
|
||||
brew list libtool >/dev/null 2>&1 || brew install libtool
|
||||
|
||||
WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
mkdir -p "$OUT_DIR"
|
||||
NATIVE_PROTOC_DIR=""
|
||||
|
||||
# Pre-fetch sources once.
|
||||
cd "$WORK"
|
||||
curl_retry "https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz" openssl.tgz
|
||||
curl_retry "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VER/protobuf-cpp-3.$PROTOBUF_VER.tar.gz" protobuf.tgz
|
||||
curl_retry "https://invisible-island.net/archives/ncurses/ncurses-$NCURSES_VER.tar.gz" ncurses.tgz
|
||||
git init mosh-src
|
||||
git -C mosh-src remote add origin https://github.com/mobile-shell/mosh.git
|
||||
git -C mosh-src fetch --depth 1 origin "$MOSH_REF"
|
||||
git -C mosh-src checkout --detach FETCH_HEAD
|
||||
|
||||
build_arch() {
|
||||
local ARCH="$1"
|
||||
local TRIPLE
|
||||
case "$ARCH" in
|
||||
arm64) TRIPLE=aarch64-apple-darwin ;;
|
||||
x86_64) TRIPLE=x86_64-apple-darwin ;;
|
||||
*) echo "unknown arch: $ARCH" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
local PREFIX="$WORK/prefix-$ARCH"
|
||||
mkdir -p "$PREFIX"
|
||||
|
||||
local CFLAGS_COMMON="-arch $ARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -O2"
|
||||
local LDFLAGS_COMMON="-arch $ARCH -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
|
||||
|
||||
# OpenSSL
|
||||
rm -rf "openssl-$OPENSSL_VER"
|
||||
tar xf openssl.tgz
|
||||
( cd "openssl-$OPENSSL_VER"
|
||||
if [ "$ARCH" = "arm64" ]; then
|
||||
./Configure darwin64-arm64-cc no-shared no-tests --prefix="$PREFIX" --openssldir="$PREFIX/ssl" -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET
|
||||
else
|
||||
./Configure darwin64-x86_64-cc no-shared no-tests --prefix="$PREFIX" --openssldir="$PREFIX/ssl" -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET
|
||||
fi
|
||||
make -j"$(sysctl -n hw.ncpu)"
|
||||
make install_sw )
|
||||
|
||||
# protobuf
|
||||
rm -rf "protobuf-3.$PROTOBUF_VER"
|
||||
tar xf protobuf.tgz
|
||||
( cd "protobuf-3.$PROTOBUF_VER"
|
||||
./configure --prefix="$PREFIX" --enable-static --disable-shared --with-pic --host="$TRIPLE" \
|
||||
CXX="clang++" CC="clang" \
|
||||
CFLAGS="$CFLAGS_COMMON" CXXFLAGS="$CFLAGS_COMMON" LDFLAGS="$LDFLAGS_COMMON"
|
||||
# protoc must run on the host (not the cross-target) — but here host arch is one of the two,
|
||||
# so this works directly when ARCH matches the runner. For the *other* arch we reuse the
|
||||
# protoc compiled in the first pass via PATH.
|
||||
make -j"$(sysctl -n hw.ncpu)" || make -j1
|
||||
make install )
|
||||
if [ "$ARCH" = "$NATIVE_ARCH" ]; then
|
||||
NATIVE_PROTOC_DIR="$PREFIX/bin"
|
||||
fi
|
||||
|
||||
# ncurses
|
||||
rm -rf "ncurses-$NCURSES_VER"
|
||||
tar xf ncurses.tgz
|
||||
( cd "ncurses-$NCURSES_VER"
|
||||
./configure --prefix="$PREFIX" --without-shared --without-debug --without-cxx-shared --without-tests --disable-pc-files --enable-widec --host="$TRIPLE" \
|
||||
CC="clang" CXX="clang++" \
|
||||
CFLAGS="$CFLAGS_COMMON" CXXFLAGS="$CFLAGS_COMMON" LDFLAGS="$LDFLAGS_COMMON"
|
||||
make -j"$(sysctl -n hw.ncpu)"
|
||||
make -C include install
|
||||
make -C ncurses install
|
||||
# Compile + install the terminfo database for the native arch only.
|
||||
# `tic` runs on the build host, so a cross-target build can't compile
|
||||
# terminfo entries — but the .src database is arch-independent, so a
|
||||
# single native-arch install populates $PREFIX/share/terminfo/ with
|
||||
# the data we bundle below.
|
||||
if [ "$ARCH" = "$NATIVE_ARCH" ]; then
|
||||
make -C progs install
|
||||
make -C misc install
|
||||
fi )
|
||||
|
||||
# mosh per-arch build
|
||||
( cd mosh-src
|
||||
make distclean >/dev/null 2>&1 || true
|
||||
export PATH="${NATIVE_PROTOC_DIR:-$PREFIX/bin}:$PATH"
|
||||
./autogen.sh
|
||||
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" \
|
||||
./configure --enable-completion=no --disable-server --host="$TRIPLE" \
|
||||
CXX="clang++" CC="clang" \
|
||||
CPPFLAGS="-I$PREFIX/include -I$PREFIX/include/ncursesw" \
|
||||
CXXFLAGS="-I$PREFIX/include -I$PREFIX/include/ncursesw $CFLAGS_COMMON" \
|
||||
CFLAGS="-I$PREFIX/include -I$PREFIX/include/ncursesw $CFLAGS_COMMON" \
|
||||
LDFLAGS="-L$PREFIX/lib $LDFLAGS_COMMON"
|
||||
make -j"$(sysctl -n hw.ncpu)"
|
||||
cp src/frontend/mosh-client "$WORK/mosh-client-$ARCH" )
|
||||
}
|
||||
|
||||
# Build host arch first so the first protobuf pass can use a native protoc.
|
||||
NATIVE_ARCH=$(uname -m)
|
||||
if [ "$NATIVE_ARCH" = "arm64" ]; then
|
||||
build_arch arm64
|
||||
build_arch x86_64
|
||||
else
|
||||
build_arch x86_64
|
||||
build_arch arm64
|
||||
fi
|
||||
|
||||
BUNDLE_DIR="$WORK/darwin-universal-bundle"
|
||||
mkdir -p "$BUNDLE_DIR"
|
||||
OUT_BIN="$BUNDLE_DIR/mosh-client"
|
||||
lipo -create "$WORK/mosh-client-arm64" "$WORK/mosh-client-x86_64" -output "$OUT_BIN"
|
||||
strip -x "$OUT_BIN" || true
|
||||
|
||||
echo "--- file ---"
|
||||
file "$OUT_BIN"
|
||||
echo "--- otool -L ---"
|
||||
otool -L "$OUT_BIN"
|
||||
echo "--- lipo -info ---"
|
||||
lipo -info "$OUT_BIN"
|
||||
echo "--- size ---"
|
||||
ls -lh "$OUT_BIN"
|
||||
|
||||
# Sanity check: must not depend on non-system dylibs.
|
||||
if otool -L "$OUT_BIN" | tail -n +2 | awk '{print $1}' | grep -Ev "^(/usr/lib/|/System/)"; then
|
||||
echo "ERROR: mosh-client links a non-system dylib; static linking failed." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Bundle the terminfo entries our statically-linked ncurses needs. Pull
|
||||
# from the native-arch prefix where `make -C misc install` ran tic above.
|
||||
TERMINFO_SRC="$WORK/prefix-$NATIVE_ARCH/share/terminfo"
|
||||
TERMINFO_OUT="$BUNDLE_DIR/terminfo"
|
||||
mkdir -p "$TERMINFO_OUT"
|
||||
copy_terminfo_entry() {
|
||||
local name="$1"
|
||||
for src in "$TERMINFO_SRC"/?/"$name" "$TERMINFO_SRC"/??/"$name"; do
|
||||
[ -f "$src" ] || continue
|
||||
local rel
|
||||
rel=$(basename "$(dirname "$src")")
|
||||
mkdir -p "$TERMINFO_OUT/$rel"
|
||||
cp "$src" "$TERMINFO_OUT/$rel/$name"
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
for entry in xterm-256color xterm xterm-color vt100 vt220 ansi screen screen-256color tmux tmux-256color dumb; do
|
||||
copy_terminfo_entry "$entry" || echo "WARN: terminfo entry $entry not found in $TERMINFO_SRC" >&2
|
||||
done
|
||||
if [ ! -f "$TERMINFO_OUT/x/xterm-256color" ] && [ ! -f "$TERMINFO_OUT/78/xterm-256color" ]; then
|
||||
echo "ERROR: failed to bundle xterm-256color terminfo for mosh-client (darwin-universal)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "--- bundled terminfo ---"
|
||||
find "$TERMINFO_OUT" -type f -print
|
||||
|
||||
BUNDLE_TGZ="$OUT_DIR/mosh-client-darwin-universal.tar.gz"
|
||||
( cd "$BUNDLE_DIR" && tar -czf "$BUNDLE_TGZ" "mosh-client" "terminfo" )
|
||||
|
||||
( cd "$OUT_DIR" && shasum -a 256 "mosh-client-darwin-universal.tar.gz" > "mosh-client-darwin-universal.tar.gz.sha256" )
|
||||
cat "$OUT_DIR/mosh-client-darwin-universal.tar.gz.sha256"
|
||||
@@ -1,61 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Source: pin the last known-good Windows mosh bundle built by Netcatty's
|
||||
# Cygwin workflow. The bundle carries mosh-client.exe, runtime DLLs, and the
|
||||
# xterm-256color terminfo entry needed by packaged Windows builds.
|
||||
#
|
||||
# Keep the old FluentTerminal standalone exe as a release fallback. It is
|
||||
# PE32+ x86-64 with no cygwin1.dll dependency. FluentTerminal is GPL-3.0, same
|
||||
# license as Netcatty, and the binary itself is GPL-3.0 from upstream
|
||||
# mobile-shell/mosh.
|
||||
#
|
||||
# Inputs (env): OUT_DIR
|
||||
# Output: $OUT_DIR/mosh-client-win32-x64.tar.gz (+ .sha256)
|
||||
# $OUT_DIR/mosh-client-win32-x64.exe (+ .sha256 fallback)
|
||||
set -euo pipefail
|
||||
|
||||
: "${OUT_DIR:?missing OUT_DIR}"
|
||||
|
||||
WINDOWS_BUNDLE_URL="${WINDOWS_BUNDLE_URL:-https://github.com/binaricat/Netcatty-mosh-bin/releases/download/mosh-bin-1.4.0-2/mosh-client-win32-x64.tar.gz}"
|
||||
WINDOWS_BUNDLE_SHA256="${WINDOWS_BUNDLE_SHA256:-3d4c4ae9fc8026dc8f4972856b9dedfb5e67fc623f2c23133c83b24c08bc1b2f}"
|
||||
|
||||
# Fallback pin: github.com/felixse/FluentTerminal commit bad0f85,
|
||||
# Dependencies/MoshExecutables/x64/mosh-client.exe.
|
||||
LEGACY_SOURCE_URL="${LEGACY_SOURCE_URL:-https://raw.githubusercontent.com/felixse/FluentTerminal/bad0f85/Dependencies/MoshExecutables/x64/mosh-client.exe}"
|
||||
LEGACY_EXPECTED_SHA256="${LEGACY_EXPECTED_SHA256:-5a8d84ff205c6a0711e53b961f909484a892f42648807e52d46d4fa93c05e286}"
|
||||
|
||||
check_sha256() {
|
||||
local file="$1"
|
||||
local expected="$2"
|
||||
local label="$3"
|
||||
local actual
|
||||
actual=$(sha256sum "$file" | awk '{print $1}')
|
||||
|
||||
if [ "$actual" != "$expected" ]; then
|
||||
echo "ERROR: SHA256 mismatch for $label" >&2
|
||||
echo " expected: $expected" >&2
|
||||
echo " actual: $actual" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s' "$actual"
|
||||
}
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
BUNDLE_OUT="$OUT_DIR/mosh-client-win32-x64.tar.gz"
|
||||
LEGACY_OUT="$OUT_DIR/mosh-client-win32-x64.exe"
|
||||
|
||||
curl -fsSL "$WINDOWS_BUNDLE_URL" -o "$BUNDLE_OUT"
|
||||
BUNDLE_ACTUAL=$(check_sha256 "$BUNDLE_OUT" "$WINDOWS_BUNDLE_SHA256" "mosh-client-win32-x64.tar.gz")
|
||||
|
||||
echo "Fetched mosh-client-win32-x64.tar.gz (sha256=$BUNDLE_ACTUAL)."
|
||||
ls -lh "$BUNDLE_OUT"
|
||||
echo "$BUNDLE_ACTUAL mosh-client-win32-x64.tar.gz" > "$BUNDLE_OUT.sha256"
|
||||
cat "$BUNDLE_OUT.sha256"
|
||||
|
||||
curl -fsSL "$LEGACY_SOURCE_URL" -o "$LEGACY_OUT"
|
||||
LEGACY_ACTUAL=$(check_sha256 "$LEGACY_OUT" "$LEGACY_EXPECTED_SHA256" "mosh-client.exe")
|
||||
|
||||
echo "Fetched fallback mosh-client.exe (sha256=$LEGACY_ACTUAL)."
|
||||
ls -lh "$LEGACY_OUT"
|
||||
echo "$LEGACY_ACTUAL mosh-client-win32-x64.exe" > "$LEGACY_OUT.sha256"
|
||||
cat "$LEGACY_OUT.sha256"
|
||||
+78
-177
@@ -1,33 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
//
|
||||
// Download platform-specific mosh-client binaries built by the
|
||||
// `build-mosh-binaries` GitHub Actions workflow into resources/mosh/, so
|
||||
// electron-builder can bundle them via `extraResources`. Designed to be
|
||||
// idempotent and safe to skip in dev / CI matrix legs that don't ship
|
||||
// mosh (e.g. when MOSH_BIN_RELEASE is unset).
|
||||
// Download platform-specific mosh-client binaries from binaricat/MoshCatty
|
||||
// releases into resources/mosh/, so electron-builder can bundle them via
|
||||
// extraResources.
|
||||
//
|
||||
// Layout (MoshCatty only — pure single binary per platform, no Cygwin DLLs,
|
||||
// no terminfo bag):
|
||||
// mosh-client-linux-x64.tar.gz -> resources/mosh/linux-x64/mosh-client
|
||||
// mosh-client-linux-arm64.tar.gz -> resources/mosh/linux-arm64/mosh-client
|
||||
// mosh-client-darwin-universal.tar.gz -> resources/mosh/darwin-universal/mosh-client
|
||||
// mosh-client-win32-x64.tar.gz -> resources/mosh/win32-x64/mosh-client.exe
|
||||
//
|
||||
// Usage:
|
||||
// node scripts/fetch-mosh-binaries.cjs # all platforms
|
||||
// node scripts/fetch-mosh-binaries.cjs
|
||||
// node scripts/fetch-mosh-binaries.cjs --platform=darwin --arch=universal
|
||||
// node scripts/fetch-mosh-binaries.cjs --host --resolve-release
|
||||
//
|
||||
// Env knobs:
|
||||
// MOSH_BIN_RELEASE — release tag in ${MOSH_BIN_OWNER}/${MOSH_BIN_REPO}.
|
||||
// Skip the whole step if unset (printed as a notice
|
||||
// so the build doesn't silently miss the bundling).
|
||||
// MOSH_BIN_OWNER — defaults to the GITHUB_REPOSITORY owner, or 'binaricat'
|
||||
// MOSH_BIN_REPO — default 'Netcatty-mosh-bin' (a dedicated binary
|
||||
// repository so the client repo stays source-only).
|
||||
// MOSH_BIN_BASE_URL — full override (e.g. for staging / local mirror).
|
||||
// MOSH_BIN_RES_DIR — override output dir for tests.
|
||||
// MOSH_BIN_ALLOW_UNVERIFIED=true — explicit local escape hatch for mirrors
|
||||
// without SHA256SUMS. Never use for release builds.
|
||||
// MOSH_BIN_FORCE_WINDOWS_CYGWIN=true — legacy debug knob kept for older
|
||||
// automation. Windows now prefers the released bundle
|
||||
// with its runtime helpers when SHA256SUMS lists it.
|
||||
// MOSH_BIN_WINDOWS_LEGACY_URL / MOSH_BIN_WINDOWS_LEGACY_SHA256 — test/mirror
|
||||
// overrides for that pinned Windows fallback.
|
||||
// Env:
|
||||
// MOSH_BIN_RELEASE — required for fetch unless --resolve-release
|
||||
// MOSH_BIN_OWNER / MOSH_BIN_REPO — default binaricat / MoshCatty
|
||||
// MOSH_BIN_BASE_URL — full release download base override
|
||||
// MOSH_BIN_RES_DIR — output dir override (tests)
|
||||
// MOSH_BIN_ALLOW_UNVERIFIED — accept missing SHA256SUMS (local mirrors only)
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
@@ -36,90 +31,33 @@ const https = require("node:https");
|
||||
const os = require("node:os");
|
||||
const crypto = require("node:crypto");
|
||||
const { execFileSync } = require("node:child_process");
|
||||
const { main: resolveMoshBinRelease } = require("./resolve-mosh-bin-release.cjs");
|
||||
const {
|
||||
main: resolveMoshBinRelease,
|
||||
validateReleaseTag,
|
||||
} = require("./resolve-mosh-bin-release.cjs");
|
||||
|
||||
const ROOT = path.resolve(__dirname, "..");
|
||||
const DEFAULT_RES_DIR = path.join(ROOT, "resources", "mosh");
|
||||
const WINDOWS_LEGACY_FLUENT_MOSH_CLIENT = {
|
||||
id: "windows-fluentterminal-standalone",
|
||||
file: "mosh-client-win32-x64.exe",
|
||||
local: "win32-x64/mosh-client.exe",
|
||||
url: "https://raw.githubusercontent.com/felixse/FluentTerminal/bad0f85/Dependencies/MoshExecutables/x64/mosh-client.exe",
|
||||
sha256: "5a8d84ff205c6a0711e53b961f909484a892f42648807e52d46d4fa93c05e286",
|
||||
};
|
||||
|
||||
// (file basename in the release -> relative subpath under resources/mosh/)
|
||||
// Using flat names in the release for SHA256SUMS readability, then
|
||||
// fanning out into platform-arch subdirs locally.
|
||||
//
|
||||
// Linux/macOS/Windows bundle targets are tar.gz archives containing the
|
||||
// binary plus the runtime helpers each platform needs.
|
||||
// Bundling terminfo lets bundled Posix mosh-client builds work on
|
||||
// minimal hosts that don't have a
|
||||
// system ncurses-base — see issue #890.
|
||||
//
|
||||
// `legacy` describes the pre-bundle artifact name some published mosh
|
||||
// binary releases still ship (Linux/Darwin used flat files before the
|
||||
// bundle layout). When SHA256SUMS lists only the legacy name we fall
|
||||
// back to it so existing releases keep working until a new tag is
|
||||
// republished with the bundle layout.
|
||||
const TARGETS = [
|
||||
{
|
||||
platform: "linux", arch: "x64",
|
||||
file: "mosh-client-linux-x64.tar.gz", localDir: "linux-x64", extract: "tar.gz",
|
||||
legacy: { file: "mosh-client-linux-x64", local: "linux-x64/mosh-client" },
|
||||
file: "mosh-client-linux-x64.tar.gz", localDir: "linux-x64", binary: "mosh-client",
|
||||
},
|
||||
{
|
||||
platform: "linux", arch: "arm64",
|
||||
file: "mosh-client-linux-arm64.tar.gz", localDir: "linux-arm64", extract: "tar.gz",
|
||||
legacy: { file: "mosh-client-linux-arm64", local: "linux-arm64/mosh-client" },
|
||||
file: "mosh-client-linux-arm64.tar.gz", localDir: "linux-arm64", binary: "mosh-client",
|
||||
},
|
||||
{
|
||||
platform: "darwin", arch: "universal",
|
||||
file: "mosh-client-darwin-universal.tar.gz", localDir: "darwin-universal", extract: "tar.gz",
|
||||
legacy: { file: "mosh-client-darwin-universal", local: "darwin-universal/mosh-client" },
|
||||
file: "mosh-client-darwin-universal.tar.gz", localDir: "darwin-universal", binary: "mosh-client",
|
||||
},
|
||||
{
|
||||
platform: "win32", arch: "x64",
|
||||
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", extract: "tar.gz",
|
||||
legacy: WINDOWS_LEGACY_FLUENT_MOSH_CLIENT,
|
||||
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", binary: "mosh-client.exe",
|
||||
},
|
||||
];
|
||||
|
||||
function applyReleaseAssetOverrides(asset, opts = {}) {
|
||||
if (asset.id !== WINDOWS_LEGACY_FLUENT_MOSH_CLIENT.id) return asset;
|
||||
return {
|
||||
...asset,
|
||||
url: opts.windowsLegacyUrl || asset.url,
|
||||
sha256: opts.windowsLegacySha256 || asset.sha256,
|
||||
};
|
||||
}
|
||||
|
||||
function selectReleaseAsset(target, sums, opts = {}) {
|
||||
const primary = { file: target.file, extract: target.extract, local: target.local, localDir: target.localDir };
|
||||
if (!target.legacy) return primary;
|
||||
if (target.preferLegacy && !opts.forceWindowsCygwin) {
|
||||
const legacy = applyReleaseAssetOverrides(target.legacy, opts);
|
||||
if (sums.get(target.legacy.file) === legacy.sha256) {
|
||||
return { file: target.legacy.file, local: target.legacy.local, sha256: legacy.sha256 };
|
||||
}
|
||||
return legacy;
|
||||
}
|
||||
// SHA256SUMS unavailable (allowUnverified mirror) — keep the primary
|
||||
// and let download / extraction errors surface naturally.
|
||||
if (sums.size === 0) return primary;
|
||||
if (sums.has(target.file)) return primary;
|
||||
if (sums.has(target.legacy.file)) {
|
||||
const expected = sums.get(target.legacy.file);
|
||||
const fallback = applyReleaseAssetOverrides(target.legacy, opts);
|
||||
if (fallback.id && fallback.sha256 && expected !== fallback.sha256) {
|
||||
return fallback;
|
||||
}
|
||||
return { file: target.legacy.file, local: target.legacy.local, sha256: expected };
|
||||
}
|
||||
return primary;
|
||||
}
|
||||
|
||||
function log(msg) { console.log(`[fetch-mosh-binaries] ${msg}`); }
|
||||
function warn(msg) { console.warn(`[fetch-mosh-binaries] WARN ${msg}`); }
|
||||
|
||||
@@ -215,10 +153,11 @@ function chmodExecutable(filePath) {
|
||||
}
|
||||
|
||||
function parseMoshBinRepository(env) {
|
||||
const githubOwner = (env.GITHUB_REPOSITORY || "").split("/")[0];
|
||||
// Canonical default binaricat/MoshCatty — never inherit fork owner from
|
||||
// GITHUB_REPOSITORY (same policy as resolve-mosh-bin-release).
|
||||
return {
|
||||
owner: env.MOSH_BIN_OWNER || githubOwner || "binaricat",
|
||||
repo: env.MOSH_BIN_REPO || "Netcatty-mosh-bin",
|
||||
owner: env.MOSH_BIN_OWNER || "binaricat",
|
||||
repo: env.MOSH_BIN_REPO || "MoshCatty",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -252,53 +191,46 @@ function assertExtractedTreeSafe(root) {
|
||||
}
|
||||
}
|
||||
|
||||
function assertBundledTerminfo(extractDir, target) {
|
||||
const terminfoDir = path.join(extractDir, "terminfo");
|
||||
const terminfoEntry = [
|
||||
path.join(terminfoDir, "x", "xterm-256color"),
|
||||
path.join(terminfoDir, "78", "xterm-256color"),
|
||||
].find((entry) => fs.existsSync(entry));
|
||||
if (terminfoEntry && !fs.lstatSync(terminfoEntry).isFile()) {
|
||||
throw new Error(`${target.file} contained invalid terminfo for xterm-256color`);
|
||||
/** Keep only the pure MoshCatty client binary under extractDir. */
|
||||
function normalizeMoshCattyBundle(extractDir, target) {
|
||||
const wanted = target.binary;
|
||||
const candidates = [
|
||||
path.join(extractDir, wanted),
|
||||
path.join(extractDir, `mosh-client-${target.platform}-${target.arch}${wanted.endsWith(".exe") ? ".exe" : ""}`),
|
||||
path.join(extractDir, wanted.endsWith(".exe") ? "mosh-client.exe" : "mosh-client"),
|
||||
];
|
||||
let found = candidates.find((p) => fs.existsSync(p) && fs.lstatSync(p).isFile());
|
||||
if (!found) {
|
||||
// Search one level deep for a correctly named binary
|
||||
for (const name of fs.readdirSync(extractDir)) {
|
||||
const child = path.join(extractDir, name);
|
||||
if (!fs.statSync(child).isDirectory()) continue;
|
||||
const nested = path.join(child, wanted);
|
||||
if (fs.existsSync(nested) && fs.lstatSync(nested).isFile()) {
|
||||
found = nested;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!terminfoEntry) {
|
||||
warn(`${target.file} did not contain terminfo for xterm-256color; ${target.platform}-${target.arch} mosh packaging will fall back to host system terminfo (issue #890).`);
|
||||
if (!found) {
|
||||
throw new Error(`${target.file} did not contain ${wanted}`);
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeWindowsBundle(extractDir, target) {
|
||||
const genericExe = path.join(extractDir, "mosh-client.exe");
|
||||
const legacyExe = path.join(extractDir, `mosh-client-${target.platform}-${target.arch}.exe`);
|
||||
if (!fs.existsSync(genericExe) && fs.existsSync(legacyExe)) {
|
||||
fs.renameSync(legacyExe, genericExe);
|
||||
}
|
||||
if (!fs.existsSync(genericExe) || !fs.lstatSync(genericExe).isFile()) {
|
||||
throw new Error(`${target.file} did not contain mosh-client.exe`);
|
||||
}
|
||||
const dllDir = path.join(extractDir, `mosh-client-${target.platform}-${target.arch}-dlls`);
|
||||
if (!fs.existsSync(dllDir) || !fs.statSync(dllDir).isDirectory()) {
|
||||
throw new Error(`${target.file} did not contain ${path.basename(dllDir)}/`);
|
||||
}
|
||||
assertBundledTerminfo(extractDir, target);
|
||||
chmodExecutable(genericExe);
|
||||
}
|
||||
// Stage a clean tree with only the client binary (drop any accidental extras).
|
||||
const cleanDir = path.join(extractDir, ".moshcatty-clean");
|
||||
fs.mkdirSync(cleanDir, { recursive: true });
|
||||
const destBinary = path.join(cleanDir, wanted);
|
||||
fs.copyFileSync(found, destBinary);
|
||||
chmodExecutable(destBinary);
|
||||
|
||||
function normalizePosixBundle(extractDir, target) {
|
||||
const binary = path.join(extractDir, "mosh-client");
|
||||
const legacyBinary = path.join(extractDir, `mosh-client-${target.platform}-${target.arch}`);
|
||||
if (!fs.existsSync(binary) && fs.existsSync(legacyBinary)) {
|
||||
fs.renameSync(legacyBinary, binary);
|
||||
for (const name of fs.readdirSync(extractDir)) {
|
||||
if (name === ".moshcatty-clean") continue;
|
||||
fs.rmSync(path.join(extractDir, name), { recursive: true, force: true });
|
||||
}
|
||||
if (!fs.existsSync(binary) || !fs.lstatSync(binary).isFile()) {
|
||||
throw new Error(`${target.file} did not contain mosh-client`);
|
||||
for (const name of fs.readdirSync(cleanDir)) {
|
||||
fs.renameSync(path.join(cleanDir, name), path.join(extractDir, name));
|
||||
}
|
||||
assertBundledTerminfo(extractDir, target);
|
||||
chmodExecutable(binary);
|
||||
}
|
||||
|
||||
function normalizeBundle(extractDir, target) {
|
||||
if (target.platform === "win32") return normalizeWindowsBundle(extractDir, target);
|
||||
return normalizePosixBundle(extractDir, target);
|
||||
fs.rmSync(cleanDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
function replaceDir(srcDir, destDir) {
|
||||
@@ -328,7 +260,7 @@ function unpackTarGz(buf, target, { resDir }) {
|
||||
stdio: "inherit",
|
||||
});
|
||||
assertExtractedTreeSafe(extractDir);
|
||||
normalizeBundle(extractDir, target);
|
||||
normalizeMoshCattyBundle(extractDir, target);
|
||||
replaceDir(extractDir, destDir);
|
||||
} finally {
|
||||
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
||||
@@ -336,55 +268,30 @@ function unpackTarGz(buf, target, { resDir }) {
|
||||
return destDir;
|
||||
}
|
||||
|
||||
function writeFlatAsset(buf, target, asset, { resDir }) {
|
||||
const dest = path.join(resDir, asset.local);
|
||||
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-mosh-flat-"));
|
||||
const tmpDest = path.join(tmpRoot, path.basename(dest));
|
||||
try {
|
||||
fs.writeFileSync(tmpDest, buf);
|
||||
if (target.platform !== "win32") fs.chmodSync(tmpDest, 0o755);
|
||||
replaceDir(tmpRoot, path.dirname(dest));
|
||||
} catch (err) {
|
||||
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
||||
throw err;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
async function fetchOne(target, sums, opts) {
|
||||
const { baseUrl, resDir, allowUnverified = false } = opts;
|
||||
const asset = selectReleaseAsset(target, sums, opts);
|
||||
if (asset.file !== target.file) {
|
||||
log(`using legacy asset ${asset.file} for ${target.platform}-${target.arch}`);
|
||||
}
|
||||
const url = asset.url || `${baseUrl}/${asset.file}`;
|
||||
const url = `${baseUrl}/${target.file}`;
|
||||
let buf;
|
||||
try {
|
||||
buf = await follow(url);
|
||||
} catch (err) {
|
||||
throw new Error(`download failed for ${asset.file}: ${err.message}`);
|
||||
throw new Error(`download failed for ${target.file}: ${err.message}`);
|
||||
}
|
||||
|
||||
const expected = asset.sha256 || sums.get(asset.file);
|
||||
const expected = sums.get(target.file);
|
||||
const actual = crypto.createHash("sha256").update(buf).digest("hex");
|
||||
if (expected && expected !== actual) {
|
||||
throw new Error(`SHA256 mismatch for ${asset.file}: expected ${expected}, got ${actual}`);
|
||||
throw new Error(`SHA256 mismatch for ${target.file}: expected ${expected}, got ${actual}`);
|
||||
}
|
||||
if (!expected) {
|
||||
if (!allowUnverified) {
|
||||
throw new Error(`no SHA256 entry for ${asset.file}`);
|
||||
throw new Error(`no SHA256 entry for ${target.file}`);
|
||||
}
|
||||
warn(`no SHA256 entry for ${asset.file} - accepting actual ${actual}`);
|
||||
warn(`no SHA256 entry for ${target.file} - accepting actual ${actual}`);
|
||||
}
|
||||
|
||||
if (asset.extract === "tar.gz") {
|
||||
const destDir = unpackTarGz(buf, target, { resDir });
|
||||
log(`unpacked ${asset.file} into ${path.relative(ROOT, destDir)}/ (sha256=${actual})`);
|
||||
return true;
|
||||
}
|
||||
|
||||
const dest = writeFlatAsset(buf, target, asset, { resDir });
|
||||
log(`wrote ${path.relative(ROOT, dest)} (${buf.length} bytes, sha256=${actual})`);
|
||||
const destDir = unpackTarGz(buf, target, { resDir });
|
||||
log(`unpacked ${target.file} into ${path.relative(ROOT, destDir)}/ (sha256=${actual})`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -406,16 +313,18 @@ async function main(argv = process.argv.slice(2), env = process.env) {
|
||||
release = await resolveMoshBinRelease(env);
|
||||
}
|
||||
if (!release) {
|
||||
log("MOSH_BIN_RELEASE is unset - skipping. Set it (e.g. mosh-bin-1.4.0-1) to bundle mosh-client into the package.");
|
||||
log("MOSH_BIN_RELEASE is unset - skipping. Set it (e.g. moshcatty-0.1.2) to bundle mosh-client into the package.");
|
||||
return 0;
|
||||
}
|
||||
// Reject pre-0.1.2 pins (Linux GLIBC 2.34) even when MOSH_BIN_RELEASE is set
|
||||
// without going through --resolve-release.
|
||||
release = validateReleaseTag(release);
|
||||
|
||||
const { owner, repo } = parseMoshBinRepository(env);
|
||||
const baseUrl = env.MOSH_BIN_BASE_URL ||
|
||||
`https://github.com/${owner}/${repo}/releases/download/${encodeURIComponent(release)}`;
|
||||
const resDir = path.resolve(env.MOSH_BIN_RES_DIR || DEFAULT_RES_DIR);
|
||||
const allowUnverified = env.MOSH_BIN_ALLOW_UNVERIFIED === "true";
|
||||
const forceWindowsCygwin = env.MOSH_BIN_FORCE_WINDOWS_CYGWIN === "true";
|
||||
const platformFilter = hostTarget?.platform || platformArg;
|
||||
const archFilter = hostTarget?.arch || archArg;
|
||||
|
||||
@@ -427,14 +336,7 @@ async function main(argv = process.argv.slice(2), env = process.env) {
|
||||
if (platformFilter && target.platform !== platformFilter) continue;
|
||||
if (archFilter && target.arch !== archFilter) continue;
|
||||
total += 1;
|
||||
if (await fetchOne(target, sums, {
|
||||
baseUrl,
|
||||
resDir,
|
||||
allowUnverified,
|
||||
forceWindowsCygwin,
|
||||
windowsLegacyUrl: env.MOSH_BIN_WINDOWS_LEGACY_URL,
|
||||
windowsLegacySha256: env.MOSH_BIN_WINDOWS_LEGACY_SHA256,
|
||||
})) ok += 1;
|
||||
if (await fetchOne(target, sums, { baseUrl, resDir, allowUnverified })) ok += 1;
|
||||
}
|
||||
log(`done - ${ok}/${total} binaries written`);
|
||||
if (ok < total) throw new Error(`only wrote ${ok}/${total} requested binaries`);
|
||||
@@ -455,10 +357,9 @@ module.exports = {
|
||||
resolveHostTarget,
|
||||
resolveTarArchiveInvocation,
|
||||
parseSums,
|
||||
selectReleaseAsset,
|
||||
validateTarEntries,
|
||||
assertExtractedTreeSafe,
|
||||
normalizeMoshCattyBundle,
|
||||
unpackTarGz,
|
||||
writeFlatAsset,
|
||||
main,
|
||||
};
|
||||
@@ -15,7 +15,7 @@ const {
|
||||
replaceDir,
|
||||
resolveHostTarget,
|
||||
resolveTarArchiveInvocation,
|
||||
selectReleaseAsset,
|
||||
TARGETS,
|
||||
} = require("./fetch-mosh-binaries.cjs");
|
||||
|
||||
function makeTmp(t) {
|
||||
@@ -40,35 +40,48 @@ function makeTarGz(t, entries) {
|
||||
return fs.readFileSync(tarPath);
|
||||
}
|
||||
|
||||
test("fetch-mosh-binaries defaults to the dedicated mosh binary repository", () => {
|
||||
assert.deepEqual(parseMoshBinRepository({}), { owner: "binaricat", repo: "Netcatty-mosh-bin" });
|
||||
async function serveAssets(t, assets) {
|
||||
const server = http.createServer((req, res) => {
|
||||
const name = decodeURIComponent(req.url.split("/").pop());
|
||||
if (!Object.prototype.hasOwnProperty.call(assets, name)) {
|
||||
res.writeHead(404);
|
||||
res.end("missing");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200);
|
||||
res.end(assets[name]);
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
t.after(() => server.close());
|
||||
return `http://127.0.0.1:${server.address().port}`;
|
||||
}
|
||||
|
||||
test("fetch-mosh-binaries defaults to the MoshCatty binary repository", () => {
|
||||
assert.deepEqual(parseMoshBinRepository({}), { owner: "binaricat", repo: "MoshCatty" });
|
||||
// Fork CI must not inherit GITHUB_REPOSITORY owner for MoshCatty downloads.
|
||||
assert.deepEqual(parseMoshBinRepository({ GITHUB_REPOSITORY: "owner/project" }), {
|
||||
owner: "owner",
|
||||
repo: "Netcatty-mosh-bin",
|
||||
owner: "binaricat",
|
||||
repo: "MoshCatty",
|
||||
});
|
||||
assert.deepEqual(
|
||||
parseMoshBinRepository({ GITHUB_REPOSITORY: "owner/project", MOSH_BIN_OWNER: "bin", MOSH_BIN_REPO: "binaries" }),
|
||||
{ owner: "bin", repo: "binaries" },
|
||||
parseMoshBinRepository({ MOSH_BIN_OWNER: "other", MOSH_BIN_REPO: "fork-mosh" }),
|
||||
{ owner: "other", repo: "fork-mosh" },
|
||||
);
|
||||
});
|
||||
|
||||
test("TARGETS are pure MoshCatty tarball assets only", () => {
|
||||
for (const t of TARGETS) {
|
||||
assert.match(t.file, /^mosh-client-.+\.tar\.gz$/);
|
||||
assert.ok(t.binary === "mosh-client" || t.binary === "mosh-client.exe");
|
||||
assert.equal(Object.prototype.hasOwnProperty.call(t, "legacy"), false);
|
||||
}
|
||||
});
|
||||
|
||||
test("resolveHostTarget maps the local platform to the bundled target", () => {
|
||||
assert.deepEqual(resolveHostTarget({ platform: "darwin", arch: "arm64" }), {
|
||||
platform: "darwin",
|
||||
arch: "universal",
|
||||
});
|
||||
assert.deepEqual(resolveHostTarget({ platform: "darwin", arch: "x64" }), {
|
||||
platform: "darwin",
|
||||
arch: "universal",
|
||||
});
|
||||
assert.deepEqual(resolveHostTarget({ platform: "linux", arch: "x64" }), {
|
||||
platform: "linux",
|
||||
arch: "x64",
|
||||
});
|
||||
assert.deepEqual(resolveHostTarget({ platform: "linux", arch: "arm64" }), {
|
||||
platform: "linux",
|
||||
arch: "arm64",
|
||||
});
|
||||
assert.deepEqual(resolveHostTarget({ platform: "win32", arch: "x64" }), {
|
||||
platform: "win32",
|
||||
arch: "x64",
|
||||
@@ -117,9 +130,7 @@ test("replaceDir falls back to copy when rename crosses devices", (t) => {
|
||||
|
||||
test("fetch-mosh-binaries host mode skips unsupported local targets", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const baseUrl = await serveAssets(t, {
|
||||
SHA256SUMS: "",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, { SHA256SUMS: "" });
|
||||
|
||||
const { stderr } = await execFileAsync(
|
||||
process.execPath,
|
||||
@@ -127,7 +138,7 @@ test("fetch-mosh-binaries host mode skips unsupported local targets", async (t)
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
@@ -140,49 +151,39 @@ test("fetch-mosh-binaries host mode skips unsupported local targets", async (t)
|
||||
assert.equal(fs.existsSync(resDir), false);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries host mode skips unsupported targets before resolving release", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
|
||||
const { stdout, stderr } = await execFileAsync(
|
||||
process.execPath,
|
||||
[script, "--host", "--resolve-release", "--platform=win32", "--arch=arm64"],
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "",
|
||||
MOSH_BIN_RELEASES_JSON: "[]",
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
},
|
||||
);
|
||||
|
||||
assert.match(stderr, /No bundled mosh-client target for win32-arm64/);
|
||||
assert.doesNotMatch(stdout, /MOSH_BIN_RELEASE is unset/);
|
||||
assert.equal(fs.existsSync(resDir), false);
|
||||
});
|
||||
|
||||
async function serveAssets(t, assets) {
|
||||
const server = http.createServer((req, res) => {
|
||||
const name = decodeURIComponent(req.url.split("/").pop());
|
||||
if (!Object.prototype.hasOwnProperty.call(assets, name)) {
|
||||
res.writeHead(404);
|
||||
res.end("missing");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200);
|
||||
res.end(assets[name]);
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
t.after(() => server.close());
|
||||
return `http://127.0.0.1:${server.address().port}`;
|
||||
}
|
||||
|
||||
test("fetch-mosh-binaries normalizes the Windows tarball to mosh-client.exe", async (t) => {
|
||||
test("fetch-mosh-binaries unpacks pure Windows MoshCatty tarball", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client-win32-x64.exe": "exe",
|
||||
"mosh-client.exe": "pure-moshcatty-exe",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-win32-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-win32-x64.tar.gz\n`,
|
||||
});
|
||||
|
||||
await execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
fs.readFileSync(path.join(resDir, "win32-x64", "mosh-client.exe"), "utf8"),
|
||||
"pure-moshcatty-exe",
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls")), false);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "terminfo")), false);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries strips accidental dll/terminfo from Windows tarball", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client.exe": "exe",
|
||||
"mosh-client-win32-x64-dlls/cygwin1.dll": "dll",
|
||||
"terminfo/x/xterm-256color": "terminfo",
|
||||
});
|
||||
@@ -194,216 +195,7 @@ test("fetch-mosh-binaries normalizes the Windows tarball to mosh-client.exe", as
|
||||
await execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
MOSH_BIN_FORCE_WINDOWS_CYGWIN: "true",
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "mosh-client.exe")), true);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls", "cygwin1.dll")), true);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "terminfo", "x", "xterm-256color")), true);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries accepts legacy Windows bundles without terminfo", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client.exe": "exe",
|
||||
"mosh-client-win32-x64-dlls/cygwin1.dll": "dll",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-win32-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-win32-x64.tar.gz\n`,
|
||||
});
|
||||
|
||||
const { stderr } = await execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
MOSH_BIN_FORCE_WINDOWS_CYGWIN: "true",
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
assert.match(stderr, /did not contain terminfo for xterm-256color/);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "mosh-client.exe")), true);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries rejects invalid Windows terminfo entries", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const srcDir = makeTmp(t);
|
||||
fs.writeFileSync(path.join(srcDir, "mosh-client.exe"), "exe");
|
||||
fs.mkdirSync(path.join(srcDir, "mosh-client-win32-x64-dlls"), { recursive: true });
|
||||
fs.writeFileSync(path.join(srcDir, "mosh-client-win32-x64-dlls", "cygwin1.dll"), "dll");
|
||||
fs.mkdirSync(path.join(srcDir, "terminfo", "x", "xterm-256color"), { recursive: true });
|
||||
const tarPath = path.join(makeTmp(t), "invalid-terminfo.tar.gz");
|
||||
execFileSync("tar", ["-czf", tarPath, "-C", srcDir, "mosh-client.exe", "mosh-client-win32-x64-dlls", "terminfo"], { stdio: "pipe" });
|
||||
const tar = fs.readFileSync(tarPath);
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-win32-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-win32-x64.tar.gz\n`,
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
MOSH_BIN_FORCE_WINDOWS_CYGWIN: "true",
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
}),
|
||||
/invalid terminfo for xterm-256color/,
|
||||
);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries fails when SHA256SUMS lacks the requested asset", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client.exe": "exe",
|
||||
"mosh-client-win32-x64-dlls/cygwin1.dll": "dll",
|
||||
"terminfo/x/xterm-256color": "terminfo",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-win32-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(Buffer.from("other"))} other-file\n`,
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
MOSH_BIN_FORCE_WINDOWS_CYGWIN: "true",
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test("selectReleaseAsset prefers the bundled tarball when listed in SHA256SUMS", () => {
|
||||
const target = {
|
||||
platform: "linux", arch: "x64",
|
||||
file: "mosh-client-linux-x64.tar.gz", localDir: "linux-x64", extract: "tar.gz",
|
||||
legacy: { file: "mosh-client-linux-x64", local: "linux-x64/mosh-client" },
|
||||
};
|
||||
const sums = new Map([
|
||||
["mosh-client-linux-x64.tar.gz", "abc"],
|
||||
["mosh-client-linux-x64", "def"],
|
||||
]);
|
||||
assert.equal(selectReleaseAsset(target, sums).file, "mosh-client-linux-x64.tar.gz");
|
||||
});
|
||||
|
||||
test("selectReleaseAsset falls back to the legacy flat asset when only it is published", () => {
|
||||
const target = {
|
||||
platform: "linux", arch: "x64",
|
||||
file: "mosh-client-linux-x64.tar.gz", localDir: "linux-x64", extract: "tar.gz",
|
||||
legacy: { file: "mosh-client-linux-x64", local: "linux-x64/mosh-client" },
|
||||
};
|
||||
const sums = new Map([["mosh-client-linux-x64", "def"]]);
|
||||
const asset = selectReleaseAsset(target, sums);
|
||||
assert.equal(asset.file, "mosh-client-linux-x64");
|
||||
assert.equal(asset.local, "linux-x64/mosh-client");
|
||||
assert.equal(asset.extract, undefined);
|
||||
});
|
||||
|
||||
test("selectReleaseAsset stays on the primary when SHA256SUMS is empty (unverified mirror)", () => {
|
||||
const target = {
|
||||
platform: "linux", arch: "x64",
|
||||
file: "mosh-client-linux-x64.tar.gz", localDir: "linux-x64", extract: "tar.gz",
|
||||
legacy: { file: "mosh-client-linux-x64", local: "linux-x64/mosh-client" },
|
||||
};
|
||||
assert.equal(selectReleaseAsset(target, new Map()).file, "mosh-client-linux-x64.tar.gz");
|
||||
});
|
||||
|
||||
test("selectReleaseAsset prefers the released Windows bundle by default", () => {
|
||||
const target = {
|
||||
platform: "win32", arch: "x64",
|
||||
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", extract: "tar.gz",
|
||||
legacy: {
|
||||
id: "windows-fluentterminal-standalone",
|
||||
file: "mosh-client-win32-x64.exe",
|
||||
local: "win32-x64/mosh-client.exe",
|
||||
url: "https://example.test/mosh-client.exe",
|
||||
sha256: "abc",
|
||||
},
|
||||
};
|
||||
const sums = new Map([["mosh-client-win32-x64.tar.gz", "def"]]);
|
||||
|
||||
assert.equal(selectReleaseAsset(target, sums).file, "mosh-client-win32-x64.tar.gz");
|
||||
assert.equal(selectReleaseAsset(target, sums, { forceWindowsCygwin: true }).file, "mosh-client-win32-x64.tar.gz");
|
||||
});
|
||||
|
||||
test("selectReleaseAsset falls back to the Windows standalone asset when the bundle is absent", () => {
|
||||
const target = {
|
||||
platform: "win32", arch: "x64",
|
||||
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", extract: "tar.gz",
|
||||
legacy: {
|
||||
id: "windows-fluentterminal-standalone",
|
||||
file: "mosh-client-win32-x64.exe",
|
||||
local: "win32-x64/mosh-client.exe",
|
||||
url: "https://example.test/mosh-client.exe",
|
||||
sha256: "abc",
|
||||
},
|
||||
};
|
||||
const asset = selectReleaseAsset(target, new Map([["mosh-client-win32-x64.exe", "abc"]]));
|
||||
|
||||
assert.equal(asset.file, "mosh-client-win32-x64.exe");
|
||||
assert.equal(asset.local, "win32-x64/mosh-client.exe");
|
||||
assert.equal(asset.url, undefined);
|
||||
assert.equal(asset.sha256, "abc");
|
||||
});
|
||||
|
||||
test("selectReleaseAsset ignores a released Windows asset when its checksum is not the pinned standalone", () => {
|
||||
const target = {
|
||||
platform: "win32", arch: "x64",
|
||||
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", extract: "tar.gz",
|
||||
legacy: {
|
||||
id: "windows-fluentterminal-standalone",
|
||||
file: "mosh-client-win32-x64.exe",
|
||||
local: "win32-x64/mosh-client.exe",
|
||||
url: "https://example.test/mosh-client.exe",
|
||||
sha256: "abc",
|
||||
},
|
||||
};
|
||||
const asset = selectReleaseAsset(target, new Map([["mosh-client-win32-x64.exe", "def"]]));
|
||||
|
||||
assert.equal(asset.file, "mosh-client-win32-x64.exe");
|
||||
assert.equal(asset.local, "win32-x64/mosh-client.exe");
|
||||
assert.equal(asset.url, "https://example.test/mosh-client.exe");
|
||||
assert.equal(asset.sha256, "abc");
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries downloads the released Windows bundle by default", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client.exe": "exe",
|
||||
"mosh-client-win32-x64-dlls/cygwin1.dll": "dll",
|
||||
"terminfo/x/xterm-256color": "terminfo",
|
||||
});
|
||||
fs.mkdirSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls"), { recursive: true });
|
||||
fs.writeFileSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls", "cygwin1.dll"), "stale");
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-win32-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-win32-x64.tar.gz\n`,
|
||||
});
|
||||
|
||||
await execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
@@ -412,24 +204,24 @@ test("fetch-mosh-binaries downloads the released Windows bundle by default", asy
|
||||
});
|
||||
|
||||
assert.equal(fs.readFileSync(path.join(resDir, "win32-x64", "mosh-client.exe"), "utf8"), "exe");
|
||||
assert.equal(fs.readFileSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls", "cygwin1.dll"), "utf8"), "dll");
|
||||
assert.equal(fs.readFileSync(path.join(resDir, "win32-x64", "terminfo", "x", "xterm-256color"), "utf8"), "terminfo");
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls")), false);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "terminfo")), false);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries falls back to the legacy flat asset for older releases", async (t) => {
|
||||
test("fetch-mosh-binaries unpacks pure Linux MoshCatty tarball", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const flat = Buffer.from("legacy-binary");
|
||||
fs.mkdirSync(path.join(resDir, "linux-x64", "terminfo", "78"), { recursive: true });
|
||||
fs.writeFileSync(path.join(resDir, "linux-x64", "terminfo", "78", "xterm-256color"), "stale");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client": "linux-client",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-linux-x64": flat,
|
||||
SHA256SUMS: `${sha256(flat)} mosh-client-linux-x64\n`,
|
||||
"mosh-client-linux-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-linux-x64.tar.gz\n`,
|
||||
});
|
||||
|
||||
await execFileAsync(process.execPath, [script, "--platform=linux", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
@@ -437,92 +229,14 @@ test("fetch-mosh-binaries falls back to the legacy flat asset for older releases
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
assert.equal(fs.existsSync(path.join(resDir, "linux-x64", "mosh-client")), true);
|
||||
assert.equal(fs.readFileSync(path.join(resDir, "linux-x64", "mosh-client"), "utf8"), "legacy-binary");
|
||||
assert.equal(fs.readFileSync(path.join(resDir, "linux-x64", "mosh-client"), "utf8"), "linux-client");
|
||||
assert.equal(fs.existsSync(path.join(resDir, "linux-x64", "terminfo")), false);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries unpacks the Linux tarball with bundled terminfo", async (t) => {
|
||||
test("fetch-mosh-binaries rejects tarball without mosh-client", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client": "binary",
|
||||
"terminfo/x/xterm-256color": "terminfo",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-linux-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-linux-x64.tar.gz\n`,
|
||||
});
|
||||
|
||||
await execFileAsync(process.execPath, [script, "--platform=linux", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
assert.equal(fs.existsSync(path.join(resDir, "linux-x64", "mosh-client")), true);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "linux-x64", "terminfo", "x", "xterm-256color")), true);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries warns when the Linux tarball lacks terminfo", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client": "binary",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-linux-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-linux-x64.tar.gz\n`,
|
||||
});
|
||||
|
||||
const { stderr } = await execFileAsync(process.execPath, [script, "--platform=linux", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
assert.match(stderr, /did not contain terminfo for xterm-256color/);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "linux-x64", "mosh-client")), true);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries unpacks the Darwin tarball with bundled terminfo", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"mosh-client": "binary",
|
||||
"terminfo/x/xterm-256color": "terminfo",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-darwin-universal.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(tar)} mosh-client-darwin-universal.tar.gz\n`,
|
||||
});
|
||||
|
||||
await execFileAsync(process.execPath, [script, "--platform=darwin", "--arch=universal"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
});
|
||||
|
||||
assert.equal(fs.existsSync(path.join(resDir, "darwin-universal", "mosh-client")), true);
|
||||
assert.equal(fs.existsSync(path.join(resDir, "darwin-universal", "terminfo", "x", "xterm-256color")), true);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries rejects a Linux tarball without mosh-client", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, {
|
||||
"terminfo/x/xterm-256color": "terminfo",
|
||||
"README.txt": "no binary here",
|
||||
});
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-linux-x64.tar.gz": tar,
|
||||
@@ -533,7 +247,7 @@ test("fetch-mosh-binaries rejects a Linux tarball without mosh-client", async (t
|
||||
execFileAsync(process.execPath, [script, "--platform=linux", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
@@ -544,14 +258,36 @@ test("fetch-mosh-binaries rejects a Linux tarball without mosh-client", async (t
|
||||
);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries rejects symlinks inside Windows tarballs", { skip: process.platform === "win32" }, async (t) => {
|
||||
test("fetch-mosh-binaries fails when SHA256SUMS lacks the asset", async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const tar = makeTarGz(t, { "mosh-client.exe": "exe" });
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-win32-x64.tar.gz": tar,
|
||||
SHA256SUMS: `${sha256(Buffer.from("other"))} other-file\n`,
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
}),
|
||||
/no SHA256 entry/,
|
||||
);
|
||||
});
|
||||
|
||||
test("fetch-mosh-binaries rejects symlinks inside tarballs", { skip: process.platform === "win32" }, async (t) => {
|
||||
const resDir = path.join(makeTmp(t), "resources", "mosh");
|
||||
const srcDir = makeTmp(t);
|
||||
fs.writeFileSync(path.join(srcDir, "outside.exe"), "outside");
|
||||
fs.symlinkSync(path.join(srcDir, "outside.exe"), path.join(srcDir, "mosh-client.exe"));
|
||||
fs.mkdirSync(path.join(srcDir, "mosh-client-win32-x64-dlls"));
|
||||
fs.writeFileSync(path.join(srcDir, "mosh-client-win32-x64-dlls", "cygwin1.dll"), "dll");
|
||||
fs.writeFileSync(path.join(srcDir, "mosh-client.exe"), "exe");
|
||||
fs.symlinkSync("mosh-client.exe", path.join(srcDir, "link.exe"));
|
||||
const tarPath = path.join(makeTmp(t), "symlink.tar.gz");
|
||||
execFileSync("tar", ["-czf", tarPath, "-C", srcDir, "mosh-client.exe", "mosh-client-win32-x64-dlls"], { stdio: "pipe" });
|
||||
execFileSync("tar", ["-czf", tarPath, "-C", srcDir, "mosh-client.exe", "link.exe"], { stdio: "pipe" });
|
||||
const tar = fs.readFileSync(tarPath);
|
||||
const baseUrl = await serveAssets(t, {
|
||||
"mosh-client-win32-x64.tar.gz": tar,
|
||||
@@ -562,14 +298,13 @@ test("fetch-mosh-binaries rejects symlinks inside Windows tarballs", { skip: pro
|
||||
execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
|
||||
env: {
|
||||
...process.env,
|
||||
MOSH_BIN_RELEASE: "test",
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
MOSH_BIN_BASE_URL: baseUrl,
|
||||
MOSH_BIN_RES_DIR: path.join(makeTmp(t), "resources", "mosh"),
|
||||
MOSH_BIN_FORCE_WINDOWS_CYGWIN: "true",
|
||||
MOSH_BIN_RES_DIR: resDir,
|
||||
CI: "true",
|
||||
},
|
||||
stdio: "pipe",
|
||||
}),
|
||||
/symbolic link|did not contain mosh-client\.exe/,
|
||||
/symbolic link/,
|
||||
);
|
||||
});
|
||||
@@ -7,8 +7,6 @@ const buildWorkflow = fs.readFileSync(
|
||||
path.join(__dirname, "..", ".github", "workflows", "build.yml"),
|
||||
"utf8",
|
||||
);
|
||||
const moshLinuxScript = fs.readFileSync(path.join(__dirname, "build-mosh", "build-linux.sh"), "utf8");
|
||||
const moshMacScript = fs.readFileSync(path.join(__dirname, "build-mosh", "build-macos.sh"), "utf8");
|
||||
const etLinuxScript = fs.readFileSync(path.join(__dirname, "build-et", "build-linux.sh"), "utf8");
|
||||
const etMacScript = fs.readFileSync(path.join(__dirname, "build-et", "build-macos.sh"), "utf8");
|
||||
|
||||
@@ -134,17 +132,6 @@ test("build workflow builds Linux x64 native modules in a glibc 2.28 container",
|
||||
);
|
||||
});
|
||||
|
||||
test("mosh binary build scripts retry source downloads before failing CI", () => {
|
||||
for (const [name, script] of [
|
||||
["linux", moshLinuxScript],
|
||||
["macos", moshMacScript],
|
||||
]) {
|
||||
assert.match(script, /curl_retry\(\)/, `${name} mosh build must use retrying downloads`);
|
||||
assert.match(script, /--retry 8/, `${name} mosh build must retry transient HTTP failures`);
|
||||
assert.match(script, /--retry-max-time 600/, `${name} mosh build must bound retry time`);
|
||||
}
|
||||
});
|
||||
|
||||
test("et binary build scripts retry dependency configure and pin ninja", () => {
|
||||
for (const [name, script] of [
|
||||
["linux", etLinuxScript],
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
// Compute the platform-specific `extraResources` entry for bundling
|
||||
// mosh-client. Lives under scripts/ (eslint-ignored) so it can use
|
||||
// Node CommonJS globals freely; consumed from electron-builder.config.cjs.
|
||||
//
|
||||
// Binaries are produced by .github/workflows/build-mosh-binaries.yml and
|
||||
// downloaded into resources/mosh/<platform-arch>/ by
|
||||
// scripts/fetch-mosh-binaries.cjs (gated on MOSH_BIN_RELEASE).
|
||||
//
|
||||
// We only emit the directive when the binary is actually on disk so that
|
||||
// `npm run pack` keeps working without bundled mosh — for example, when
|
||||
// the developer skipped the fetch step or the relevant arch hasn't been
|
||||
// built yet.
|
||||
// Platform-specific electron-builder extraResources for the MoshCatty client.
|
||||
// Binaries are downloaded from binaricat/MoshCatty into resources/mosh/ by
|
||||
// scripts/fetch-mosh-binaries.cjs. Pure single-binary layout only.
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
@@ -21,10 +13,6 @@ function hasFile(file) {
|
||||
return fs.existsSync(file) && fs.statSync(file).isFile();
|
||||
}
|
||||
|
||||
function hasDir(dir) {
|
||||
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
|
||||
}
|
||||
|
||||
function moshExtraResources(platform) {
|
||||
const moshRoot = path.resolve(process.cwd(), "resources", "mosh");
|
||||
if (!fs.existsSync(moshRoot)) return [];
|
||||
@@ -32,52 +20,27 @@ function moshExtraResources(platform) {
|
||||
if (platform === "darwin") {
|
||||
const file = path.join(moshRoot, "darwin-universal", "mosh-client");
|
||||
if (!hasFile(file)) return [];
|
||||
const resources = [
|
||||
return [
|
||||
{ from: "resources/mosh/darwin-universal/", to: "mosh/", filter: ["mosh-client"] },
|
||||
];
|
||||
const terminfoDir = path.join(moshRoot, "darwin-universal", "terminfo");
|
||||
if (hasDir(terminfoDir)) {
|
||||
resources.push({ from: "resources/mosh/darwin-universal/terminfo/", to: "mosh/terminfo/", filter: ["**/*"] });
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
if (platform === "linux") {
|
||||
const arch = requestedArch();
|
||||
const file = path.join(moshRoot, `linux-${arch}`, "mosh-client");
|
||||
if (!hasFile(file)) return [];
|
||||
const resources = [
|
||||
return [
|
||||
{ from: `resources/mosh/linux-${arch}/`, to: "mosh/", filter: ["mosh-client"] },
|
||||
];
|
||||
const terminfoDir = path.join(moshRoot, `linux-${arch}`, "terminfo");
|
||||
if (hasDir(terminfoDir)) {
|
||||
resources.push({ from: `resources/mosh/linux-${arch}/terminfo/`, to: "mosh/terminfo/", filter: ["**/*"] });
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
if (platform === "win32") {
|
||||
// Windows normally ships the pinned runtime bundle. Keep DLL/terminfo
|
||||
// packaging optional so the standalone fallback remains packageable.
|
||||
const arch = requestedArch();
|
||||
const exe = path.join(moshRoot, `win32-${arch}`, "mosh-client.exe");
|
||||
const dllDir = path.join(moshRoot, `win32-${arch}`, `mosh-client-win32-${arch}-dlls`);
|
||||
if (!hasFile(exe)) return [];
|
||||
const resources = [
|
||||
return [
|
||||
{ from: `resources/mosh/win32-${arch}/`, to: "mosh/", filter: ["mosh-client.exe"] },
|
||||
];
|
||||
if (hasDir(dllDir)) {
|
||||
resources.push({
|
||||
from: `resources/mosh/win32-${arch}/mosh-client-win32-${arch}-dlls/`,
|
||||
to: `mosh/mosh-client-win32-${arch}-dlls/`,
|
||||
filter: ["**/*"],
|
||||
});
|
||||
}
|
||||
const terminfoDir = path.join(moshRoot, `win32-${arch}`, "terminfo");
|
||||
if (hasDir(terminfoDir)) {
|
||||
resources.push({ from: `resources/mosh/win32-${arch}/terminfo/`, to: "mosh/terminfo/", filter: ["**/*"] });
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
return [];
|
||||
|
||||
@@ -32,10 +32,11 @@ function writeFile(filePath) {
|
||||
fs.writeFileSync(filePath, "x");
|
||||
}
|
||||
|
||||
test("moshExtraResources returns concrete Linux arch paths (legacy bundle without terminfo)", (t) => {
|
||||
test("moshExtraResources packages pure Linux client only", (t) => {
|
||||
const root = makeTmp(t);
|
||||
withCwdAndArch(t, root, "x64");
|
||||
writeFile(path.join(root, "resources", "mosh", "linux-x64", "mosh-client"));
|
||||
writeFile(path.join(root, "resources", "mosh", "linux-x64", "terminfo", "x", "xterm-256color"));
|
||||
|
||||
const got = moshExtraResources("linux");
|
||||
assert.deepEqual(got, [
|
||||
@@ -43,20 +44,7 @@ test("moshExtraResources returns concrete Linux arch paths (legacy bundle withou
|
||||
]);
|
||||
});
|
||||
|
||||
test("moshExtraResources packages bundled terminfo on Linux when present", (t) => {
|
||||
const root = makeTmp(t);
|
||||
withCwdAndArch(t, root, "arm64");
|
||||
writeFile(path.join(root, "resources", "mosh", "linux-arm64", "mosh-client"));
|
||||
writeFile(path.join(root, "resources", "mosh", "linux-arm64", "terminfo", "x", "xterm-256color"));
|
||||
|
||||
const got = moshExtraResources("linux");
|
||||
assert.deepEqual(got, [
|
||||
{ from: "resources/mosh/linux-arm64/", to: "mosh/", filter: ["mosh-client"] },
|
||||
{ from: "resources/mosh/linux-arm64/terminfo/", to: "mosh/terminfo/", filter: ["**/*"] },
|
||||
]);
|
||||
});
|
||||
|
||||
test("moshExtraResources packages bundled terminfo on Darwin when present", (t) => {
|
||||
test("moshExtraResources packages pure Darwin client only", (t) => {
|
||||
const root = makeTmp(t);
|
||||
withCwdAndArch(t, root, "x64");
|
||||
writeFile(path.join(root, "resources", "mosh", "darwin-universal", "mosh-client"));
|
||||
@@ -65,11 +53,10 @@ test("moshExtraResources packages bundled terminfo on Darwin when present", (t)
|
||||
const got = moshExtraResources("darwin");
|
||||
assert.deepEqual(got, [
|
||||
{ from: "resources/mosh/darwin-universal/", to: "mosh/", filter: ["mosh-client"] },
|
||||
{ from: "resources/mosh/darwin-universal/terminfo/", to: "mosh/terminfo/", filter: ["**/*"] },
|
||||
]);
|
||||
});
|
||||
|
||||
test("moshExtraResources returns concrete Windows arch paths only when that arch exists", (t) => {
|
||||
test("moshExtraResources packages pure Windows client only (ignores dlls/terminfo)", (t) => {
|
||||
const root = makeTmp(t);
|
||||
withCwdAndArch(t, root, "x64");
|
||||
writeFile(path.join(root, "resources", "mosh", "win32-x64", "mosh-client.exe"));
|
||||
@@ -79,42 +66,8 @@ test("moshExtraResources returns concrete Windows arch paths only when that arch
|
||||
const got = moshExtraResources("win32");
|
||||
assert.deepEqual(got, [
|
||||
{ from: "resources/mosh/win32-x64/", to: "mosh/", filter: ["mosh-client.exe"] },
|
||||
{
|
||||
from: "resources/mosh/win32-x64/mosh-client-win32-x64-dlls/",
|
||||
to: "mosh/mosh-client-win32-x64-dlls/",
|
||||
filter: ["**/*"],
|
||||
},
|
||||
{ from: "resources/mosh/win32-x64/terminfo/", to: "mosh/terminfo/", filter: ["**/*"] },
|
||||
]);
|
||||
|
||||
process.env.npm_config_arch = "arm64";
|
||||
assert.deepEqual(moshExtraResources("win32"), []);
|
||||
});
|
||||
|
||||
test("moshExtraResources keeps legacy Windows bundles packageable", (t) => {
|
||||
const root = makeTmp(t);
|
||||
withCwdAndArch(t, root, "x64");
|
||||
writeFile(path.join(root, "resources", "mosh", "win32-x64", "mosh-client.exe"));
|
||||
writeFile(path.join(root, "resources", "mosh", "win32-x64", "mosh-client-win32-x64-dlls", "cygwin1.dll"));
|
||||
|
||||
const got = moshExtraResources("win32");
|
||||
assert.deepEqual(got, [
|
||||
{ from: "resources/mosh/win32-x64/", to: "mosh/", filter: ["mosh-client.exe"] },
|
||||
{
|
||||
from: "resources/mosh/win32-x64/mosh-client-win32-x64-dlls/",
|
||||
to: "mosh/mosh-client-win32-x64-dlls/",
|
||||
filter: ["**/*"],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("moshExtraResources packages standalone Windows mosh-client.exe", (t) => {
|
||||
const root = makeTmp(t);
|
||||
withCwdAndArch(t, root, "x64");
|
||||
writeFile(path.join(root, "resources", "mosh", "win32-x64", "mosh-client.exe"));
|
||||
|
||||
const got = moshExtraResources("win32");
|
||||
assert.deepEqual(got, [
|
||||
{ from: "resources/mosh/win32-x64/", to: "mosh/", filter: ["mosh-client.exe"] },
|
||||
]);
|
||||
});
|
||||
@@ -1,38 +1,88 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
//
|
||||
// Resolve the mosh-client binary release used by build-packages.
|
||||
// Resolve the MoshCatty mosh-client binary release used by packaging / dev.
|
||||
//
|
||||
// Priority:
|
||||
// 1. MOSH_BIN_RELEASE from workflow input / repository variable.
|
||||
// 2. Latest non-draft, non-prerelease GitHub Release whose tag is
|
||||
// mosh-bin-* in MOSH_BIN_OWNER/MOSH_BIN_REPO. By default this is a
|
||||
// dedicated sibling binary repository named Netcatty-mosh-bin.
|
||||
// moshcatty-* in MOSH_BIN_OWNER/MOSH_BIN_REPO (default binaricat/MoshCatty).
|
||||
//
|
||||
// In GitHub Actions, the resolved tag is written back to $GITHUB_ENV so
|
||||
// later steps can run scripts/fetch-mosh-binaries.cjs without duplicating
|
||||
// release discovery logic.
|
||||
// In GitHub Actions, the resolved tag is written to $GITHUB_ENV.
|
||||
|
||||
const fs = require("node:fs");
|
||||
const https = require("node:https");
|
||||
|
||||
const TAG_RE = /^mosh-bin-[A-Za-z0-9._-]+$/;
|
||||
// MoshCatty pure-Rust releases only.
|
||||
// Minimum 0.1.2: earlier Linux builds linked GLIBC 2.34 (above Netcatty floors).
|
||||
// Allow semver prerelease (-rc1) and build metadata (+meta); no path separators.
|
||||
const TAG_RE = /^moshcatty-[A-Za-z0-9._+-]+$/;
|
||||
const MIN_VERSION = { major: 0, minor: 1, patch: 2 };
|
||||
const MIN_TAG = `moshcatty-${MIN_VERSION.major}.${MIN_VERSION.minor}.${MIN_VERSION.patch}`;
|
||||
|
||||
function log(msg) {
|
||||
console.log(`[resolve-mosh-bin-release] ${msg}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse moshcatty-X.Y.Z with optional prerelease (-rc1) and build (+meta).
|
||||
* Returns null if not semver-ish.
|
||||
*/
|
||||
function parseMoshCattyVersion(tag) {
|
||||
const match = String(tag || "").trim().match(
|
||||
/^moshcatty-(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/,
|
||||
);
|
||||
if (!match) return null;
|
||||
return {
|
||||
major: Number(match[1]),
|
||||
minor: Number(match[2]),
|
||||
patch: Number(match[3]),
|
||||
// Present when tag is e.g. moshcatty-0.1.2-rc1 (semver: prerelease < final).
|
||||
prerelease: match[4] || null,
|
||||
};
|
||||
}
|
||||
|
||||
function compareCoreVersion(a, b) {
|
||||
if (a.major !== b.major) return a.major - b.major;
|
||||
if (a.minor !== b.minor) return a.minor - b.minor;
|
||||
return a.patch - b.patch;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when tag is usable for packaging (core version ≥ min, with semver
|
||||
* prerelease rules: X.Y.Z-rcN is below final X.Y.Z).
|
||||
*/
|
||||
function isAtLeastMinRelease(tag) {
|
||||
const version = parseMoshCattyVersion(tag);
|
||||
if (!version) return false;
|
||||
const core = compareCoreVersion(version, MIN_VERSION);
|
||||
if (core > 0) return true;
|
||||
if (core < 0) return false;
|
||||
// Equal to the floor: final only (no prerelease suffix).
|
||||
return !version.prerelease;
|
||||
}
|
||||
|
||||
function validateReleaseTag(tag) {
|
||||
const value = String(tag || "").trim();
|
||||
if (!TAG_RE.test(value)) {
|
||||
throw new Error(`invalid mosh binary release tag: ${tag}`);
|
||||
if (!TAG_RE.test(value) || !parseMoshCattyVersion(value)) {
|
||||
throw new Error(`invalid mosh binary release tag: ${tag} (expected moshcatty-X.Y.Z[(-pre)|(+build)])`);
|
||||
}
|
||||
if (!isAtLeastMinRelease(value)) {
|
||||
throw new Error(
|
||||
`mosh binary release ${value} is below minimum ${MIN_TAG} `
|
||||
+ "(Linux glibc floors: x64 ≤ 2.28, arm64 ≤ 2.31; 0.1.0/0.1.1 require GLIBC 2.34; "
|
||||
+ "prereleases of the floor e.g. 0.1.2-rc1 are not accepted)",
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseRepository(env) {
|
||||
const owner = env.MOSH_BIN_OWNER || (env.GITHUB_REPOSITORY || "").split("/")[0] || "binaricat";
|
||||
const repo = env.MOSH_BIN_REPO || "Netcatty-mosh-bin";
|
||||
// Canonical default is always binaricat/MoshCatty. Do not derive owner from
|
||||
// GITHUB_REPOSITORY — fork packaging would otherwise look for
|
||||
// <fork-owner>/MoshCatty and fail. Override only via MOSH_BIN_OWNER/REPO.
|
||||
const owner = env.MOSH_BIN_OWNER || "binaricat";
|
||||
const repo = env.MOSH_BIN_REPO || "MoshCatty";
|
||||
return { owner, repo };
|
||||
}
|
||||
|
||||
@@ -46,8 +96,10 @@ function pickLatestMoshBinRelease(releases) {
|
||||
return releases
|
||||
.map((release, index) => ({ release, index }))
|
||||
.filter(({ release }) => {
|
||||
const tag = String(release?.tag_name || "");
|
||||
return release
|
||||
&& TAG_RE.test(String(release.tag_name || ""))
|
||||
&& TAG_RE.test(tag)
|
||||
&& isAtLeastMinRelease(tag)
|
||||
&& release.draft !== true
|
||||
&& release.prerelease !== true;
|
||||
})
|
||||
@@ -122,7 +174,7 @@ async function loadReleases(env, request = requestJsonWithHeaders) {
|
||||
const { owner, repo } = parseRepository(env);
|
||||
const apiBase = (env.GITHUB_API_URL || "https://api.github.com").replace(/\/+$/, "");
|
||||
let url = `${apiBase}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/releases?per_page=100`;
|
||||
log(`looking up latest mosh-bin-* release in ${owner}/${repo}`);
|
||||
log(`looking up latest moshcatty-* release in ${owner}/${repo}`);
|
||||
const releases = [];
|
||||
const seen = new Set();
|
||||
while (url) {
|
||||
@@ -159,7 +211,8 @@ async function main(env = process.env) {
|
||||
const release = pickLatestMoshBinRelease(releases);
|
||||
if (!release) {
|
||||
throw new Error(
|
||||
"could not find a non-draft mosh-bin-* release in the mosh binary repository. Publish build-mosh-binaries artifacts with release_tag (for example mosh-bin-1.4.0-1) before packaging.",
|
||||
`could not find a non-draft ${MIN_TAG}+ release in binaricat/MoshCatty. `
|
||||
+ `Publish a MoshCatty GitHub Release (e.g. ${MIN_TAG}) before packaging.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -180,7 +233,10 @@ module.exports = {
|
||||
loadReleases,
|
||||
parseNextLink,
|
||||
validateReleaseTag,
|
||||
parseMoshCattyVersion,
|
||||
isAtLeastMinRelease,
|
||||
parseRepository,
|
||||
pickLatestMoshBinRelease,
|
||||
MIN_TAG,
|
||||
main,
|
||||
};
|
||||
@@ -11,6 +11,8 @@ const {
|
||||
parseNextLink,
|
||||
pickLatestMoshBinRelease,
|
||||
validateReleaseTag,
|
||||
isAtLeastMinRelease,
|
||||
MIN_TAG,
|
||||
} = require("./resolve-mosh-bin-release.cjs");
|
||||
|
||||
function makeTmp(t) {
|
||||
@@ -19,17 +21,37 @@ function makeTmp(t) {
|
||||
return dir;
|
||||
}
|
||||
|
||||
test("validateReleaseTag accepts only mosh binary release tags", () => {
|
||||
assert.equal(validateReleaseTag("mosh-bin-1.4.0-1"), "mosh-bin-1.4.0-1");
|
||||
test("validateReleaseTag accepts only moshcatty-* tags at min version", () => {
|
||||
assert.equal(validateReleaseTag("moshcatty-0.1.2"), "moshcatty-0.1.2");
|
||||
assert.equal(validateReleaseTag("moshcatty-0.2.0"), "moshcatty-0.2.0");
|
||||
assert.equal(validateReleaseTag("moshcatty-0.1.3-rc1"), "moshcatty-0.1.3-rc1");
|
||||
assert.equal(validateReleaseTag("moshcatty-0.1.2+build.1"), "moshcatty-0.1.2+build.1");
|
||||
assert.throws(() => validateReleaseTag("mosh-bin-1.4.0-1"), /invalid mosh binary release tag/);
|
||||
assert.throws(() => validateReleaseTag("v1.2.3"), /invalid mosh binary release tag/);
|
||||
assert.throws(() => validateReleaseTag("mosh-bin-../bad"), /invalid mosh binary release tag/);
|
||||
assert.throws(() => validateReleaseTag("moshcatty-../bad"), /invalid mosh binary release tag/);
|
||||
assert.throws(() => validateReleaseTag("moshcatty-not-a-version"), /invalid mosh binary release tag/);
|
||||
assert.throws(() => validateReleaseTag("moshcatty-0.1.0"), /below minimum/);
|
||||
assert.throws(() => validateReleaseTag("moshcatty-0.1.1"), /below minimum/);
|
||||
assert.throws(() => validateReleaseTag("moshcatty-0.1.2-rc1"), /below minimum/);
|
||||
});
|
||||
|
||||
test("parseRepository falls back to the dedicated mosh binary repository", () => {
|
||||
assert.deepEqual(parseRepository({}), { owner: "binaricat", repo: "Netcatty-mosh-bin" });
|
||||
test("isAtLeastMinRelease enforces moshcatty-0.1.2 floor with semver prerelease rules", () => {
|
||||
assert.equal(MIN_TAG, "moshcatty-0.1.2");
|
||||
assert.equal(isAtLeastMinRelease("moshcatty-0.1.1"), false);
|
||||
assert.equal(isAtLeastMinRelease("moshcatty-0.1.2"), true);
|
||||
// Prerelease of the floor sorts below the final floor release.
|
||||
assert.equal(isAtLeastMinRelease("moshcatty-0.1.2-rc1"), false);
|
||||
// Above the floor, prereleases are fine.
|
||||
assert.equal(isAtLeastMinRelease("moshcatty-0.1.3-rc1"), true);
|
||||
assert.equal(isAtLeastMinRelease("moshcatty-0.1.2+build.1"), true);
|
||||
assert.equal(isAtLeastMinRelease("moshcatty-not-a-version"), false);
|
||||
});
|
||||
|
||||
test("parseRepository defaults to binaricat/MoshCatty (ignores GITHUB_REPOSITORY fork owner)", () => {
|
||||
assert.deepEqual(parseRepository({}), { owner: "binaricat", repo: "MoshCatty" });
|
||||
assert.deepEqual(parseRepository({ GITHUB_REPOSITORY: "owner/project" }), {
|
||||
owner: "owner",
|
||||
repo: "Netcatty-mosh-bin",
|
||||
owner: "binaricat",
|
||||
repo: "MoshCatty",
|
||||
});
|
||||
assert.deepEqual(
|
||||
parseRepository({ GITHUB_REPOSITORY: "owner/project", MOSH_BIN_OWNER: "bin", MOSH_BIN_REPO: "binaries" }),
|
||||
@@ -37,16 +59,17 @@ test("parseRepository falls back to the dedicated mosh binary repository", () =>
|
||||
);
|
||||
});
|
||||
|
||||
test("pickLatestMoshBinRelease ignores non-packaging releases", () => {
|
||||
test("pickLatestMoshBinRelease ignores non-moshcatty and pre-0.1.2 tags", () => {
|
||||
const got = pickLatestMoshBinRelease([
|
||||
{ tag_name: "v1.0.0", published_at: "2026-03-01T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-3", draft: true, published_at: "2026-04-01T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-4", prerelease: true, published_at: "2026-04-02T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-1", published_at: "2026-02-01T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-2", published_at: "2026-03-01T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-2", published_at: "2026-06-01T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.2", draft: true, published_at: "2026-07-11T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.0", published_at: "2026-05-01T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.1", published_at: "2026-07-10T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.2", published_at: "2026-07-10T12:00:00Z" },
|
||||
]);
|
||||
|
||||
assert.equal(got, "mosh-bin-1.4.0-2");
|
||||
assert.equal(got, "moshcatty-0.1.2");
|
||||
});
|
||||
|
||||
test("parseNextLink reads the next GitHub pagination URL", () => {
|
||||
@@ -69,7 +92,7 @@ test("loadReleases follows GitHub pagination until the last page", async () => {
|
||||
requested.push(url);
|
||||
if (url.includes("page=2")) {
|
||||
return {
|
||||
json: [{ tag_name: "mosh-bin-1.4.0-1", published_at: "2026-01-01T00:00:00Z" }],
|
||||
json: [{ tag_name: "moshcatty-0.1.2", published_at: "2026-01-01T00:00:00Z" }],
|
||||
headers: {},
|
||||
};
|
||||
}
|
||||
@@ -81,7 +104,7 @@ test("loadReleases follows GitHub pagination until the last page", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
assert.deepEqual(got.map((release) => release.tag_name), ["v1.0.0", "mosh-bin-1.4.0-1"]);
|
||||
assert.deepEqual(got.map((release) => release.tag_name), ["v1.0.0", "moshcatty-0.1.2"]);
|
||||
assert.equal(requested.length, 2);
|
||||
});
|
||||
|
||||
@@ -99,34 +122,45 @@ test("main keeps an explicit MOSH_BIN_RELEASE and exports it", async (t) => {
|
||||
const githubEnv = path.join(makeTmp(t), "github-env");
|
||||
|
||||
const got = await main({
|
||||
MOSH_BIN_RELEASE: "mosh-bin-1.4.0-1",
|
||||
MOSH_BIN_RELEASE: "moshcatty-0.1.2",
|
||||
GITHUB_ENV: githubEnv,
|
||||
});
|
||||
|
||||
assert.equal(got, "mosh-bin-1.4.0-1");
|
||||
assert.equal(fs.readFileSync(githubEnv, "utf8"), "MOSH_BIN_RELEASE=mosh-bin-1.4.0-1\n");
|
||||
assert.equal(got, "moshcatty-0.1.2");
|
||||
assert.equal(fs.readFileSync(githubEnv, "utf8"), "MOSH_BIN_RELEASE=moshcatty-0.1.2\n");
|
||||
});
|
||||
|
||||
test("main resolves the latest release from the release list and exports it", async (t) => {
|
||||
test("main rejects explicit pre-0.1.2 MOSH_BIN_RELEASE", async () => {
|
||||
await assert.rejects(
|
||||
main({ MOSH_BIN_RELEASE: "moshcatty-0.1.1" }),
|
||||
/below minimum/,
|
||||
);
|
||||
});
|
||||
|
||||
test("main resolves the latest moshcatty release from the list and exports it", async (t) => {
|
||||
const githubEnv = path.join(makeTmp(t), "github-env");
|
||||
const got = await main({
|
||||
GITHUB_ENV: githubEnv,
|
||||
MOSH_BIN_RELEASES_JSON: JSON.stringify([
|
||||
{ tag_name: "mosh-bin-1.4.0-1", published_at: "2026-01-01T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-2", published_at: "2026-02-01T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.0", published_at: "2026-01-01T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.1", published_at: "2026-07-10T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.2", published_at: "2026-07-10T12:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-2", published_at: "2026-08-01T00:00:00Z" },
|
||||
]),
|
||||
});
|
||||
|
||||
assert.equal(got, "mosh-bin-1.4.0-2");
|
||||
assert.equal(fs.readFileSync(githubEnv, "utf8"), "MOSH_BIN_RELEASE=mosh-bin-1.4.0-2\n");
|
||||
assert.equal(got, "moshcatty-0.1.2");
|
||||
assert.equal(fs.readFileSync(githubEnv, "utf8"), "MOSH_BIN_RELEASE=moshcatty-0.1.2\n");
|
||||
});
|
||||
|
||||
test("main fails when no usable release exists", async () => {
|
||||
test("main fails when no usable moshcatty release exists", async () => {
|
||||
await assert.rejects(
|
||||
main({
|
||||
MOSH_BIN_RELEASES_JSON: JSON.stringify([
|
||||
{ tag_name: "v1.0.0", published_at: "2026-01-01T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-1", draft: true, published_at: "2026-02-01T00:00:00Z" },
|
||||
{ tag_name: "mosh-bin-1.4.0-1", published_at: "2026-02-01T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.1", published_at: "2026-02-01T00:00:00Z" },
|
||||
{ tag_name: "moshcatty-0.1.2", draft: true, published_at: "2026-02-01T00:00:00Z" },
|
||||
]),
|
||||
}),
|
||||
/could not find/,
|
||||
|
||||
Reference in new issue
Block a user