Files
J621/deploy/push_desktop.sh
JakeBreath 7ca84f4fea
CI / Backend tests (push) Successful in 2m41s
CI / Frontend build & lint (push) Successful in 25s
Point desktop updates at the Gitea release feed
The updater now resolves the newest non-draft desktop-v* release through the
Gitea API at check time (J621_UPDATE_REPO, lowercase because the API path is
case-sensitive), picks the platform's latest*.yml asset and uses that release
as a generic electron-updater feed; J621_UPDATE_URL still overrides
everything. Verified against the live API: release picked, yml fetched,
artifact HEAD 200.

electron-builder's publish.url is now metadata only (still needed so the
build emits latest*.yml). Docs updated: CD release assets are the feed, the
website /desktop/ feed only matters for installs before 0.1.2.
2026-09-23 22:00:49 -05:00

127 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
# Build the J621 desktop packages, optionally publish them to the website
# feed.
#
# Desktop updates no longer depend on this: the app resolves the newest
# `desktop-v*` release on Gitea at check time (see desktop/README.md). This
# script builds the packages and can copy them to deploy/data/desktop, which
# the frontend nginx mounts read-only and serves at /desktop/ for manual
# downloads and for pre-0.1.2 installs.
#
# Usage: ./push_desktop.sh [--win] [--no-build] [--local] [--host user@server:/path]
# --win also cross-build the Windows NSIS installer (needs wine)
# --no-build publish what is already in desktop/release/
# --local only publish locally, skip the remote copy
# --host override the remote deploy checkout
#
# The remote copy defaults to $J621_DESKTOP_FEED_HOST, or
# jakerasp:/home/jake/servers/J621 when that is not set.
set -euo pipefail
cd "$(dirname "$0")/.."
DEFAULT_REMOTE="jakerasp:/home/jake/servers/J621"
BUILD=1
WIN=0
REMOTE="${J621_DESKTOP_FEED_HOST:-$DEFAULT_REMOTE}"
while [ $# -gt 0 ]; do
case "$1" in
--win) WIN=1 ;;
--no-build) BUILD=0 ;;
--local) REMOTE="" ;;
--host) REMOTE="${2:?--host needs user@server:/path}"; shift ;;
*)
echo "usage: $0 [--win] [--no-build] [--local] [--host user@server:/path]" >&2
exit 2
;;
esac
shift
done
if [ -n "$REMOTE" ] && [ "$REMOTE" = "${REMOTE#*:}" ]; then
echo "--host needs user@server:/path (got '$REMOTE')" >&2
exit 2
fi
if [ "$BUILD" = 1 ]; then
echo "==> Building Linux packages (deb + pacman) ..."
npm --prefix desktop run dist:linux
if [ "$WIN" = 1 ]; then
echo "==> Cross-building the Windows installer (wine) ..."
npm --prefix desktop run dist:win
fi
fi
FEED=deploy/data/desktop
mkdir -p "$FEED"
shopt -s nullglob
VERSION="$(node -p "require('./desktop/package.json').version")"
deb=(desktop/release/*"$VERSION"*.deb)
zst=(desktop/release/*"$VERSION"*.pkg.tar.zst)
linux_meta=(desktop/release/latest-linux.yml)
win_exe=("desktop/release/J621 Setup ${VERSION}"*.exe)
win_meta=(desktop/release/latest.yml)
blockmaps=(desktop/release/*"$VERSION"*.exe.blockmap)
if [ "${#deb[@]}" -eq 0 ] && [ "${#zst[@]}" -eq 0 ]; then
echo "No $VERSION artifacts in desktop/release/ — run without --no-build first." >&2
exit 1
fi
# Replace the previous release's metadata and drop older installers from the
# feed: latest*.yml only ever points at the current version.
rm -f "$FEED"/latest-linux.yml "$FEED"/latest.yml
old=("$FEED"/*.deb "$FEED"/*.pkg.tar.zst "$FEED"/"J621 Setup "*.exe "$FEED"/*.exe.blockmap)
for file in "${old[@]}"; do
case "$(basename "$file")" in
*"$VERSION"*) ;;
*) echo " pruning $(basename "$file")"; rm -f "$file" ;;
esac
done
cp -f "${deb[@]}" "${zst[@]}" "${linux_meta[@]}" "$FEED"/ 2>/dev/null || true
if [ "${#win_exe[@]}" -gt 0 ]; then
cp -f "${win_exe[@]}" "${win_meta[@]}" "${blockmaps[@]}" "$FEED"/ 2>/dev/null || true
fi
echo "==> Published to $FEED:"
ls -1sh "$FEED" | sed 's/^/ /'
if [ -n "$REMOTE" ]; then
REMOTE_TARGET="${REMOTE%%:*}"
REMOTE_ROOT="${REMOTE#*:}"
REMOTE_FEED="${REMOTE_ROOT%/}/deploy/data/desktop"
echo
echo "==> Copying the feed to $REMOTE_TARGET:$REMOTE_FEED ..."
if ! ssh "$REMOTE_TARGET" "mkdir -p '$REMOTE_FEED'"; then
echo "ssh to $REMOTE_TARGET failed; nothing was copied." >&2
exit 1
fi
# The remote feed keeps only the current version, like the local one.
if ! ssh "$REMOTE_TARGET" \
"find '$REMOTE_FEED' -maxdepth 1 -type f \\( -name '*.deb' -o -name '*.pkg.tar.zst' -o -name '*.exe' -o -name '*.exe.blockmap' \\) ! -name '*$VERSION*' -exec rm -f {} +"; then
echo "==> Could not prune old installers on $REMOTE_TARGET (continuing)." >&2
fi
transferred=0
if command -v rsync >/dev/null 2>&1; then
if rsync -a --info=progress2 "$FEED"/ "$REMOTE_TARGET:$REMOTE_FEED/"; then
transferred=1
else
echo "==> rsync did not work (missing on the server?); trying tar over ssh ..."
fi
fi
if [ "$transferred" -eq 0 ]; then
if ! tar -C "$FEED" -cf - . |
ssh "$REMOTE_TARGET" "tar -C '$REMOTE_FEED' -xf -"; then
echo "Copy to $REMOTE_TARGET:$REMOTE_FEED failed." >&2
exit 1
fi
fi
echo "==> Feed live at $REMOTE_TARGET:$REMOTE_FEED (no restart needed)."
fi
echo
echo "Served read-only by the frontend nginx at /desktop/ (no restart needed):"
echo " https://<frontend-host>/desktop/latest-linux.yml"