rouse-context/deploy/deploy.sh
monkopedia-coder 0d15ef1914
Triage the masked-return findings and enable the two checks (#657) (#682)
`-o check-extra-masked-returns,check-set-e-suppressed` is now on in
scripts/check-shell-lint.sh, in both phases: phase 1 passes the options to
shellcheck directly, phase 2 hands them through actionlint to the same
version-asserted binary, so the inline `run:` shell cannot drift to a weaker
standard than the `*.sh` next to it.

27 sites were live on this base and each was decided on its own terms, not
silenced: 19 restructured so the status is checked, 5 kept behind an explicit
`|| true` and 3 behind a targeted `disable=`, every one of the 8 with a comment
saying why the discarded status is genuinely uninteresting. In all 8 the masked
command is the diagnostic half of a failure that has ALREADY been decided, and
letting its status escape would kill the script between the header and the
verdict -- the #628 shape.

Three of the restructures were not cosmetic. Measured against the old code:

  * check-zombie-screens.sh with a stubbed-failing `awk` printed
    "OK: no zombie screens" and exited 0 over a tree containing one. It now
    names the file it could not read and fails.
  * deploy/deploy.sh with a stubbed-failing `du` printed "Binary size:  ",
    scp'd the binary to production, restarted the unit and exited 0. It now
    stops with du's own reason, before the copy.
  * backfill-relay-secrets.sh printed "[set] NAME ( bytes)" for a file it
    could not read and let the failed `gh secret set` pass for a successful
    one. It now says "[fail] ... NOT pushed" and does not push.

Every restructured gate was re-run against an input that must produce a
finding, and the finding is still PRINTED rather than the gate dying first:
check-apk-distribution.sh (three fixtures, byte-identical output, including
the path where the diagnostic grep itself matches nothing and exits 1),
check-roborazzi-step-order.sh, check-zombie-screens.sh, the release.yml
changelog step (four fixtures) and the ci.yml diagnostic with no shellcheck
on PATH.

#678 is deliberately untouched: check-roborazzi-step-order.sh still exits 1
with zero bytes on a workflow with no `jobs:` key and on `jobs: {}`, before
and after, byte for byte. Fixing it here would have buried it.

The self-test grows from 21 to 26 cases: a red case for SC2312 and one for
SC2310 (both clean at the default severity this gate used before, so a red is
evidence the FLAG is on and not merely that the linter ran), a green case
carrying the same two shapes with their statuses handled, and a red/green pair
for phase 2 proving the options reach the inline `run:` shell. Mutation-tested:
dropping `-o` from phase 1 fails exactly the two phase-1 reds, dropping it from
the phase-2 command string fails exactly the phase-2 red, and both green twins
stay green through both mutations.

`-o all` stays off: 637 findings, and after this change 100% of them pure style
(591 SC2250, 46 SC2292).

Full gate suite green before and after -- 6 suites, 88 cases before, 93 after,
the +5 all in check-shell-lint-test.sh.

Closes #657


Claude-Session: https://claude.ai/code/session_01YYSPuh9bZEJkrzvnEpY1QK

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 13:59:17 -04:00

47 lines
1.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# Deploy the relay binary to the VPS.
# Usage: ./deploy.sh [user@host]
set -euo pipefail
REMOTE="${1:-relay@relay.rousecontext.com}"
BINARY="relay/target/x86_64-unknown-linux-musl/release/rouse-relay"
echo "=== Building relay (musl static binary) ==="
cd relay
cargo build --release --target x86_64-unknown-linux-musl
cd ..
if [ ! -f "$BINARY" ]; then
echo "Error: binary not found at $BINARY"
echo "Make sure you have the musl target installed: rustup target add x86_64-unknown-linux-musl"
exit 1
fi
# Assigned, then printed: substituted straight into the `echo`, the status of
# `du` (and of `cut`) is thrown away, so a binary that became unreadable between
# the existence check above and here would print "Binary size: " and this
# script would go on to `scp` it to production anyway -- measured against this
# script with a `du` stubbed to fail: it printed "Binary size: ", copied the
# binary, restarted the unit and exited 0. As an assignment the
# pipeline's status is `set -e`-visible -- and `du` has already written its own
# reason to stderr, so the deploy stops WITH a diagnosis rather than the
# exit-1-in-silence shape (#628).
binary_size=$(du -h "$BINARY" | cut -f1)
echo "=== Binary size: $binary_size ==="
echo "=== Deploying to $REMOTE ==="
scp "$BINARY" "$REMOTE":/opt/rouse-relay/rouse-relay.new
scp deploy/relay.toml.production "$REMOTE":/etc/rouse-relay/relay.toml
scp deploy/relay.service "$REMOTE":/tmp/relay.service
ssh "$REMOTE" bash -s <<'REMOTE_SCRIPT'
set -euo pipefail
sudo mv /opt/rouse-relay/rouse-relay.new /opt/rouse-relay/rouse-relay
sudo chmod +x /opt/rouse-relay/rouse-relay
sudo cp /tmp/relay.service /etc/systemd/system/rouse-relay.service
sudo systemctl daemon-reload
sudo systemctl restart rouse-relay
sleep 2
sudo systemctl status rouse-relay --no-pager
echo "=== Deploy complete ==="
REMOTE_SCRIPT