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
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env bats
# adopt's helpers that don't need a server: rewriting the PM2 config, and finding the install's
# own data files. Run with `npm run test:scripts`.
setup() {
# shellcheck source=../lib/common.sh
source "$BATS_TEST_DIRNAME/../lib/common.sh"
# shellcheck source=../lib/adopt.sh
source "$BATS_TEST_DIRNAME/../lib/adopt.sh"
TMP="$BATS_TEST_TMPDIR"
}
@test "rewrite_ecosystem points absolute paths at the new app folder" {
run rewrite_ecosystem /var/www/hope-events /var/www/sites/hope/events/apps/events <<'EOF'
module.exports = { apps: [
{ name: 'hope-events-backend', cwd: '/var/www/hope-events/backend', script: 'src/index.js' },
{ name: 'hope-events-frontend', cwd: "/var/www/hope-events/frontend", script: 'npm', args: 'start -- -p 3000' },
{ name: 'x', cwd: `/var/www/hope-events`, out_file: '/var/www/hope-events2/log' },
] };
EOF
[[ "$output" == *"cwd: '/var/www/sites/hope/events/apps/events/backend'"* ]]
[[ "$output" == *'cwd: "/var/www/sites/hope/events/apps/events/frontend"'* ]]
[[ "$output" == *'cwd: `/var/www/sites/hope/events/apps/events`'* ]]
# A different folder that only starts the same isn't touched.
[[ "$output" == *"'/var/www/hope-events2/log'"* ]]
[[ "$output" == *"name: 'hope-events-backend'"* ]]
}
@test "rewrite_ecosystem leaves __dirname configs alone" {
input="$(cat "$BATS_TEST_DIRNAME/../../apps/events/ecosystem.config.example.js")"
run rewrite_ecosystem /var/www/hope-events /var/www/sites/hope/events/apps/events <<< "$input"
[ "$output" = "$input" ]
}
@test "rewrite_ecosystem copes with dots and other characters in paths" {
run rewrite_ecosystem /opt/hope.events /srv/a\&b <<'EOF'
cwd: '/opt/hope.events/backend', other: '/opt/hopexevents/backend'
EOF
[ "$output" = "cwd: '/srv/a&b/backend', other: '/opt/hopexevents/backend'" ]
}
@test "ignored_files_in lists the install's own data files, not tracked ones" {
git init -q "$TMP/old"
cd "$TMP/old"
mkdir -p backend/data
printf 'backend/data/banner.json\n' > .gitignore
echo '{}' > backend/data/defaults.json
git add . && git -c user.name=t -c user.email=t@t commit -q -m one
echo '{}' > backend/data/banner.json
run ignored_files_in "$TMP/old" backend/data
[ "$output" = "backend/data/banner.json" ]
}
+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"* ]]
}
+261
View File
@@ -0,0 +1,261 @@
#!/usr/bin/env bats
# The parts of the crosscode script that don't need a server: versions, tags, WHATS-NEW.md
# requirements, church.env and .env reading. Run with `npm run test:scripts`.
setup() {
# shellcheck source=../lib/common.sh
source "$BATS_TEST_DIRNAME/../lib/common.sh"
TMP="$BATS_TEST_TMPDIR"
}
# ── version_ge ──────────────────────────────────────────────────────────────────────────────
@test "version_ge compares x.y.z numerically" {
version_ge 1.2.0 1.2.0
version_ge 1.10.0 1.9.9
version_ge 2.0.0 1.99.99
run version_ge 1.9.0 1.10.0
[ "$status" -eq 1 ]
run version_ge 2.1.1 2.2.0
[ "$status" -eq 1 ]
}
@test "version_ge puts a prerelease below its release" {
version_ge 2.2.0 2.2.0-test
run version_ge 2.2.0-test 2.2.0
[ "$status" -eq 1 ]
version_ge 2.2.0-rc2 2.2.0-rc1
version_ge 2.2.0-test 2.1.9
}
@test "version_ge refuses something that isn't a version" {
run version_ge abc 1.0.0
[ "$status" -eq 2 ]
}
# ── tags ────────────────────────────────────────────────────────────────────────────────────
@test "latest_tag_from takes the newest release of that product only" {
run latest_tag_from events <<'EOF'
events@2.2.0
events@2.10.0
events@2.9.3
events@3.0.0-test
website@9.0.0
contracts@1.1.0
eventsx@4.0.0
EOF
[ "$status" -eq 0 ]
[ "$output" = "events@2.10.0" ]
}
@test "latest_tag_from is empty without releases" {
run latest_tag_from events <<'EOF'
events@2.2.0-test
contracts@1.0.0
EOF
[ "$output" = "" ]
}
@test "latest_tag and checkout_ref read a real checkout" {
git init -q "$TMP/repo"
cd "$TMP/repo"
git -c user.name=t -c user.email=t@t commit -q --allow-empty -m one
git tag events@2.2.0
git tag contracts@1.1.0
git -c user.name=t -c user.email=t@t commit -q --allow-empty -m two
git tag events@2.2.1
git tag events@2.3.0-test
[ "$(latest_tag "$TMP/repo" events)" = "events@2.2.1" ]
[ "$(checkout_ref "$TMP/repo" events)" = "events@2.2.1" ]
git checkout -q --detach events@2.2.0
[ "$(checkout_ref "$TMP/repo" events)" = "events@2.2.0" ]
git -c user.name=t -c user.email=t@t commit -q --allow-empty -m three
[ "$(checkout_ref "$TMP/repo" events)" = "$(git rev-parse --short HEAD)" ]
[ "$(tag_version events@2.2.1)" = "2.2.1" ]
}
# ── WHATS-NEW.md requirements ───────────────────────────────────────────────────────────────
whatsnew() {
cat <<'EOF'
# What's new in Cross Events
<!--
How this file is used: … Each version is a "## 1.2.3" heading; add "— urgent" …
## 9.9.9 — requires accounts 9.9.9
-->
## 3.1.0 — urgent — requires accounts 1.3.0, website v1.1.0
- Something.
## 3.0.0 — requires accounts 1.2.0
- Sign-in moves.
## [2.4.0] - 2026-12-01 — Requires Website 1.0.0 — urgent
## 2.3.0 — urgent
## 2.2.0
- Nothing changes for you.
EOF
}
@test "whatsnew_requires reads one requirement" {
run whatsnew_requires 3.0.0 < <(whatsnew)
[ "$output" = "accounts 1.2.0" ]
}
@test "whatsnew_requires reads several, after urgent and with a v prefix" {
run whatsnew_requires 3.1.0 < <(whatsnew)
[ "${lines[0]}" = "accounts 1.3.0" ]
[ "${lines[1]}" = "website 1.1.0" ]
[ "${#lines[@]}" -eq 2 ]
}
@test "whatsnew_requires ignores case, brackets, dates and a trailing urgent" {
run whatsnew_requires 2.4.0 < <(whatsnew)
[ "$output" = "website 1.0.0" ]
}
@test "whatsnew_requires is empty without requirements, or for a missing version" {
run whatsnew_requires 2.3.0 < <(whatsnew)
[ "$output" = "" ]
run whatsnew_requires 2.2.0 < <(whatsnew)
[ "$output" = "" ]
run whatsnew_requires 1.0.0 < <(whatsnew)
[ "$output" = "" ]
}
@test "whatsnew_requires skips headings inside HTML comments" {
run whatsnew_requires 9.9.9 < <(whatsnew)
[ "$output" = "" ]
}
@test "whatsnew_requires handles Windows line endings" {
run whatsnew_requires 3.0.0 < <(whatsnew | sed 's/$/\r/')
[ "$output" = "accounts 1.2.0" ]
}
@test "whatsnew_requires reads the real Cross Events notes" {
run whatsnew_requires 2.1.1 < "$BATS_TEST_DIRNAME/../../apps/events/WHATS-NEW.md"
[ "$status" -eq 0 ]
[ "$output" = "" ]
}
# ── church.env ──────────────────────────────────────────────────────────────────────────────
@test "church_env_read takes known keys, quoted or bare, and skips the rest" {
cat > "$TMP/church.env" <<'EOF'
# a comment
CHURCH=hopefamily
PRODUCTS="events website"
ADDRESS=hopefamily.co.za # the address
EVENTS_DIR=/var/www/sites/hopefamily/events
EVENTS_PM2='hope-events-backend hope-events-frontend'
EVENTS_PORTS="5000 3000" # api web
PATH=/tmp/evil
SOMETHING_ELSE=1
lower=1
EOF
church_env_read "$TMP/church.env"
[ "$(cenv CHURCH)" = hopefamily ]
[ "$(cenv PRODUCTS)" = "events website" ]
[ "$(cenv ADDRESS)" = hopefamily.co.za ]
[ "$(pvar events PM2)" = "hope-events-backend hope-events-frontend" ]
[ "$(pvar events PORTS)" = "5000 3000" ]
[ "$(pvar events DIR)" = /var/www/sites/hopefamily/events ]
[ -z "${CENV[PATH]+x}" ]
[ -z "${CENV[SOMETHING_ELSE]+x}" ]
[ "$PATH" != /tmp/evil ]
[ "$(pvar website DIR /fallback)" = /fallback ]
}
@test "church_env_read handles Windows line endings and fails on a missing file" {
printf 'CHURCH=grace\r\nEVENTS_DB=grace_events\r\n' > "$TMP/church.env"
church_env_read "$TMP/church.env"
[ "$(cenv CHURCH)" = grace ]
[ "$(pvar events DB)" = grace_events ]
run church_env_read "$TMP/missing.env"
[ "$status" -eq 1 ]
}
@test "church_env_write writes a fixed order that reads back the same" {
CENV=()
church_env_set EVENTS_PORTS "5000 3000"
church_env_set ADDRESS hopefamily.co.za
church_env_set EVENTS_DIR /var/www/sites/hopefamily/events
church_env_set ACCOUNTS_DIR /var/www/sites/hopefamily/accounts
church_env_set CHURCH hopefamily
church_env_set PRODUCTS "accounts events"
church_env_write "$TMP/church.env"
run grep -v '^#' "$TMP/church.env"
[ "${lines[0]}" = "CHURCH=hopefamily" ]
[ "${lines[1]}" = 'PRODUCTS="accounts events"' ]
[ "${lines[2]}" = "ADDRESS=hopefamily.co.za" ]
[ "${lines[3]}" = "ACCOUNTS_DIR=/var/www/sites/hopefamily/accounts" ]
[ "${lines[4]}" = "EVENTS_DIR=/var/www/sites/hopefamily/events" ]
[ "${lines[5]}" = 'EVENTS_PORTS="5000 3000"' ]
CENV=()
church_env_read "$TMP/church.env"
[ "$(cenv PRODUCTS)" = "accounts events" ]
[ "$(pvar events PORTS)" = "5000 3000" ]
[ "${#CENV[@]}" -eq 6 ]
}
@test "church_env_set refuses unknown keys and unsafe values" {
run church_env_set PATH /tmp
[ "$status" -eq 1 ]
run church_env_set EVENTS_DIR '/var/www/$(reboot)'
[ "$status" -eq 1 ]
run church_env_set EVENTS_DIR 'a"b'
[ "$status" -eq 1 ]
}
@test "list_churches lists folders with a church.env" {
CROSSCODE_SITES="$TMP/sites"
mkdir -p "$TMP/sites/hopefamily" "$TMP/sites/grace" "$TMP/sites/.undone-old"
touch "$TMP/sites/hopefamily/church.env" "$TMP/sites/grace/church.env"
run list_churches
[ "${#lines[@]}" -eq 2 ]
[[ "$output" == *hopefamily* ]]
[[ "$output" == *grace* ]]
}
@test "in_product_order puts products in deploy order, once each" {
run in_product_order app events accounts events
[ "${lines[0]}" = accounts ]
[ "${lines[1]}" = events ]
[ "${lines[2]}" = app ]
[ "${#lines[@]}" -eq 3 ]
}
@test "valid_slug" {
valid_slug hopefamily
valid_slug grace-church2
run valid_slug Hope
[ "$status" -eq 1 ]
run valid_slug ../etc
[ "$status" -eq 1 ]
run valid_slug 1church
[ "$status" -eq 1 ]
}
# ── .env and URLs ───────────────────────────────────────────────────────────────────────────
@test "env_value, db_name_from_url and host_from_url" {
cat > "$TMP/.env" <<'EOF'
# DATABASE_URL=postgresql://old
DATABASE_URL="postgresql://hope_events:p%40ss@localhost:5432/hope_events?schema=public"
PORT=5001
FRONTEND_URL=https://events.hopefamily.co.za,https://www.hopefamily.co.za
EOF
[ "$(env_value "$TMP/.env" PORT)" = 5001 ]
[ "$(env_value "$TMP/.env" MISSING)" = "" ]
[ "$(db_name_from_url "$(env_value "$TMP/.env" DATABASE_URL)")" = hope_events ]
[ "$(host_from_url "$(env_value "$TMP/.env" FRONTEND_URL)")" = events.hopefamily.co.za ]
[ "$(host_from_url http://localhost:3000/x)" = localhost ]
}
+211
View File
@@ -0,0 +1,211 @@
#!/usr/bin/env bats
# crosscode deploy against a local git "origin", with stub Events hooks that log what they do
# instead of running npm, Prisma or PM2. Covers the checks, requirements, order, rollback and
# --every-church. What needs a real server is tested on a VM (EVENTS-2.2-PLAN §6).
git_q() { git -c user.name=test -c user.email=test@test -c init.defaultBranch=main "$@"; }
setup() {
TMP="$BATS_TEST_TMPDIR"
export CROSSCODE_TEST=1 CROSSCODE_NO_UPDATE=1
export CROSSCODE_SITES="$TMP/sites"
export CROSSCODE_REPO="$TMP/origin"
export LOG="$TMP/log"
: > "$LOG"
# The crosscode script, with stub hooks for Events.
export CROSSCODE_HOME="$TMP/tools"
mkdir -p "$CROSSCODE_HOME/products"
cp -R "$BATS_TEST_DIRNAME/../lib" "$BATS_TEST_DIRNAME/../crosscode" "$CROSSCODE_HOME/"
cat > "$CROSSCODE_HOME/products/events.sh" <<'EOF'
ref() { git -C "$1" describe --tags --exact-match 2>/dev/null || echo main; }
events_backup() { echo "backup $(ref "$1")" >> "$LOG"; [ "${FAIL_AT:-}" != backup ]; }
events_install_deps() { echo "install $(ref "$1")" >> "$LOG"; }
events_migrate() { echo "migrate $(ref "$1")" >> "$LOG"; [ "${FAIL_AT:-}" != migrate ]; }
events_build() { echo "build $(ref "$1")" >> "$LOG"; [ "${FAIL_AT:-}" != build ]; }
events_rollback_build() { echo "rollback_build $(ref "$1")" >> "$LOG"; }
events_expected_version() { cat "$1/apps/events/VERSION"; }
events_reload() { echo "reload $(ref "$1")" >> "$LOG"; }
events_health_url() { echo http://stub/health; }
wait_for_version() { echo "health $2" >> "$LOG"; [ "${FAIL_HEALTH:-}" != "$2" ]; }
EOF
# origin: events@2.2.0, events@2.2.1, events@2.3.0 (which requires accounts 1.0.0).
git_q init -q "$TMP/origin"
mkdir -p "$TMP/origin/apps/events"
release 2.2.0 "## 2.2.0"
release 2.2.1 "## 2.2.1"
release 2.3.0 "## 2.3.0 — requires accounts 1.0.0"
add_church hope events@2.2.0
}
release() {
printf '%s\n' "$1" > "$TMP/origin/apps/events/VERSION"
printf '# What is new\n\n%s\n\n- Notes.\n' "$2" > "$TMP/origin/apps/events/WHATS-NEW.md"
git_q -C "$TMP/origin" add -A
git_q -C "$TMP/origin" commit -q -m "events $1"
git_q -C "$TMP/origin" tag "events@$1"
}
add_church() {
local church="$1" at="$2"
mkdir -p "$CROSSCODE_SITES/$church"
git_q clone -q "$CROSSCODE_REPO" "$CROSSCODE_SITES/$church/events"
git_q -C "$CROSSCODE_SITES/$church/events" checkout -q --detach "$at"
cat > "$CROSSCODE_SITES/$church/church.env" <<EOF
CHURCH=$church
PRODUCTS="events"
ADDRESS=$church.co.za
EVENTS_DIR=$CROSSCODE_SITES/$church/events
EVENTS_USER=$(id -un)
EVENTS_PM2="$church-events-backend $church-events-frontend"
EVENTS_PORTS="5000 3000"
EOF
}
on() { git -C "$CROSSCODE_SITES/$1/events" describe --tags --exact-match 2>/dev/null || echo main; }
cc() { bash "$CROSSCODE_HOME/crosscode" "$@"; }
@test "deploy --check refuses a release whose requirement isn't met, and changes nothing" {
run cc deploy hope events --check
[ "$status" -eq 1 ]
[[ "$output" == *"events 2.3.0 requires accounts 1.0.0"* ]]
[[ "$output" == *"Nothing was changed"* ]]
[ "$(on hope)" = events@2.2.0 ]
[ ! -s "$LOG" ]
}
@test "deploy to the latest release is refused while its requirement isn't met" {
run cc deploy hope events
[ "$status" -eq 1 ]
[[ "$output" == *"Requirements not met"* ]]
[ "$(on hope)" = events@2.2.0 ]
[ ! -s "$LOG" ]
}
@test "deploy --check with a met release says it's ready" {
run cc deploy hope events --check --version events@2.2.1
[ "$status" -eq 0 ]
[[ "$output" == *"events@2.2.0 → events@2.2.1"* ]]
[[ "$output" == *"ready to deploy"* ]]
[ ! -s "$LOG" ]
}
@test "deploy runs backup, checkout, install, migrate, build, reload and health, in that order" {
run cc deploy hope events --version events@2.2.1
[ "$status" -eq 0 ]
[ "$(on hope)" = events@2.2.1 ]
[ "$(cat "$LOG")" = "$(printf '%s\n' 'backup events@2.2.0' 'install events@2.2.1' 'migrate events@2.2.1' 'build events@2.2.1' 'reload events@2.2.1' 'health 2.2.1')" ]
[[ "$output" == *"updated events@2.2.0 → events@2.2.1"* ]]
}
@test "a church already on the release is left alone" {
run cc deploy hope events --version events@2.2.0
[ "$status" -eq 0 ]
[[ "$output" == *"already on events@2.2.0"* ]]
[ ! -s "$LOG" ]
}
@test "a failed backup changes nothing" {
FAIL_AT=backup run cc deploy hope events --version events@2.2.1
[ "$status" -eq 1 ]
[ "$(on hope)" = events@2.2.0 ]
[[ "$output" == *"failed at the backup"* ]]
run grep -q install "$LOG"
[ "$status" -ne 0 ]
}
@test "a failed migration goes back to the previous release, without reloading" {
FAIL_AT=migrate run cc deploy hope events --version events@2.2.1
[ "$status" -eq 1 ]
[ "$(on hope)" = events@2.2.0 ]
[[ "$output" == *"rolled back to events@2.2.0 (the running version was never stopped)"* ]]
grep -qx "rollback_build events@2.2.0" "$LOG"
run grep -q reload "$LOG"
[ "$status" -ne 0 ]
}
@test "a release that doesn't come up is rolled back, reloaded and checked again" {
FAIL_HEALTH=2.2.1 run cc deploy hope events --version events@2.2.1
[ "$status" -eq 1 ]
[ "$(on hope)" = events@2.2.0 ]
[ "$(grep -c reload "$LOG")" -eq 2 ]
grep -qx "health 2.2.0" "$LOG"
[[ "$output" == *"rolled back to events@2.2.0 and running again"* ]]
}
@test "files changed by hand stop the deploy" {
echo "hand edit" >> "$CROSSCODE_SITES/hope/events/apps/events/VERSION"
run cc deploy hope events --version events@2.2.1 --check
[ "$status" -eq 1 ]
[[ "$output" == *"changed or added by hand"* ]]
[[ "$output" == *"apps/events/VERSION"* ]]
run cc deploy hope events --version events@2.2.1
[ "$status" -eq 1 ]
[ ! -s "$LOG" ]
}
@test "--allow-local-changes deploys with a file added by hand" {
echo "notes" > "$CROSSCODE_SITES/hope/events/apps/events/notes.txt"
run cc deploy hope events --version events@2.2.1
[ "$status" -eq 1 ]
[ ! -s "$LOG" ]
run cc deploy hope events --version events@2.2.1 --allow-local-changes
[ "$status" -eq 0 ]
[[ "$output" == *"deploying anyway"* ]]
[ "$(on hope)" = events@2.2.1 ]
# --check never passes with changes, even with the flag.
run cc deploy hope events --check --allow-local-changes
[ "$status" -eq 1 ]
}
@test "ignored files (.env, ecosystem.config.js) don't count as changes" {
printf '.env\n/apps/events/ecosystem.config.js\n' > "$CROSSCODE_SITES/hope/events/.git/info/exclude"
echo "SECRET=1" > "$CROSSCODE_SITES/hope/events/.env"
echo "module.exports = {}" > "$CROSSCODE_SITES/hope/events/apps/events/ecosystem.config.js"
run cc deploy hope events --version events@2.2.1
[ "$status" -eq 0 ]
[ "$(on hope)" = events@2.2.1 ]
}
@test "a product the church doesn't have is refused; nothing named does nothing" {
run cc deploy hope website
[ "$status" -eq 1 ]
[[ "$output" == *"hope has no website"* ]]
run cc deploy hope
[ "$status" -eq 0 ]
[[ "$output" == *"Nothing to deploy"* ]]
}
@test "deploy --main checks out the latest main" {
release 2.4.0-dev "## 2.4.0-dev"
git_q -C "$TMP/origin" tag -d events@2.4.0-dev >/dev/null
run cc deploy hope events --main
[ "$status" -eq 0 ]
[ "$(on hope)" = main ]
grep -qx "health 2.4.0-dev" "$LOG"
}
@test "deploy --every-church updates each church, one after the other" {
add_church grace events@2.2.0
run cc deploy --every-church events --version events@2.2.1
[ "$status" -eq 0 ]
[ "$(on hope)" = events@2.2.1 ]
[ "$(on grace)" = events@2.2.1 ]
[ "$(grep -c '^health 2.2.1' "$LOG")" -eq 2 ]
}
@test "deploy --every-church stops at the first church that fails" {
add_church grace events@2.2.0
FAIL_AT=build run cc deploy --every-church events --version events@2.2.1
[ "$status" -eq 1 ]
[[ "$output" == *"Stopped at "* ]]
[ "$(grep -c '^backup' "$LOG")" -eq 1 ]
}
@test "unknown church" {
run cc deploy nowhere events
[ "$status" -eq 1 ]
[[ "$output" == *'No church "nowhere"'* ]]
}