crosscode script: deploy, status, install, adopt (Events 2.2.0, plan §4-5)

One script for installing, updating and moving church installs, replacing
hope-events' scripts/deploy.sh and install.sh:

- deploy <church> [events] / --every-church, with --version, --main, --check
  and --allow-local-changes: checks every product first (files changed by
  hand, Node, release requirements from WHATS-NEW.md headings), then each
  product in order with backup, checkout, install, migrate, build, PM2 reload
  and a /health version check; a failure rolls that product back and stops.
- status [<church>]: checked-out and latest release, /health, and the old
  folder kept after adopt.
- install <church> --products events --domain <address>: a new church under
  /var/www/sites/<church>, writing church.env.
- adopt <church> --events-dir <old> builds the monorepo checkout next to the
  running install and switches PM2 over; adopt --undo goes back to it.

Product hooks live in scripts/products/events.sh. shellcheck (lint:scripts)
and 47 bats tests (test:scripts) are part of npm run check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 19:17:06 +02:00
co-authored by Claude Opus 5.5
parent f174285711
commit c442fe0d42
16 changed files with 3111 additions and 7 deletions
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env bats
# The crosscode entry script: help, and the argument checks that run before anything needs root.
setup() {
export CROSSCODE_NO_UPDATE=1
CC="$BATS_TEST_DIRNAME/../crosscode"
}
@test "help lists the commands" {
run bash "$CC" help
[ "$status" -eq 0 ]
[[ "$output" == *"crosscode deploy <church>"* ]]
[[ "$output" == *"crosscode adopt <church> --undo"* ]]
}
@test "help <command> shows that command's options" {
run bash "$CC" help deploy
[ "$status" -eq 0 ]
[[ "$output" == *"--every-church"* ]]
run bash "$CC" adopt --help
[ "$status" -eq 0 ]
[[ "$output" == *"--events-dir"* ]]
}
@test "an unknown command fails" {
run bash "$CC" frobnicate
[ "$status" -eq 1 ]
[[ "$output" == *'Unknown command "frobnicate"'* ]]
}
@test "the copy it runs from is removed afterwards" {
before="$(find /tmp -maxdepth 1 -name 'crosscode.*' 2>/dev/null | wc -l)"
run bash "$CC" help
after="$(find /tmp -maxdepth 1 -name 'crosscode.*' 2>/dev/null | wc -l)"
[ "$before" -eq "$after" ]
}
@test "deploy refuses bad arguments before touching anything" {
run bash "$CC" deploy hopefamily events --version events@2.2
[ "$status" -eq 1 ]
[[ "$output" == *"expected <product>@<x.y.z>"* ]]
run bash "$CC" deploy hopefamily --version events@2.2.0
[ "$status" -eq 1 ]
[[ "$output" == *"name events as well"* ]]
run bash "$CC" deploy hopefamily events --main --version events@2.2.0
[ "$status" -eq 1 ]
[[ "$output" == *"not both"* ]]
run bash "$CC" deploy hopefamily calendar
[ "$status" -eq 1 ]
[[ "$output" == *'Unknown product "calendar"'* ]]
run bash "$CC" deploy hopefamily --frobnicate
[ "$status" -eq 1 ]
run bash "$CC" deploy events --every-church
[ "$status" -eq 1 ]
[[ "$output" != *"doesn't take a church name"* ]]
run bash "$CC" deploy hopefamily --every-church
[ "$status" -eq 1 ]
[[ "$output" == *"doesn't take a church name"* ]]
}
@test "install and adopt check their arguments" {
run bash "$CC" install Hope --products events --domain hope.co.za --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"isn't a church name"* ]]
run bash "$CC" install hope --products website --domain hope.co.za --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"can only install events"* ]]
run bash "$CC" install hope --products events --domain hope.co.za
[ "$status" -eq 1 ]
[[ "$output" == *"--email is required"* ]]
run bash "$CC" adopt hope
[ "$status" -eq 1 ]
[[ "$output" == *"--events-dir is required"* ]]
run bash "$CC" adopt hope --events-dir /var/www/hope-events --version 2.2.0
[ "$status" -eq 1 ]
[[ "$output" == *"expected events@x.y.z"* ]]
}